phi/lex/token.go
Felix Angell 8687f612d4 command palette is now has a hand written lexer
this means that we can 'type check' command palette arguments, e.g. if something should be a string or not, etc.
it uses the same lexer which is used for the syntax highlighting ... let's see how long that lasts.
2019-03-02 20:54:01 +00:00

39 lines
655 B
Go

package lex
import (
"fmt"
"strings"
)
type TokenType string
const (
Word TokenType = "word"
Symbol = "sym"
Character = "char"
String = "string"
Number = "num"
)
type Token struct {
Lexeme string
Type TokenType
Start int
}
func (t *Token) Equals(str string) bool {
return strings.Compare(str, t.Lexeme) == 0
}
func (t *Token) IsType(typ TokenType) bool {
return t.Type == typ
}
func NewToken(lexeme string, kind TokenType, start int) *Token {
return &Token{lexeme, kind, start}
}
func (t *Token) String() string {
return fmt.Sprintf("{ %s = %s }", t.Lexeme, string(t.Type))
}