mirror of
https://github.com/Fluffy-Bean/GoLox.git
synced 2025-05-14 07:42:15 +00:00
66 lines
606 B
Go
66 lines
606 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
// Single Char tokens
|
|
LeftParen = iota
|
|
RightParen
|
|
LeftBrace
|
|
RightBrace
|
|
Comma
|
|
Dot
|
|
Minus
|
|
Plus
|
|
Semicolon
|
|
Slash
|
|
Star
|
|
|
|
// One or Two Char tokens
|
|
Bang
|
|
BangEqual
|
|
Equal
|
|
EqualEqual
|
|
Greater
|
|
GreaterEqual
|
|
Less
|
|
LessEqual
|
|
|
|
// Literals
|
|
Identifier
|
|
String
|
|
Number
|
|
|
|
// Keywords
|
|
And
|
|
Class
|
|
Else
|
|
False
|
|
Fun
|
|
For
|
|
If
|
|
Nah
|
|
Or
|
|
Print
|
|
Return
|
|
Super
|
|
This
|
|
True
|
|
Var
|
|
While
|
|
|
|
EOF
|
|
)
|
|
|
|
type Token struct {
|
|
Type int
|
|
Lexeme string
|
|
Literal string
|
|
Line int
|
|
}
|
|
|
|
func (t Token) String() string {
|
|
return fmt.Sprintf("%d %s %s", t.Type, t.Lexeme, t.Literal)
|
|
}
|