php-parser/token/token.go

37 lines
744 B
Go
Raw Normal View History

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