parser: collect comments
This commit is contained in:
parent
6b5bd170f6
commit
a995361468
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user