add token comments

This commit is contained in:
z7zmey 2018-01-11 20:49:00 +02:00
parent 3392ce2f1c
commit 8f874944e3

View File

@ -4,6 +4,7 @@ import (
"github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/comment"
) )
// Token value returned by lexer
type Token struct { type Token struct {
Value string Value string
StartLine int StartLine int
@ -13,6 +14,8 @@ type Token struct {
comments []comment.Comment comments []comment.Comment
} }
// NewToken Token constructor
// TODO: return pointer
func NewToken(value []byte, startLine int, endLine int, startPos int, endPos int) Token { func NewToken(value []byte, startLine int, endLine int, startPos int, endPos int) Token {
return Token{string(value), startLine, endLine, startPos, endPos, nil} return Token{string(value), startLine, endLine, startPos, endPos, nil}
} }
@ -21,20 +24,12 @@ func (t Token) String() string {
return string(t.Value) return string(t.Value)
} }
func (t Token) GetValue() string { // Comments returns attached comments
return t.Value
}
func (t Token) GetStartLine() int {
return t.StartLine
}
func (t Token) GetEndLine() int {
return t.EndLine
}
func (t Token) Comments() []comment.Comment { func (t Token) Comments() []comment.Comment {
return t.comments return t.comments
} }
// SetComments attach comments
func (t Token) SetComments(comments []comment.Comment) Token { func (t Token) SetComments(comments []comment.Comment) Token {
t.comments = comments t.comments = comments
return t return t