parser: collect comments

This commit is contained in:
Fatih Arslan 2015-10-24 23:11:03 +03:00
parent 6b5bd170f6
commit a995361468

View File

@ -12,7 +12,8 @@ import (
type Parser struct { type Parser struct {
sc *scanner.Scanner sc *scanner.Scanner
tok token.Token // last read token tok token.Token // last read token
comments []*ast.Comment
enableTrace bool enableTrace bool
indent int indent int
@ -48,11 +49,12 @@ func (p *Parser) parseObjectList() (*ast.ObjectList, error) {
return node, err return node, err
} }
if item, ok := n.(*ast.ObjectItem); ok { switch t := n.(type) {
// we successfully parsed a node, add it to the final source node case *ast.ObjectItem:
node.Add(item) node.Add(t)
case *ast.Comment:
p.comments = append(p.comments, t)
} }
} }
return node, nil return node, nil