create token name constants in comment package

This commit is contained in:
z7zmey
2018-05-27 22:15:27 +03:00
parent e396f81eea
commit b383fe98fe
8 changed files with 2217 additions and 2000 deletions

View File

@@ -3,6 +3,7 @@ package parser
import (
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/scanner"
)
// Comments a collection of comment groups assigned to nodes
@@ -12,3 +13,18 @@ type Comments map[node.Node][]*comment.Comment
func (c Comments) AddComments(node node.Node, comments []*comment.Comment) {
c[node] = append(c[node], comments...)
}
func (c Comments) AddFromToken(node node.Node, token *scanner.Token, tokenName comment.TokenName) {
comments := token.Comments()
for _, cmt := range comments {
cmt.SetTokenName(tokenName)
}
c.AddComments(node, comments)
}
func (c Comments) AddFromChildNode(n node.Node, ch node.Node) {
c.AddComments(n, c[ch])
delete(c, ch)
}