github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/compiler/token/type.go (about)

     1  package token
     2  
     3  type Type uint
     4  
     5  func (typ Type) String() string {
     6  	return tokenNames[typ]
     7  }
     8  
     9  const (
    10  	ILLEGAL Type = iota
    11  
    12  	EOF
    13  	COMMENT
    14  	LABEL    // ::
    15  	ELLIPSIS // ...
    16  
    17  	literal_beg
    18  
    19  	NAME
    20  
    21  	INT
    22  	FLOAT
    23  	STRING
    24  
    25  	literal_end
    26  	operator_beg
    27  
    28  	ADD    // +
    29  	SUB    // -
    30  	MUL    // *
    31  	MOD    // %
    32  	POW    // ^
    33  	DIV    // /
    34  	IDIV   // //
    35  	BAND   // &
    36  	BOR    // |
    37  	BXOR   // ~
    38  	SHL    // <<
    39  	SHR    // >>
    40  	CONCAT // ..
    41  
    42  	// UNM    // -
    43  	// BNOT   // ~
    44  	LEN // #
    45  
    46  	ASSIGN // =
    47  
    48  	EQ // ==
    49  	NE // ~=
    50  	LT // <
    51  	LE // <=
    52  	GT // >
    53  	GE // >=
    54  
    55  	LPAREN    // (
    56  	RPAREN    // )
    57  	LBRACK    // [
    58  	RBRACK    // ]
    59  	LBRACE    // {
    60  	RBRACE    // }
    61  	COLON     // :
    62  	COMMA     // ,
    63  	SEMICOLON // ;
    64  	PERIOD    // .
    65  
    66  	operator_end
    67  	keyword_beg
    68  
    69  	AND
    70  	BREAK
    71  	DO
    72  	ELSE
    73  	ELSEIF
    74  	END
    75  	FALSE
    76  	FOR
    77  	FUNCTION
    78  	GOTO
    79  	IF
    80  	IN
    81  	LOCAL
    82  	NIL
    83  	NOT
    84  	OR
    85  	REPEAT
    86  	RETURN
    87  	THEN
    88  	TRUE
    89  	UNTIL
    90  	WHILE
    91  
    92  	keyword_end
    93  )
    94  
    95  // alias
    96  const (
    97  	UNM  = SUB
    98  	BNOT = BXOR
    99  )
   100  
   101  var tokenNames = [...]string{
   102  	ILLEGAL: "ILLEGAL",
   103  
   104  	EOF:      "EOF",
   105  	COMMENT:  "COMMENT",
   106  	LABEL:    "::",
   107  	ELLIPSIS: "...",
   108  
   109  	NAME:   "NAME",
   110  	INT:    "INT",
   111  	FLOAT:  "FLOAT",
   112  	STRING: "STRING",
   113  
   114  	ADD:    "+",
   115  	SUB:    "-",
   116  	MUL:    "*",
   117  	MOD:    "%",
   118  	POW:    "^",
   119  	DIV:    "/",
   120  	IDIV:   "//",
   121  	BAND:   "&",
   122  	BOR:    "|",
   123  	BXOR:   "~",
   124  	SHL:    "<<",
   125  	SHR:    ">>",
   126  	CONCAT: "..",
   127  
   128  	// UNM:  "-",
   129  	// BNOT: "~",
   130  	LEN: "#",
   131  
   132  	ASSIGN: "=",
   133  
   134  	EQ: "==",
   135  	NE: "~=",
   136  	LT: "<",
   137  	LE: "<=",
   138  	GT: ">",
   139  	GE: ">=",
   140  
   141  	LPAREN:    "(",
   142  	RPAREN:    ")",
   143  	LBRACK:    "[",
   144  	RBRACK:    "]",
   145  	LBRACE:    "{",
   146  	RBRACE:    "}",
   147  	COLON:     ":",
   148  	COMMA:     ",",
   149  	SEMICOLON: ";",
   150  	PERIOD:    ".",
   151  
   152  	AND:      "and",
   153  	BREAK:    "break",
   154  	DO:       "do",
   155  	ELSE:     "else",
   156  	ELSEIF:   "elseif",
   157  	END:      "end",
   158  	FALSE:    "false",
   159  	FOR:      "for",
   160  	FUNCTION: "function",
   161  	GOTO:     "goto",
   162  	IF:       "if",
   163  	IN:       "in",
   164  	LOCAL:    "local",
   165  	NIL:      "nil",
   166  	NOT:      "not",
   167  	OR:       "or",
   168  	REPEAT:   "repeat",
   169  	RETURN:   "return",
   170  	THEN:     "then",
   171  	TRUE:     "true",
   172  	UNTIL:    "until",
   173  	WHILE:    "while",
   174  }
   175  
   176  var keywords = map[string]Type{
   177  	"and":      AND,
   178  	"break":    BREAK,
   179  	"do":       DO,
   180  	"else":     ELSE,
   181  	"elseif":   ELSEIF,
   182  	"end":      END,
   183  	"false":    FALSE,
   184  	"for":      FOR,
   185  	"function": FUNCTION,
   186  	"goto":     GOTO,
   187  	"if":       IF,
   188  	"in":       IN,
   189  	"local":    LOCAL,
   190  	"nil":      NIL,
   191  	"not":      NOT,
   192  	"or":       OR,
   193  	"repeat":   REPEAT,
   194  	"return":   RETURN,
   195  	"then":     THEN,
   196  	"true":     TRUE,
   197  	"until":    UNTIL,
   198  	"while":    WHILE,
   199  }