vex-ast 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vex_ast/README.md +101 -51
- vex_ast/READMEAPI.md +133 -318
- vex_ast/__init__.py +81 -72
- vex_ast/ast/README.md +87 -87
- vex_ast/ast/__init__.py +74 -74
- vex_ast/ast/core.py +71 -71
- vex_ast/ast/expressions.py +276 -276
- vex_ast/ast/interfaces.py +208 -208
- vex_ast/ast/literals.py +80 -80
- vex_ast/ast/navigator.py +225 -225
- vex_ast/ast/operators.py +135 -135
- vex_ast/ast/statements.py +351 -351
- vex_ast/ast/validators.py +121 -120
- vex_ast/ast/vex_nodes.py +279 -279
- vex_ast/parser/README.md +47 -47
- vex_ast/parser/__init__.py +26 -26
- vex_ast/parser/factory.py +190 -190
- vex_ast/parser/interfaces.py +34 -34
- vex_ast/parser/python_parser.py +831 -786
- vex_ast/registry/README.md +107 -29
- vex_ast/registry/__init__.py +51 -51
- vex_ast/registry/api.py +190 -155
- vex_ast/registry/categories.py +179 -136
- vex_ast/registry/functions/__init__.py +10 -10
- vex_ast/registry/functions/constructors.py +71 -0
- vex_ast/registry/functions/display.py +146 -146
- vex_ast/registry/functions/drivetrain.py +163 -163
- vex_ast/registry/functions/initialize.py +31 -28
- vex_ast/registry/functions/motor.py +140 -140
- vex_ast/registry/functions/sensors.py +194 -194
- vex_ast/registry/functions/timing.py +103 -103
- vex_ast/registry/language_map.py +77 -77
- vex_ast/registry/registry.py +164 -153
- vex_ast/registry/signature.py +269 -191
- vex_ast/registry/simulation_behavior.py +8 -8
- vex_ast/registry/validation.py +43 -43
- vex_ast/serialization/__init__.py +37 -37
- vex_ast/serialization/json_deserializer.py +284 -275
- vex_ast/serialization/json_serializer.py +148 -148
- vex_ast/serialization/schema.py +492 -470
- vex_ast/types/README.md +78 -26
- vex_ast/types/__init__.py +140 -140
- vex_ast/types/base.py +83 -83
- vex_ast/types/enums.py +122 -97
- vex_ast/types/objects.py +64 -64
- vex_ast/types/primitives.py +68 -68
- vex_ast/types/type_checker.py +31 -31
- vex_ast/utils/README.md +39 -39
- vex_ast/utils/__init__.py +37 -37
- vex_ast/utils/errors.py +112 -112
- vex_ast/utils/source_location.py +38 -38
- vex_ast/utils/type_definitions.py +8 -8
- vex_ast/visitors/README.md +49 -49
- vex_ast/visitors/__init__.py +27 -27
- vex_ast/visitors/analyzer.py +102 -102
- vex_ast/visitors/base.py +133 -133
- vex_ast/visitors/printer.py +196 -146
- {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/METADATA +206 -174
- vex_ast-0.2.6.dist-info/RECORD +64 -0
- vex_ast-0.2.4.dist-info/RECORD +0 -63
- {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/WHEEL +0 -0
- {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/licenses/LICENSE +0 -0
- {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/top_level.txt +0 -0
vex_ast/ast/operators.py
CHANGED
@@ -1,136 +1,136 @@
|
|
1
|
-
"""Operator definitions for the AST."""
|
2
|
-
|
3
|
-
from enum import Enum, auto
|
4
|
-
from typing import Dict, Set, cast
|
5
|
-
|
6
|
-
class OperatorType(Enum):
|
7
|
-
"""Categories of operators."""
|
8
|
-
BINARY = auto()
|
9
|
-
UNARY = auto()
|
10
|
-
COMPARISON = auto()
|
11
|
-
LOGICAL = auto()
|
12
|
-
|
13
|
-
class Operator(Enum):
|
14
|
-
"""Enumeration of supported operators."""
|
15
|
-
# Binary Arithmetic
|
16
|
-
ADD = '+'
|
17
|
-
SUBTRACT = '-'
|
18
|
-
MULTIPLY = '*'
|
19
|
-
DIVIDE = '/'
|
20
|
-
MODULO = '%'
|
21
|
-
POWER = '**'
|
22
|
-
FLOOR_DIVIDE = '//'
|
23
|
-
|
24
|
-
# Binary Bitwise
|
25
|
-
BITWISE_AND = '&'
|
26
|
-
BITWISE_OR = '|'
|
27
|
-
BITWISE_XOR = '^'
|
28
|
-
LEFT_SHIFT = '<<'
|
29
|
-
RIGHT_SHIFT = '>>'
|
30
|
-
|
31
|
-
# Binary Comparison
|
32
|
-
EQUAL = '=='
|
33
|
-
NOT_EQUAL = '!='
|
34
|
-
LESS_THAN = '<'
|
35
|
-
LESS_EQUAL = '<='
|
36
|
-
GREATER_THAN = '>'
|
37
|
-
GREATER_EQUAL = '>='
|
38
|
-
|
39
|
-
# Binary Logical
|
40
|
-
LOGICAL_AND = 'and'
|
41
|
-
LOGICAL_OR = 'or'
|
42
|
-
|
43
|
-
# Membership/Identity
|
44
|
-
IN = 'in'
|
45
|
-
NOT_IN = 'not in'
|
46
|
-
IS = 'is'
|
47
|
-
IS_NOT = 'is not'
|
48
|
-
|
49
|
-
# Object access
|
50
|
-
MEMBER_ACCESS = '.' # Add this line
|
51
|
-
|
52
|
-
# Unary Arithmetic
|
53
|
-
UNARY_PLUS = '+ (unary)'
|
54
|
-
UNARY_MINUS = '- (unary)'
|
55
|
-
|
56
|
-
# Unary Bitwise
|
57
|
-
BITWISE_NOT = '~'
|
58
|
-
|
59
|
-
# Unary Logical
|
60
|
-
LOGICAL_NOT = 'not'
|
61
|
-
|
62
|
-
@classmethod
|
63
|
-
def get_type(cls, op: 'Operator') -> OperatorType:
|
64
|
-
"""Get the type of an operator."""
|
65
|
-
if op in UNARY_OPERATORS:
|
66
|
-
return OperatorType.UNARY
|
67
|
-
if op in COMPARISON_OPERATORS:
|
68
|
-
return OperatorType.COMPARISON
|
69
|
-
if op in LOGICAL_OPERATORS:
|
70
|
-
return OperatorType.LOGICAL
|
71
|
-
return OperatorType.BINARY
|
72
|
-
|
73
|
-
# Operator sets for validation
|
74
|
-
UNARY_OPERATORS: Set[Operator] = {
|
75
|
-
Operator.UNARY_PLUS,
|
76
|
-
Operator.UNARY_MINUS,
|
77
|
-
Operator.BITWISE_NOT,
|
78
|
-
Operator.LOGICAL_NOT
|
79
|
-
}
|
80
|
-
|
81
|
-
COMPARISON_OPERATORS: Set[Operator] = {
|
82
|
-
Operator.EQUAL,
|
83
|
-
Operator.NOT_EQUAL,
|
84
|
-
Operator.LESS_THAN,
|
85
|
-
Operator.LESS_EQUAL,
|
86
|
-
Operator.GREATER_THAN,
|
87
|
-
Operator.GREATER_EQUAL,
|
88
|
-
Operator.IN,
|
89
|
-
Operator.NOT_IN,
|
90
|
-
Operator.IS,
|
91
|
-
Operator.IS_NOT
|
92
|
-
}
|
93
|
-
|
94
|
-
LOGICAL_OPERATORS: Set[Operator] = {
|
95
|
-
Operator.LOGICAL_AND,
|
96
|
-
Operator.LOGICAL_OR
|
97
|
-
}
|
98
|
-
|
99
|
-
# Mappings for parser use
|
100
|
-
PYTHON_BINARY_OP_MAP: Dict[str, Operator] = {
|
101
|
-
'+': Operator.ADD,
|
102
|
-
'-': Operator.SUBTRACT,
|
103
|
-
'*': Operator.MULTIPLY,
|
104
|
-
'/': Operator.DIVIDE,
|
105
|
-
'//': Operator.FLOOR_DIVIDE,
|
106
|
-
'%': Operator.MODULO,
|
107
|
-
'**': Operator.POWER,
|
108
|
-
'<<': Operator.LEFT_SHIFT,
|
109
|
-
'>>': Operator.RIGHT_SHIFT,
|
110
|
-
'|': Operator.BITWISE_OR,
|
111
|
-
'^': Operator.BITWISE_XOR,
|
112
|
-
'&': Operator.BITWISE_AND,
|
113
|
-
'@': Operator.MULTIPLY # Matrix multiplication, maps to regular multiply for now
|
114
|
-
}
|
115
|
-
|
116
|
-
PYTHON_BINARY_OP_MAP['.'] = Operator.MEMBER_ACCESS
|
117
|
-
|
118
|
-
PYTHON_UNARY_OP_MAP: Dict[str, Operator] = {
|
119
|
-
'+': Operator.UNARY_PLUS,
|
120
|
-
'-': Operator.UNARY_MINUS,
|
121
|
-
'not': Operator.LOGICAL_NOT,
|
122
|
-
'~': Operator.BITWISE_NOT
|
123
|
-
}
|
124
|
-
|
125
|
-
PYTHON_COMP_OP_MAP: Dict[str, Operator] = {
|
126
|
-
'==': Operator.EQUAL,
|
127
|
-
'!=': Operator.NOT_EQUAL,
|
128
|
-
'<': Operator.LESS_THAN,
|
129
|
-
'<=': Operator.LESS_EQUAL,
|
130
|
-
'>': Operator.GREATER_THAN,
|
131
|
-
'>=': Operator.GREATER_EQUAL,
|
132
|
-
'in': Operator.IN,
|
133
|
-
'not in': Operator.NOT_IN,
|
134
|
-
'is': Operator.IS,
|
135
|
-
'is not': Operator.IS_NOT
|
1
|
+
"""Operator definitions for the AST."""
|
2
|
+
|
3
|
+
from enum import Enum, auto
|
4
|
+
from typing import Dict, Set, cast
|
5
|
+
|
6
|
+
class OperatorType(Enum):
|
7
|
+
"""Categories of operators."""
|
8
|
+
BINARY = auto()
|
9
|
+
UNARY = auto()
|
10
|
+
COMPARISON = auto()
|
11
|
+
LOGICAL = auto()
|
12
|
+
|
13
|
+
class Operator(Enum):
|
14
|
+
"""Enumeration of supported operators."""
|
15
|
+
# Binary Arithmetic
|
16
|
+
ADD = '+'
|
17
|
+
SUBTRACT = '-'
|
18
|
+
MULTIPLY = '*'
|
19
|
+
DIVIDE = '/'
|
20
|
+
MODULO = '%'
|
21
|
+
POWER = '**'
|
22
|
+
FLOOR_DIVIDE = '//'
|
23
|
+
|
24
|
+
# Binary Bitwise
|
25
|
+
BITWISE_AND = '&'
|
26
|
+
BITWISE_OR = '|'
|
27
|
+
BITWISE_XOR = '^'
|
28
|
+
LEFT_SHIFT = '<<'
|
29
|
+
RIGHT_SHIFT = '>>'
|
30
|
+
|
31
|
+
# Binary Comparison
|
32
|
+
EQUAL = '=='
|
33
|
+
NOT_EQUAL = '!='
|
34
|
+
LESS_THAN = '<'
|
35
|
+
LESS_EQUAL = '<='
|
36
|
+
GREATER_THAN = '>'
|
37
|
+
GREATER_EQUAL = '>='
|
38
|
+
|
39
|
+
# Binary Logical
|
40
|
+
LOGICAL_AND = 'and'
|
41
|
+
LOGICAL_OR = 'or'
|
42
|
+
|
43
|
+
# Membership/Identity
|
44
|
+
IN = 'in'
|
45
|
+
NOT_IN = 'not in'
|
46
|
+
IS = 'is'
|
47
|
+
IS_NOT = 'is not'
|
48
|
+
|
49
|
+
# Object access
|
50
|
+
MEMBER_ACCESS = '.' # Add this line
|
51
|
+
|
52
|
+
# Unary Arithmetic
|
53
|
+
UNARY_PLUS = '+ (unary)'
|
54
|
+
UNARY_MINUS = '- (unary)'
|
55
|
+
|
56
|
+
# Unary Bitwise
|
57
|
+
BITWISE_NOT = '~'
|
58
|
+
|
59
|
+
# Unary Logical
|
60
|
+
LOGICAL_NOT = 'not'
|
61
|
+
|
62
|
+
@classmethod
|
63
|
+
def get_type(cls, op: 'Operator') -> OperatorType:
|
64
|
+
"""Get the type of an operator."""
|
65
|
+
if op in UNARY_OPERATORS:
|
66
|
+
return OperatorType.UNARY
|
67
|
+
if op in COMPARISON_OPERATORS:
|
68
|
+
return OperatorType.COMPARISON
|
69
|
+
if op in LOGICAL_OPERATORS:
|
70
|
+
return OperatorType.LOGICAL
|
71
|
+
return OperatorType.BINARY
|
72
|
+
|
73
|
+
# Operator sets for validation
|
74
|
+
UNARY_OPERATORS: Set[Operator] = {
|
75
|
+
Operator.UNARY_PLUS,
|
76
|
+
Operator.UNARY_MINUS,
|
77
|
+
Operator.BITWISE_NOT,
|
78
|
+
Operator.LOGICAL_NOT
|
79
|
+
}
|
80
|
+
|
81
|
+
COMPARISON_OPERATORS: Set[Operator] = {
|
82
|
+
Operator.EQUAL,
|
83
|
+
Operator.NOT_EQUAL,
|
84
|
+
Operator.LESS_THAN,
|
85
|
+
Operator.LESS_EQUAL,
|
86
|
+
Operator.GREATER_THAN,
|
87
|
+
Operator.GREATER_EQUAL,
|
88
|
+
Operator.IN,
|
89
|
+
Operator.NOT_IN,
|
90
|
+
Operator.IS,
|
91
|
+
Operator.IS_NOT
|
92
|
+
}
|
93
|
+
|
94
|
+
LOGICAL_OPERATORS: Set[Operator] = {
|
95
|
+
Operator.LOGICAL_AND,
|
96
|
+
Operator.LOGICAL_OR
|
97
|
+
}
|
98
|
+
|
99
|
+
# Mappings for parser use
|
100
|
+
PYTHON_BINARY_OP_MAP: Dict[str, Operator] = {
|
101
|
+
'+': Operator.ADD,
|
102
|
+
'-': Operator.SUBTRACT,
|
103
|
+
'*': Operator.MULTIPLY,
|
104
|
+
'/': Operator.DIVIDE,
|
105
|
+
'//': Operator.FLOOR_DIVIDE,
|
106
|
+
'%': Operator.MODULO,
|
107
|
+
'**': Operator.POWER,
|
108
|
+
'<<': Operator.LEFT_SHIFT,
|
109
|
+
'>>': Operator.RIGHT_SHIFT,
|
110
|
+
'|': Operator.BITWISE_OR,
|
111
|
+
'^': Operator.BITWISE_XOR,
|
112
|
+
'&': Operator.BITWISE_AND,
|
113
|
+
'@': Operator.MULTIPLY # Matrix multiplication, maps to regular multiply for now
|
114
|
+
}
|
115
|
+
|
116
|
+
PYTHON_BINARY_OP_MAP['.'] = Operator.MEMBER_ACCESS
|
117
|
+
|
118
|
+
PYTHON_UNARY_OP_MAP: Dict[str, Operator] = {
|
119
|
+
'+': Operator.UNARY_PLUS,
|
120
|
+
'-': Operator.UNARY_MINUS,
|
121
|
+
'not': Operator.LOGICAL_NOT,
|
122
|
+
'~': Operator.BITWISE_NOT
|
123
|
+
}
|
124
|
+
|
125
|
+
PYTHON_COMP_OP_MAP: Dict[str, Operator] = {
|
126
|
+
'==': Operator.EQUAL,
|
127
|
+
'!=': Operator.NOT_EQUAL,
|
128
|
+
'<': Operator.LESS_THAN,
|
129
|
+
'<=': Operator.LESS_EQUAL,
|
130
|
+
'>': Operator.GREATER_THAN,
|
131
|
+
'>=': Operator.GREATER_EQUAL,
|
132
|
+
'in': Operator.IN,
|
133
|
+
'not in': Operator.NOT_IN,
|
134
|
+
'is': Operator.IS,
|
135
|
+
'is not': Operator.IS_NOT
|
136
136
|
}
|