#25: save comments within node

This commit is contained in:
z7zmey
2018-06-25 15:38:31 +03:00
parent 1ebb0c6fad
commit 3cd45ecac5
183 changed files with 16743 additions and 14671 deletions

View File

@@ -6,35 +6,25 @@ import (
// Comment aggrigates information about comment /**
type Comment struct {
value string
position *position.Position
tokenName TokenName
Value string
Position *position.Position
TokenName TokenName
}
// NewComment - Comment constructor
func NewComment(value string, pos *position.Position) *Comment {
return &Comment{
value,
pos,
UnknownToken,
Value: value,
Position: pos,
TokenName: UnknownToken,
}
}
// SetTokenName sets token name
func (c *Comment) SetTokenName(tokenName TokenName) {
c.tokenName = tokenName
}
// TokenName returns token name
func (c *Comment) TokenName() TokenName {
return c.tokenName
c.TokenName = tokenName
}
func (c *Comment) String() string {
return c.value
}
// Position returns comment position
func (c *Comment) Position() *position.Position {
return c.position
return c.Value
}

View File

@@ -3,23 +3,9 @@ package comment_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/comment"
)
func TestCommentGetPosition(t *testing.T) {
expected := position.NewPosition(0, 0, 0, 0)
comment := comment.NewComment("/** hello world */", expected)
actual := comment.Position()
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}
func TestCommentPrint(t *testing.T) {
expected := "/** hello world */"
@@ -31,3 +17,15 @@ func TestCommentPrint(t *testing.T) {
t.Errorf("expected and actual are not equal\n")
}
}
func TestCommentSetTokenName(t *testing.T) {
expected := comment.ArrayToken
c := comment.NewComment("/** hello world */", nil)
c.SetTokenName(expected)
actual := c.TokenName
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}