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