holy carp it parses

This commit is contained in:
basil 2025-06-07 21:16:05 -04:00
parent dc89e81cc5
commit edcbfde351
Signed by: basil
SSH key fingerprint: SHA256:y04xIFL/yqNaG9ae9Vl95vELtHfApGAIoOGLeVLP/fE
3 changed files with 240 additions and 6 deletions

View file

@ -59,6 +59,17 @@ const (
tokenTypeEOF
)
var keywordTokenTypes = []tokenType{
tokenTypeClass,
tokenTypeFun,
tokenTypeVar,
tokenTypeFor,
tokenTypeIf,
tokenTypeReturn,
tokenTypeWhile,
tokenTypePrint,
}
type token struct {
Type tokenType
Lexeme string
@ -69,3 +80,12 @@ type token struct {
func (t token) String() string {
return fmt.Sprintf("%s %s %+v", t.Type, t.Lexeme, t.Literal)
}
func isKeyword(token *token) bool {
for _, kt := range keywordTokenTypes {
if token.Type == kt {
return true
}
}
return false
}