/
parser_constants.py
62 lines (56 loc) · 1.17 KB
/
parser_constants.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
"""Parser constants that are used by parser.py and visitors.py."""
import re
# PyTD keywords
RESERVED = [
'async',
'class',
'def',
'else',
'elif',
'if',
'or',
'pass',
'import',
'from',
'as',
'raise',
# Keywords that are valid identifiers in Python (PyTD keywords):
'nothing',
# Names from typing.py
'NamedTuple',
'TypeVar',
]
RESERVED_PYTHON = [
# Python keywords that aren't used by PyTD:
'and',
'assert',
'break',
'continue',
'del',
'elif',
'except',
'exec',
'finally',
'for',
'global',
'in',
'is',
'lambda',
'not',
# 'print', # Not reserved in Python3
'raise',
'return',
'try',
'while',
'with',
'yield',
]
# parser.t_NAME's regexp allows a few extra characters in the name.
# A less-pedantic RE is r'[-~]'.
# See visitors._EscapedName and parser.PyLexer.t_NAME
BACKTICK_NAME = re.compile(r'[-]|^~')
# Marks external NamedTypes so that they do not get prefixed by the current
# module name.
EXTERNAL_NAME_PREFIX = '$external$'
# Regex for string literals.
STRING_RE = re.compile("^([bu]?)(('[^']*')|(\"[^\"]*\"))$")