glox/lox/token.go
Fabian Becker def39d9112
All checks were successful
continuous-integration/drone/push Build is passing
Fix linting error
2022-01-12 11:03:46 +01:00

73 lines
899 B
Go

package lox
import "fmt"
//go:generate stringer -type=TokenType
type TokenType int
const (
// Single character tokens
LeftParen TokenType = iota
RightParen
LeftBrace
RightBrace
Comma
Dot
Minus
Plus
Semicolon
Slash
Star
// One or two character tokens
Bang
BangEqual
Equal
EqualEqual
Greater
GreaterEqual
Less
LessEqual
// Literals
Identifier
String
Number
// Keywords
And
Class
Else
False
Fun
For
If
Nil
Or
Print
Return
Super
This
True
Var
While
Eof
)
type Token struct {
tokenType TokenType
lexeme string
literal interface{}
line int
column int
}
func (t Token) String() string {
return fmt.Sprintf("%s\t%s\t%s", t.tokenType, t.lexeme, t.literal)
}
func makeToken(tt TokenType, lexeme string, lit interface{}, line, column int) *Token {
return &Token{tokenType: tt, lexeme: lexeme, literal: lit, line: line, column: column}
}