1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package token
- // TokenType is the string representation of the Token types.
- type TokenType string
- // Token represents a Parser token.
- type Token struct {
- Type TokenType
- Literal string
- }
- // The TokenType values.
- 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
- }
|