func (p *Parser) objectType() (*ast.ObjectType, error) {
	defer un(trace(p, "ParseObjectType"))
	o := &ast.ObjectType{}
	l, err := p.objectList()
	if err != nil && p.tok.Type != token.RBRACE {
		return nil, err
	}
	o.List = l
	return o, nil
}
objectType parses an object type and returns a ObjectType AST
package parser
import (
	"errors"
	"fmt"
	"github.com/hashicorp/hcl/hcl/ast"
	hcltoken "github.com/hashicorp/hcl/hcl/token"
	"github.com/hashicorp/hcl/json/scanner"
	"github.com/hashicorp/hcl/json/token"
)
type Parser struct {
	sc *scanner.Scanner
	tok       token.Token
	commaPrev token.Token
	enableTrace bool
	indent      int
	n           int  
}
func newParser(src []byte) *Parser {
	return &Parser{
		sc: scanner.New(src),
	}
}
func Parse(src []byte) (*ast.File, error) {
	p := newParser(src)
	return p.Parse()
}
var errEofToken = errors.New("EOF token found")
func (p *Parser) Parse() (*ast.File, error) {
	f := &ast.File{}
	var err, scerr error
	p.sc.Error = func(pos token.Pos, msg string) {
		scerr = fmt.Errorf("%s: %s", pos, msg)
	}
	object, err := p.object()
	if scerr != nil {
		return nil, scerr
	}
	if err != nil {
		return nil, err
	}
	f.Node = object.List
	flattenObjects(f.Node)
	return f, nil
}
func (p *Parser) objectList() (*ast.ObjectList, error) {
	defer un(trace(p, "ParseObjectList"))
	node := &ast.ObjectList{}
	for {
		n, err := p.objectItem()
		if err == errEofToken {
			break  
		}
		if err != nil {
			return node, err
		}
		node.Add(n)
		if tok := p.scan(); tok.Type != token.COMMA {
			break
		}
	}
	return node, nil
}
func (p *Parser) objectItem() (*ast.ObjectItem, error) {
	defer un(trace(p, "ParseObjectItem"))
	keys, err := p.objectKey()
	if err != nil {
		return nil, err
	}
	o := &ast.ObjectItem{
		Keys: keys,
	}
	switch p.tok.Type {
	case token.COLON:
		pos := p.tok.Pos
		o.Assign = hcltoken.Pos{
			Filename: pos.Filename,
			Offset:   pos.Offset,
			Line:     pos.Line,
			Column:   pos.Column,
		}
		o.Val, err = p.objectValue()
		if err != nil {
			return nil, err
		}
	}
	return o, nil
}
func (p *Parser) objectKey() ([]*ast.ObjectKey, error) {
	keyCount := 0
	keys := make([]*ast.ObjectKey, 0)
	for {
		tok := p.scan()
		switch tok.Type {
		case token.EOF:
			return nil, errEofToken
		case token.STRING:
			keyCount++
			keys = append(keys, &ast.ObjectKey{
				Token: p.tok.HCLToken(),
			})
		case token.COLON:
			if keyCount == 0 {
				return nil, fmt.Errorf("expected: STRING got: %s", p.tok.Type)
			}
			return keys, nil
		case token.ILLEGAL:
			return nil, errors.New("illegal")
		default:
			return nil, fmt.Errorf("expected: STRING got: %s", p.tok.Type)
		}
	}
}
func (p *Parser) objectValue() (ast.Node, error) {
	defer un(trace(p, "ParseObjectValue"))
	tok := p.scan()
	switch tok.Type {
	case token.NUMBER, token.FLOAT, token.BOOL, token.NULL, token.STRING:
		return p.literalType()
	case token.LBRACE:
		return p.objectType()
	case token.LBRACK:
		return p.listType()
	case token.EOF:
		return nil, errEofToken
	}
	return nil, fmt.Errorf("Expected object value, got unknown token: %+v", tok)
}
func (p *Parser) object() (*ast.ObjectType, error) {
	defer un(trace(p, "ParseType"))
	tok := p.scan()
	switch tok.Type {
	case token.LBRACE:
		return p.objectType()
	case token.EOF:
		return nil, errEofToken
	}
	return nil, fmt.Errorf("Expected object, got unknown token: %+v", tok)
}