12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package token
- type TokenType string
- type Token struct {
- Type TokenType
- Literal string
- }
- const (
- ILLEGAL = "ILLEGAL"
- EOF = "EOF"
- // Identifiers + literals.
- IDENT = "IDENT" // add, foobar, x, y, ...
- INT = "INT" // 123456, ...
- // Operators.
- ASSIGN = "="
- PLUS = "+"
- MINUS = "-"
- BANG = "!"
- ASTERISK = "*"
- SLASH = "/"
- LT = "<"
- GT = ">"
- EQ = "=="
- NOT_EQ = "!="
- // Delimiters.
- COMMA = ","
- SEMICOLON = ";"
- LPAREN = "("
- RPAREN = ")"
- LBRACE = "{"
- RBRACE = "}"
- // Keywords
- FUNCTION = "FUNCTION"
- LET = "LET"
- TRUE = "TRUE"
- FALSE = "FALSE"
- IF = "IF"
- ELSE = "ELSE"
- RETURN = "RETURN"
- )
- var keywords = map[string]TokenType{
- "fn": FUNCTION,
- "let": LET,
- "true": TRUE,
- "false": FALSE,
- "if": IF,
- "else": ELSE,
- "return": RETURN,
- }
- // LookupIdent checks the keywords table to see whether the given identifier is
- // in fact a keyword.
- func LookupIdent(ident string) TokenType {
- if tok, ok := keywords[ident]; ok {
- return tok
- }
- return IDENT
- }
|