2018-04-15 11:47:40 +00:00
|
|
|
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-04-15 19:56:20 +00:00
|
|
|
"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 {
|
2018-04-15 19:56:20 +00:00
|
|
|
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-04-15 19:56:20 +00:00
|
|
|
func NewToken(value []byte, pos *position.Position) *Token {
|
|
|
|
return &Token{
|
|
|
|
Value: string(value),
|
|
|
|
position: pos,
|
|
|
|
comments: nil,
|
|
|
|
}
|
2017-12-03 18:49:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 19:56:20 +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
|
|
|
|
2018-04-15 19:56:20 +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
|
2018-04-15 19:56:20 +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 19:56:20 +00:00
|
|
|
func (t *Token) SetComments(comments []*comment.Comment) *Token {
|
2018-01-05 15:03:59 +00:00
|
|
|
t.comments = comments
|
|
|
|
return t
|
|
|
|
}
|