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 |
| 63 | RARROW = 50 |
| 64 | ELLIPSIS = 51 |
| 65 | OP = 52 |
| 66 | ERRORTOKEN = 53 |
| 67 | N_TOKENS = 54 |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 68 | NT_OFFSET = 256 |
| 69 | #--end constants-- |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 70 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 71 | tok_name = {value: name |
| 72 | for name, value in globals().items() |
Antoine Pitrou | ea3eb88 | 2012-05-17 18:55:59 +0200 | [diff] [blame] | 73 | if isinstance(value, int) and not name.startswith('_')} |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 74 | __all__.extend(tok_name.values()) |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 75 | |
Guido van Rossum | 154a539 | 1996-07-21 02:17:52 +0000 | [diff] [blame] | 76 | def ISTERMINAL(x): |
| 77 | return x < NT_OFFSET |
| 78 | |
| 79 | def ISNONTERMINAL(x): |
| 80 | return x >= NT_OFFSET |
| 81 | |
| 82 | def ISEOF(x): |
| 83 | return x == ENDMARKER |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 84 | |
| 85 | |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 86 | def _main(): |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 87 | import re |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 88 | import sys |
| 89 | args = sys.argv[1:] |
| 90 | inFileName = args and args[0] or "Include/token.h" |
| 91 | outFileName = "Lib/token.py" |
| 92 | if len(args) > 1: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 93 | outFileName = args[1] |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 94 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 95 | fp = open(inFileName) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 96 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 97 | sys.stdout.write("I/O error: %s\n" % str(err)) |
| 98 | sys.exit(1) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 99 | lines = fp.read().split("\n") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 100 | fp.close() |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 101 | prog = re.compile( |
Michael W. Hudson | adf1606 | 2002-10-03 09:42:01 +0000 | [diff] [blame] | 102 | "#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] | 103 | re.IGNORECASE) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 104 | tokens = {} |
| 105 | for line in lines: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 106 | match = prog.match(line) |
| 107 | if match: |
| 108 | name, val = match.group(1, 2) |
Eric S. Raymond | 6e025bc | 2001-02-10 00:22:33 +0000 | [diff] [blame] | 109 | val = int(val) |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 110 | tokens[val] = name # reverse so we can sort them... |
Guido van Rossum | c145ef3 | 2007-02-26 14:08:27 +0000 | [diff] [blame] | 111 | keys = sorted(tokens.keys()) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 112 | # load the output skeleton from the target: |
| 113 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 114 | fp = open(outFileName) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 115 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 116 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 117 | sys.exit(2) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 118 | format = fp.read().split("\n") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 119 | fp.close() |
| 120 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 121 | start = format.index("#--start constants--") + 1 |
| 122 | end = format.index("#--end constants--") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 123 | except ValueError: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 124 | sys.stderr.write("target does not contain format markers") |
| 125 | sys.exit(3) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 126 | lines = [] |
| 127 | for val in keys: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 128 | lines.append("%s = %d" % (tokens[val], val)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 129 | format[start:end] = lines |
| 130 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 131 | fp = open(outFileName, 'w') |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 132 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 133 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 134 | sys.exit(4) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 135 | fp.write("\n".join(format)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 136 | fp.close() |
| 137 | |
| 138 | |
| 139 | if __name__ == "__main__": |
Alexander Belopolsky | b9d10d0 | 2010-11-11 14:07:41 +0000 | [diff] [blame] | 140 | _main() |