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.ASSIGN:
			if keyCount > 1 {
				return nil, &PosError{
					Pos: p.tok.Pos,
					Err: fmt.Errorf("nested object expected: LBRACE got: %s", p.tok.Type),
				}
			}
			if keyCount == 0 {
				return nil, &PosError{
					Pos: p.tok.Pos,
					Err: errors.New("no object keys found!"),
				}
			}
			return keys, nil
		case token.LBRACE:
			return keys, nil
		case token.IDENT, token.STRING:
			keyCount++
			keys = append(keys, &ast.ObjectKey{Token: p.tok})
		case token.ILLEGAL:
			fmt.Println("illegal")
		default:
			return nil, &PosError{
				Pos: p.tok.Pos,
				Err: fmt.Errorf("expected: IDENT | STRING | ASSIGN | LBRACE got: %s", p.tok.Type),
			}
		}
	}
}
objectKey parses an object key and returns a ObjectKey AST
package parser
import (
	"errors"
	"fmt"
	"github.com/hashicorp/hcl/hcl/ast"
	"github.com/hashicorp/hcl/hcl/scanner"
	"github.com/hashicorp/hcl/hcl/token"
)
type Parser struct {
	sc *scanner.Scanner
	tok       token.Token
	commaPrev token.Token
	comments    []*ast.CommentGroup
	leadComment *ast.CommentGroup  
	lineComment *ast.CommentGroup  
	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 = &PosError{Pos: pos, Err: errors.New(msg)}
	}
	f.Node, err = p.objectList()
	if scerr != nil {
		return nil, scerr
	}
	if err != nil {
		return nil, err
	}
	f.Comments = p.comments
	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)
	}
	return node, nil
}
func (p *Parser) consumeComment() (comment *ast.Comment, endline int) {
	endline = p.tok.Pos.Line
	if len(p.tok.Text) > 1 && p.tok.Text[1] == '*' {
		for i := 0; i < len(p.tok.Text); i++ {
			if p.tok.Text[i] == '\n' {
				endline++
			}
		}
	}
	comment = &ast.Comment{Start: p.tok.Pos, Text: p.tok.Text}
	p.tok = p.sc.Scan()
	return
}
func (p *Parser) consumeCommentGroup(n int) (comments *ast.CommentGroup, endline int) {
	var list []*ast.Comment
	endline = p.tok.Pos.Line
	for p.tok.Type == token.COMMENT && p.tok.Pos.Line <= endline+n {
		var comment *ast.Comment
		comment, endline = p.consumeComment()
		list = append(list, comment)
	}
	comments = &ast.CommentGroup{List: list}
	p.comments = append(p.comments, comments)
	return
}
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,
	}
	if p.leadComment != nil {
		o.LeadComment = p.leadComment
		p.leadComment = nil
	}
	switch p.tok.Type {
	case token.ASSIGN:
		o.Assign = p.tok.Pos
		o.Val, err = p.object()
		if err != nil {
			return nil, err
		}
	case token.LBRACE:
		o.Val, err = p.objectType()
		if err != nil {
			return nil, err
		}
	}
	p.scan()
	if len(keys) > 0 && o.Val.Pos().Line == keys[0].Pos().Line && p.lineComment != nil {
		o.LineComment = p.lineComment
		p.lineComment = nil
	}
	p.unscan()
	return o, nil
}