#33 comment package has renamed to meta and parser now saves whitespaces

This commit is contained in:
z7zmey
2018-06-30 00:51:11 +03:00
parent 36d0cf4823
commit e90df8ef5f
205 changed files with 16485 additions and 16302 deletions

View File

@@ -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)
}

View File

@@ -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")
}
}

View File

@@ -11,5 +11,5 @@ type Parser interface {
GetPath() string
GetRootNode() node.Node
GetErrors() []*errors.Error
GetComments() Comments
WithMeta()
}