mirror of
https://github.com/felixangell/phi.git
synced 2024-10-26 17:18:31 +03:00
24 lines
371 B
Go
24 lines
371 B
Go
package lex
|
|
|
|
import "fmt"
|
|
|
|
type TokenType uint
|
|
|
|
const (
|
|
Word TokenType = iota
|
|
)
|
|
|
|
type Token struct {
|
|
Lexeme string
|
|
Type TokenType
|
|
Start int
|
|
}
|
|
|
|
func NewToken(lexeme string, kind TokenType, start int) *Token {
|
|
return &Token{lexeme, kind, start}
|
|
}
|
|
|
|
func (t *Token) String() string {
|
|
return fmt.Sprintf("lexeme: %s, type %s, at pos %d", t.Lexeme, t.Type, t.Start)
|
|
}
|