#33 comment package has renamed to meta and parser now saves whitespaces
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
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
|
||||
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...)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package parser_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
)
|
||||
|
||||
func TestComments(t *testing.T) {
|
||||
n := node.NewIdentifier("test")
|
||||
|
||||
commentGroup := []*comment.Comment{
|
||||
comment.NewComment("/** hello world */", nil),
|
||||
comment.NewComment("// hello world", nil),
|
||||
}
|
||||
|
||||
comments := parser.Comments{}
|
||||
comments.AddComments(n, commentGroup)
|
||||
|
||||
if comments[n][0].String() != "/** hello world */" {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
if comments[n][1].String() != "// hello world" {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,5 @@ type Parser interface {
|
||||
GetPath() string
|
||||
GetRootNode() node.Node
|
||||
GetErrors() []*errors.Error
|
||||
GetComments() Comments
|
||||
WithMeta()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user