token.py 2.4 KB

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