Guido van Rossum | e7b146f | 2000-02-04 15:28:42 +0000 | [diff] [blame] | 1 | """Token constants (from "token.h").""" |
| 2 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 3 | __all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF'] |
| 4 | |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 5 | # This file is automatically generated; please don't muck it up! |
| 6 | # |
| 7 | # To update the symbols in this file, 'cd' to the top directory of |
| 8 | # the python source tree after building the interpreter and run: |
| 9 | # |
Éric Araujo | e1886bf | 2011-11-29 16:45:34 +0100 | [diff] [blame] | 10 | # ./python Lib/token.py |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 12 | #--start constants-- |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 13 | ENDMARKER = 0 |
| 14 | NAME = 1 |
| 15 | NUMBER = 2 |
| 16 | STRING = 3 |
| 17 | NEWLINE = 4 |
| 18 | INDENT = 5 |
| 19 | DEDENT = 6 |
| 20 | LPAR = 7 |
| 21 | RPAR = 8 |
| 22 | LSQB = 9 |
| 23 | RSQB = 10 |
| 24 | COLON = 11 |
| 25 | COMMA = 12 |
| 26 | SEMI = 13 |
| 27 | PLUS = 14 |
| 28 | MINUS = 15 |
| 29 | STAR = 16 |
| 30 | SLASH = 17 |
| 31 | VBAR = 18 |
| 32 | AMPER = 19 |
| 33 | LESS = 20 |
| 34 | GREATER = 21 |
| 35 | EQUAL = 22 |
| 36 | DOT = 23 |
| 37 | PERCENT = 24 |
Meador Inge | 3388060 | 2012-01-15 19:15:36 -0600 | [diff] [blame] | 38 | LBRACE = 25 |
| 39 | RBRACE = 26 |
| 40 | EQEQUAL = 27 |
| 41 | NOTEQUAL = 28 |
| 42 | LESSEQUAL = 29 |
| 43 | GREATEREQUAL = 30 |
| 44 | TILDE = 31 |
| 45 | CIRCUMFLEX = 32 |
| 46 | LEFTSHIFT = 33 |
| 47 | RIGHTSHIFT = 34 |
| 48 | DOUBLESTAR = 35 |
| 49 | PLUSEQUAL = 36 |
| 50 | MINEQUAL = 37 |
| 51 | STAREQUAL = 38 |
| 52 | SLASHEQUAL = 39 |
| 53 | PERCENTEQUAL = 40 |
| 54 | AMPEREQUAL = 41 |
| 55 | VBAREQUAL = 42 |
| 56 | CIRCUMFLEXEQUAL = 43 |
| 57 | LEFTSHIFTEQUAL = 44 |
| 58 | RIGHTSHIFTEQUAL = 45 |
| 59 | DOUBLESTAREQUAL = 46 |
| 60 | DOUBLESLASH = 47 |
| 61 | DOUBLESLASHEQUAL = 48 |
| 62 | AT = 49 |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 63 | ATEQUAL = 50 |
| 64 | RARROW = 51 |
| 65 | ELLIPSIS = 52 |
| 66 | OP = 53 |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 67 | AWAIT = 54 |
| 68 | ASYNC = 55 |
| 69 | ERRORTOKEN = 56 |
| 70 | N_TOKENS = 57 |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 71 | NT_OFFSET = 256 |
| 72 | #--end constants-- |
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 | |
Guido van Rossum | 154a539 | 1996-07-21 02:17:52 +0000 | [diff] [blame] | 79 | def ISTERMINAL(x): |
| 80 | return x < NT_OFFSET |
| 81 | |
| 82 | def ISNONTERMINAL(x): |
| 83 | return x >= NT_OFFSET |
| 84 | |
| 85 | def ISEOF(x): |
| 86 | return x == ENDMARKER |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 87 | |
| 88 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 89 | def _main(): |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 90 | import re |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 91 | import sys |
| 92 | args = sys.argv[1:] |
| 93 | inFileName = args and args[0] or "Include/token.h" |
| 94 | outFileName = "Lib/token.py" |
| 95 | if len(args) > 1: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 96 | outFileName = args[1] |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 97 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 98 | fp = open(inFileName) |
Andrew Svetlov | f7a17b4 | 2012-12-25 16:47:37 +0200 | [diff] [blame] | 99 | except OSError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 100 | sys.stdout.write("I/O error: %s\n" % str(err)) |
| 101 | sys.exit(1) |
Serhiy Storchaka | 46ba6c8 | 2015-04-04 11:01:02 +0300 | [diff] [blame] | 102 | with fp: |
| 103 | lines = fp.read().split("\n") |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 104 | prog = re.compile( |
Michael W. Hudson | adf1606 | 2002-10-03 09:42:01 +0000 | [diff] [blame] | 105 | "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 106 | re.IGNORECASE) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 107 | tokens = {} |
| 108 | for line in lines: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 109 | match = prog.match(line) |
| 110 | if match: |
| 111 | name, val = match.group(1, 2) |
Eric S. Raymond | 6e025bc | 2001-02-10 00:22:33 +0000 | [diff] [blame] | 112 | val = int(val) |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 113 | tokens[val] = name # reverse so we can sort them... |
Guido van Rossum | c145ef3 | 2007-02-26 14:08:27 +0000 | [diff] [blame] | 114 | keys = sorted(tokens.keys()) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 115 | # load the output skeleton from the target: |
| 116 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 117 | fp = open(outFileName) |
Andrew Svetlov | f7a17b4 | 2012-12-25 16:47:37 +0200 | [diff] [blame] | 118 | except OSError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 119 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 120 | sys.exit(2) |
Serhiy Storchaka | 46ba6c8 | 2015-04-04 11:01:02 +0300 | [diff] [blame] | 121 | with fp: |
| 122 | format = fp.read().split("\n") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 123 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 124 | start = format.index("#--start constants--") + 1 |
| 125 | end = format.index("#--end constants--") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 126 | except ValueError: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 127 | sys.stderr.write("target does not contain format markers") |
| 128 | sys.exit(3) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 129 | lines = [] |
| 130 | for val in keys: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 131 | lines.append("%s = %d" % (tokens[val], val)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 132 | format[start:end] = lines |
| 133 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 134 | fp = open(outFileName, 'w') |
Andrew Svetlov | f7a17b4 | 2012-12-25 16:47:37 +0200 | [diff] [blame] | 135 | except OSError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 136 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 137 | sys.exit(4) |
Serhiy Storchaka | 46ba6c8 | 2015-04-04 11:01:02 +0300 | [diff] [blame] | 138 | with fp: |
| 139 | fp.write("\n".join(format)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 140 | |
| 141 | |
| 142 | if __name__ == "__main__": |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 143 | _main() |