holy carp it parses
This commit is contained in:
parent
dc89e81cc5
commit
edcbfde351
3 changed files with 240 additions and 6 deletions
20
tokentype.go
20
tokentype.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue