123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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 = "+"
- // Delimiters.
- COMMA = ","
- SEMICOLON = ";"
- LPAREN = "("
- RPAREN = ")"
- LBRACE = "{"
- RBRACE = "}"
- // Keywords
- FUNCTION = "FUNCTION"
- LET = "LET"
- )
- var keywords = map[string]TokenType{
- "fn": FUNCTION,
- "let": LET,
- }
- // 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
- }
|