about summary refs log tree commit diff
path: root/users
diff options
context:
space:
mode:
authorfranck cuny <franck@fcuny.net>2020-01-11 14:26:19 +0100
committerfranck cuny <franck@fcuny.net>2020-01-11 14:26:19 +0100
commit2c4068a5be7f60e8d0376720f70791d23a8c3ef1 (patch)
tree3ee85e9a89bfe3e33a1139e9c557e198df446fef /users
parenttoken: rewrite documentation for `LookupIdent`. (diff)
downloadworld-2c4068a5be7f60e8d0376720f70791d23a8c3ef1.tar.gz
token: support more keywords
Add support for a few more keywords (`true`, `false`, `if`, `else`,
`return`).

All keywords are grouped together in the constant declaration.
Diffstat (limited to 'users')
-rw-r--r--users/fcuny/exp/monkey/pkg/token/token.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/users/fcuny/exp/monkey/pkg/token/token.go b/users/fcuny/exp/monkey/pkg/token/token.go
index 6937595..a211c55 100644
--- a/users/fcuny/exp/monkey/pkg/token/token.go
+++ b/users/fcuny/exp/monkey/pkg/token/token.go
@@ -24,8 +24,14 @@ const (
 	LBRACE = "{"
 	RBRACE = "}"
 
+	// The following tokens are keywords
 	FUNCTION = "FUNCTION"
 	LET      = "LET"
+	TRUE     = "TRUE"
+	FALSE    = "FALSE"
+	IF       = "IF"
+	ELSE     = "ELSE"
+	RETURN   = "RETURN"
 
 	// The following tokens are for operators
 	ASSIGN   = "="
@@ -40,8 +46,13 @@ const (
 
 // List of our keywords for the language
 var keywords = map[string]TokenType{
-	"fn":  FUNCTION,
-	"let": LET,
+	"fn":     FUNCTION,
+	"let":    LET,
+	"true":   TRUE,
+	"false":  FALSE,
+	"if":     IF,
+	"else":   ELSE,
+	"return": RETURN,
 }
 
 // LookupIdent returns the token type for a given identifier.