2018-04-15 19:02:07 +00:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/z7zmey/php-parser/comment"
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
2018-05-27 19:15:27 +00:00
|
|
|
"github.com/z7zmey/php-parser/scanner"
|
2018-04-15 19:02:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Comments a collection of comment groups assigned to nodes
|
|
|
|
type Comments map[node.Node][]*comment.Comment
|
|
|
|
|
|
|
|
// AddComments add comment group to the collection
|
|
|
|
func (c Comments) AddComments(node node.Node, comments []*comment.Comment) {
|
|
|
|
c[node] = append(c[node], comments...)
|
|
|
|
}
|
2018-05-27 19:15:27 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|