mirror of
https://github.com/felixangell/phi.git
synced 2024-10-26 17:18:31 +03:00
8687f612d4
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.
39 lines
655 B
Go
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))
|
|
}
|