php-parser/scanner/token.go

37 lines
749 B
Go
Raw Normal View History

package scanner
2017-12-03 18:49:18 +00:00
2018-01-05 15:03:59 +00:00
import (
"github.com/z7zmey/php-parser/comment"
)
2018-01-11 18:49:00 +00:00
// Token value returned by lexer
2017-12-03 18:49:18 +00:00
type Token struct {
Value string
StartLine int
EndLine int
2018-01-05 11:01:14 +00:00
StartPos int
EndPos int
2018-04-15 12:55:33 +00:00
comments []*comment.Comment
2017-12-03 18:49:18 +00:00
}
2018-01-11 18:49:00 +00:00
// NewToken Token constructor
// TODO: return pointer
2018-01-05 11:01:14 +00:00
func NewToken(value []byte, startLine int, endLine int, startPos int, endPos int) Token {
2018-01-05 15:03:59 +00:00
return Token{string(value), startLine, endLine, startPos, endPos, nil}
2017-12-03 18:49:18 +00:00
}
func (t Token) String() string {
return string(t.Value)
}
2017-12-08 09:37:32 +00:00
2018-01-11 18:49:00 +00:00
// Comments returns attached comments
2018-04-15 12:55:33 +00:00
func (t Token) Comments() []*comment.Comment {
2018-01-05 15:03:59 +00:00
return t.comments
}
2018-01-11 18:49:00 +00:00
// SetComments attach comments
2018-04-15 12:55:33 +00:00
func (t Token) SetComments(comments []*comment.Comment) Token {
2018-01-05 15:03:59 +00:00
t.comments = comments
return t
}