php-parser/scanner/token.go

43 lines
813 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"
"github.com/z7zmey/php-parser/position"
2018-01-05 15:03:59 +00:00
)
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
position *position.Position
comments []*comment.Comment
2017-12-03 18:49:18 +00:00
}
2018-01-11 18:49:00 +00:00
// NewToken Token constructor
2018-06-07 12:06:54 +00:00
func NewToken(value string, pos *position.Position) *Token {
return &Token{
2018-06-07 12:06:54 +00:00
Value: value,
position: pos,
comments: nil,
}
2017-12-03 18:49:18 +00:00
}
func (t *Token) String() string {
2017-12-03 18:49:18 +00:00
return string(t.Value)
}
2017-12-08 09:37:32 +00:00
// Position returns token position
func (t *Token) Position() *position.Position {
return t.position
}
2018-01-11 18:49:00 +00:00
// Comments returns attached comments
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
func (t *Token) SetComments(comments []*comment.Comment) *Token {
2018-01-05 15:03:59 +00:00
t.comments = comments
return t
}