token.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. """Token constants."""
  2. # Auto-generated by Tools/scripts/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. OP = 54
  59. AWAIT = 55
  60. ASYNC = 56
  61. TYPE_IGNORE = 57
  62. TYPE_COMMENT = 58
  63. # These aren't used by the C tokenizer but are needed for tokenize.py
  64. ERRORTOKEN = 59
  65. COMMENT = 60
  66. NL = 61
  67. ENCODING = 62
  68. N_TOKENS = 63
  69. # Special definitions for cooperation with parser
  70. NT_OFFSET = 256
  71. tok_name = {value: name
  72. for name, value in globals().items()
  73. if isinstance(value, int) and not name.startswith('_')}
  74. __all__.extend(tok_name.values())
  75. EXACT_TOKEN_TYPES = {
  76. '!=': NOTEQUAL,
  77. '%': PERCENT,
  78. '%=': PERCENTEQUAL,
  79. '&': AMPER,
  80. '&=': AMPEREQUAL,
  81. '(': LPAR,
  82. ')': RPAR,
  83. '*': STAR,
  84. '**': DOUBLESTAR,
  85. '**=': DOUBLESTAREQUAL,
  86. '*=': STAREQUAL,
  87. '+': PLUS,
  88. '+=': PLUSEQUAL,
  89. ',': COMMA,
  90. '-': MINUS,
  91. '-=': MINEQUAL,
  92. '->': RARROW,
  93. '.': DOT,
  94. '...': ELLIPSIS,
  95. '/': SLASH,
  96. '//': DOUBLESLASH,
  97. '//=': DOUBLESLASHEQUAL,
  98. '/=': SLASHEQUAL,
  99. ':': COLON,
  100. ':=': COLONEQUAL,
  101. ';': SEMI,
  102. '<': LESS,
  103. '<<': LEFTSHIFT,
  104. '<<=': LEFTSHIFTEQUAL,
  105. '<=': LESSEQUAL,
  106. '=': EQUAL,
  107. '==': EQEQUAL,
  108. '>': GREATER,
  109. '>=': GREATEREQUAL,
  110. '>>': RIGHTSHIFT,
  111. '>>=': RIGHTSHIFTEQUAL,
  112. '@': AT,
  113. '@=': ATEQUAL,
  114. '[': LSQB,
  115. ']': RSQB,
  116. '^': CIRCUMFLEX,
  117. '^=': CIRCUMFLEXEQUAL,
  118. '{': LBRACE,
  119. '|': VBAR,
  120. '|=': VBAREQUAL,
  121. '}': RBRACE,
  122. '~': TILDE,
  123. }
  124. def ISTERMINAL(x):
  125. return x < NT_OFFSET
  126. def ISNONTERMINAL(x):
  127. return x >= NT_OFFSET
  128. def ISEOF(x):
  129. return x == ENDMARKER