Serhiy Storchaka | 8ac6581 | 2018-12-22 11:18:40 +0200 | [diff] [blame] | 1 | """Token constants.""" |
| 2 | # Auto-generated by Tools/scripts/generate_token.py |
Guido van Rossum | e7b146f | 2000-02-04 15:28:42 +0000 | [diff] [blame] | 3 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 4 | __all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF'] |
| 5 | |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 6 | ENDMARKER = 0 |
| 7 | NAME = 1 |
| 8 | NUMBER = 2 |
| 9 | STRING = 3 |
| 10 | NEWLINE = 4 |
| 11 | INDENT = 5 |
| 12 | DEDENT = 6 |
| 13 | LPAR = 7 |
| 14 | RPAR = 8 |
| 15 | LSQB = 9 |
| 16 | RSQB = 10 |
| 17 | COLON = 11 |
| 18 | COMMA = 12 |
| 19 | SEMI = 13 |
| 20 | PLUS = 14 |
| 21 | MINUS = 15 |
| 22 | STAR = 16 |
| 23 | SLASH = 17 |
| 24 | VBAR = 18 |
| 25 | AMPER = 19 |
| 26 | LESS = 20 |
| 27 | GREATER = 21 |
| 28 | EQUAL = 22 |
| 29 | DOT = 23 |
| 30 | PERCENT = 24 |
Meador Inge | 3388060 | 2012-01-15 19:15:36 -0600 | [diff] [blame] | 31 | LBRACE = 25 |
| 32 | RBRACE = 26 |
| 33 | EQEQUAL = 27 |
| 34 | NOTEQUAL = 28 |
| 35 | LESSEQUAL = 29 |
| 36 | GREATEREQUAL = 30 |
| 37 | TILDE = 31 |
| 38 | CIRCUMFLEX = 32 |
| 39 | LEFTSHIFT = 33 |
| 40 | RIGHTSHIFT = 34 |
| 41 | DOUBLESTAR = 35 |
| 42 | PLUSEQUAL = 36 |
| 43 | MINEQUAL = 37 |
| 44 | STAREQUAL = 38 |
| 45 | SLASHEQUAL = 39 |
| 46 | PERCENTEQUAL = 40 |
| 47 | AMPEREQUAL = 41 |
| 48 | VBAREQUAL = 42 |
| 49 | CIRCUMFLEXEQUAL = 43 |
| 50 | LEFTSHIFTEQUAL = 44 |
| 51 | RIGHTSHIFTEQUAL = 45 |
| 52 | DOUBLESTAREQUAL = 46 |
| 53 | DOUBLESLASH = 47 |
| 54 | DOUBLESLASHEQUAL = 48 |
| 55 | AT = 49 |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 56 | ATEQUAL = 50 |
| 57 | RARROW = 51 |
| 58 | ELLIPSIS = 52 |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 59 | COLONEQUAL = 53 |
| 60 | OP = 54 |
Guido van Rossum | 495da29 | 2019-03-07 12:38:08 -0800 | [diff] [blame] | 61 | AWAIT = 55 |
| 62 | ASYNC = 56 |
| 63 | TYPE_IGNORE = 57 |
| 64 | TYPE_COMMENT = 58 |
Albert-Jan Nijburg | fc354f0 | 2017-05-31 15:00:21 +0100 | [diff] [blame] | 65 | # These aren't used by the C tokenizer but are needed for tokenize.py |
Guido van Rossum | 495da29 | 2019-03-07 12:38:08 -0800 | [diff] [blame] | 66 | ERRORTOKEN = 59 |
| 67 | COMMENT = 60 |
| 68 | NL = 61 |
| 69 | ENCODING = 62 |
| 70 | N_TOKENS = 63 |
Albert-Jan Nijburg | fc354f0 | 2017-05-31 15:00:21 +0100 | [diff] [blame] | 71 | # Special definitions for cooperation with parser |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 72 | NT_OFFSET = 256 |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 73 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 74 | tok_name = {value: name |
| 75 | for name, value in globals().items() |
Antoine Pitrou | ea3eb88 | 2012-05-17 18:55:59 +0200 | [diff] [blame] | 76 | if isinstance(value, int) and not name.startswith('_')} |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 77 | __all__.extend(tok_name.values()) |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 78 | |
Serhiy Storchaka | 8ac6581 | 2018-12-22 11:18:40 +0200 | [diff] [blame] | 79 | EXACT_TOKEN_TYPES = { |
| 80 | '!=': NOTEQUAL, |
| 81 | '%': PERCENT, |
| 82 | '%=': PERCENTEQUAL, |
| 83 | '&': AMPER, |
| 84 | '&=': AMPEREQUAL, |
| 85 | '(': LPAR, |
| 86 | ')': RPAR, |
| 87 | '*': STAR, |
| 88 | '**': DOUBLESTAR, |
| 89 | '**=': DOUBLESTAREQUAL, |
| 90 | '*=': STAREQUAL, |
| 91 | '+': PLUS, |
| 92 | '+=': PLUSEQUAL, |
| 93 | ',': COMMA, |
| 94 | '-': MINUS, |
| 95 | '-=': MINEQUAL, |
| 96 | '->': RARROW, |
| 97 | '.': DOT, |
| 98 | '...': ELLIPSIS, |
| 99 | '/': SLASH, |
| 100 | '//': DOUBLESLASH, |
| 101 | '//=': DOUBLESLASHEQUAL, |
| 102 | '/=': SLASHEQUAL, |
| 103 | ':': COLON, |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 104 | ':=': COLONEQUAL, |
Serhiy Storchaka | 8ac6581 | 2018-12-22 11:18:40 +0200 | [diff] [blame] | 105 | ';': SEMI, |
| 106 | '<': LESS, |
| 107 | '<<': LEFTSHIFT, |
| 108 | '<<=': LEFTSHIFTEQUAL, |
| 109 | '<=': LESSEQUAL, |
| 110 | '=': EQUAL, |
| 111 | '==': EQEQUAL, |
| 112 | '>': GREATER, |
| 113 | '>=': GREATEREQUAL, |
| 114 | '>>': RIGHTSHIFT, |
| 115 | '>>=': RIGHTSHIFTEQUAL, |
| 116 | '@': AT, |
| 117 | '@=': ATEQUAL, |
| 118 | '[': LSQB, |
| 119 | ']': RSQB, |
| 120 | '^': CIRCUMFLEX, |
| 121 | '^=': CIRCUMFLEXEQUAL, |
| 122 | '{': LBRACE, |
| 123 | '|': VBAR, |
| 124 | '|=': VBAREQUAL, |
| 125 | '}': RBRACE, |
| 126 | '~': TILDE, |
| 127 | } |
| 128 | |
Guido van Rossum | 154a539 | 1996-07-21 02:17:52 +0000 | [diff] [blame] | 129 | def ISTERMINAL(x): |
| 130 | return x < NT_OFFSET |
| 131 | |
| 132 | def ISNONTERMINAL(x): |
| 133 | return x >= NT_OFFSET |
| 134 | |
| 135 | def ISEOF(x): |
| 136 | return x == ENDMARKER |