vex-ast 0.2.5__py3-none-any.whl → 0.2.7__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 -81
- 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 +241 -225
- vex_ast/ast/operators.py +135 -135
- vex_ast/ast/statements.py +351 -351
- vex_ast/ast/validators.py +121 -121
- 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 -831
- 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 -35
- vex_ast/registry/functions/display.py +146 -146
- vex_ast/registry/functions/drivetrain.py +163 -163
- vex_ast/registry/functions/initialize.py +31 -31
- 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 -284
- vex_ast/serialization/json_serializer.py +148 -148
- vex_ast/serialization/schema.py +492 -492
- 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 -122
- 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 -196
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.7.dist-info}/METADATA +206 -174
- vex_ast-0.2.7.dist-info/RECORD +64 -0
- vex_ast-0.2.5.dist-info/RECORD +0 -64
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.7.dist-info}/WHEEL +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.7.dist-info}/licenses/LICENSE +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.7.dist-info}/top_level.txt +0 -0
vex_ast/parser/__init__.py
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
"""
|
2
|
-
Parser package for VEX AST.
|
3
|
-
|
4
|
-
This package provides functionality for parsing VEX code into an Abstract Syntax Tree.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from .interfaces import (
|
8
|
-
IParser,
|
9
|
-
BaseParser
|
10
|
-
)
|
11
|
-
from .factory import NodeFactory, default_factory
|
12
|
-
from .python_parser import parse_string, parse_file, PythonParser
|
13
|
-
|
14
|
-
__all__ = [
|
15
|
-
# Interfaces
|
16
|
-
"IParser",
|
17
|
-
"BaseParser",
|
18
|
-
|
19
|
-
# Factory
|
20
|
-
"NodeFactory",
|
21
|
-
"default_factory",
|
22
|
-
|
23
|
-
# Python parser
|
24
|
-
"parse_string",
|
25
|
-
"parse_file",
|
26
|
-
"PythonParser"
|
1
|
+
"""
|
2
|
+
Parser package for VEX AST.
|
3
|
+
|
4
|
+
This package provides functionality for parsing VEX code into an Abstract Syntax Tree.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from .interfaces import (
|
8
|
+
IParser,
|
9
|
+
BaseParser
|
10
|
+
)
|
11
|
+
from .factory import NodeFactory, default_factory
|
12
|
+
from .python_parser import parse_string, parse_file, PythonParser
|
13
|
+
|
14
|
+
__all__ = [
|
15
|
+
# Interfaces
|
16
|
+
"IParser",
|
17
|
+
"BaseParser",
|
18
|
+
|
19
|
+
# Factory
|
20
|
+
"NodeFactory",
|
21
|
+
"default_factory",
|
22
|
+
|
23
|
+
# Python parser
|
24
|
+
"parse_string",
|
25
|
+
"parse_file",
|
26
|
+
"PythonParser"
|
27
27
|
]
|
vex_ast/parser/factory.py
CHANGED
@@ -1,190 +1,190 @@
|
|
1
|
-
"""Node factory for creating AST nodes (Factory Pattern)."""
|
2
|
-
|
3
|
-
from typing import Any, Dict, Optional, Type, Union, cast, List
|
4
|
-
|
5
|
-
from ..ast.core import Expression, Program, Statement
|
6
|
-
from ..ast.expressions import (
|
7
|
-
AttributeAccess, BinaryOperation, ConditionalExpression, FunctionCall, Identifier, KeywordArgument,
|
8
|
-
UnaryOperation, VariableReference
|
9
|
-
)
|
10
|
-
from ..ast.literals import (
|
11
|
-
BooleanLiteral, NoneLiteral, NumberLiteral, StringLiteral
|
12
|
-
)
|
13
|
-
from ..ast.operators import Operator
|
14
|
-
from ..ast.statements import (
|
15
|
-
Assignment, BreakStatement, ContinueStatement, ExpressionStatement,
|
16
|
-
ForLoop, FunctionDefinition, IfStatement, ReturnStatement, WhileLoop, Argument
|
17
|
-
)
|
18
|
-
from ..ast.vex_nodes import (
|
19
|
-
DisplayOutput, MotorControl, SensorReading, TimingControl, VexAPICall
|
20
|
-
)
|
21
|
-
from ..utils.errors import ErrorHandler
|
22
|
-
from ..utils.source_location import SourceLocation
|
23
|
-
|
24
|
-
class NodeFactory:
|
25
|
-
"""Factory for creating AST nodes."""
|
26
|
-
|
27
|
-
def __init__(self, error_handler: Optional[ErrorHandler] = None):
|
28
|
-
"""Initialize with an optional error handler."""
|
29
|
-
self.error_handler = error_handler
|
30
|
-
|
31
|
-
# --- Literals ---
|
32
|
-
|
33
|
-
def create_number_literal(self, value: Union[int, float],
|
34
|
-
location: Optional[SourceLocation] = None) -> NumberLiteral:
|
35
|
-
"""Create a number literal node."""
|
36
|
-
return NumberLiteral(value, location)
|
37
|
-
|
38
|
-
def create_string_literal(self, value: str,
|
39
|
-
location: Optional[SourceLocation] = None) -> StringLiteral:
|
40
|
-
"""Create a string literal node."""
|
41
|
-
return StringLiteral(value, location)
|
42
|
-
|
43
|
-
def create_boolean_literal(self, value: bool,
|
44
|
-
location: Optional[SourceLocation] = None) -> BooleanLiteral:
|
45
|
-
"""Create a boolean literal node."""
|
46
|
-
return BooleanLiteral(value, location)
|
47
|
-
|
48
|
-
def create_none_literal(self,
|
49
|
-
location: Optional[SourceLocation] = None) -> NoneLiteral:
|
50
|
-
"""Create a None literal node."""
|
51
|
-
return NoneLiteral(location)
|
52
|
-
|
53
|
-
# --- Expressions ---
|
54
|
-
|
55
|
-
def create_identifier(self, name: str,
|
56
|
-
location: Optional[SourceLocation] = None) -> Identifier:
|
57
|
-
"""Create an identifier node."""
|
58
|
-
return Identifier(name, location)
|
59
|
-
|
60
|
-
def create_variable_reference(self, identifier: Identifier,
|
61
|
-
location: Optional[SourceLocation] = None) -> VariableReference:
|
62
|
-
"""Create a variable reference node."""
|
63
|
-
return VariableReference(identifier, location)
|
64
|
-
|
65
|
-
def create_attribute_access(self, object_expr: Expression, attribute: str,
|
66
|
-
location: Optional[SourceLocation] = None) -> AttributeAccess:
|
67
|
-
"""Create an attribute access node."""
|
68
|
-
return AttributeAccess(object_expr, attribute, location)
|
69
|
-
|
70
|
-
def create_binary_operation(self, left: Expression, op: Operator, right: Expression,
|
71
|
-
location: Optional[SourceLocation] = None) -> BinaryOperation:
|
72
|
-
"""Create a binary operation node."""
|
73
|
-
return BinaryOperation(left, op, right, location)
|
74
|
-
|
75
|
-
def create_unary_operation(self, op: Operator, operand: Expression,
|
76
|
-
location: Optional[SourceLocation] = None) -> UnaryOperation:
|
77
|
-
"""Create a unary operation node."""
|
78
|
-
return UnaryOperation(op, operand, location)
|
79
|
-
|
80
|
-
def create_conditional_expression(self, condition: Expression, true_expr: Expression, false_expr: Expression,
|
81
|
-
location: Optional[SourceLocation] = None) -> ConditionalExpression:
|
82
|
-
"""Create a conditional expression (ternary operator) node."""
|
83
|
-
return ConditionalExpression(condition, true_expr, false_expr, location)
|
84
|
-
|
85
|
-
def create_function_call(self, function: Expression, args: List[Expression] = None,
|
86
|
-
keywords: List[KeywordArgument] = None,
|
87
|
-
location: Optional[SourceLocation] = None) -> FunctionCall:
|
88
|
-
"""Create a function call node."""
|
89
|
-
return FunctionCall(function, args or [], keywords or [], location)
|
90
|
-
|
91
|
-
def create_keyword_argument(self, name: str, value: Expression,
|
92
|
-
location: Optional[SourceLocation] = None) -> KeywordArgument:
|
93
|
-
"""Create a keyword argument node."""
|
94
|
-
return KeywordArgument(name, value, location)
|
95
|
-
|
96
|
-
# --- Statements ---
|
97
|
-
|
98
|
-
def create_expression_statement(self, expression: Expression,
|
99
|
-
location: Optional[SourceLocation] = None) -> ExpressionStatement:
|
100
|
-
"""Create an expression statement node."""
|
101
|
-
return ExpressionStatement(expression, location)
|
102
|
-
|
103
|
-
def create_assignment(self, target: Expression, value: Expression,
|
104
|
-
location: Optional[SourceLocation] = None) -> Assignment:
|
105
|
-
"""Create an assignment statement node."""
|
106
|
-
return Assignment(target, value, location)
|
107
|
-
|
108
|
-
def create_if_statement(self, test: Expression, body: List[Statement],
|
109
|
-
orelse: Optional[Union[List[Statement], IfStatement]] = None,
|
110
|
-
location: Optional[SourceLocation] = None) -> IfStatement:
|
111
|
-
"""Create an if statement node."""
|
112
|
-
return IfStatement(test, body, orelse, location)
|
113
|
-
|
114
|
-
def create_while_loop(self, test: Expression, body: List[Statement],
|
115
|
-
location: Optional[SourceLocation] = None) -> WhileLoop:
|
116
|
-
"""Create a while loop node."""
|
117
|
-
return WhileLoop(test, body, location)
|
118
|
-
|
119
|
-
def create_for_loop(self, target: Expression, iterable: Expression,
|
120
|
-
body: List[Statement],
|
121
|
-
location: Optional[SourceLocation] = None) -> ForLoop:
|
122
|
-
"""Create a for loop node."""
|
123
|
-
return ForLoop(target, iterable, body, location)
|
124
|
-
|
125
|
-
def create_function_definition(self, name: str, args: List[Argument], body: List[Statement],
|
126
|
-
return_annotation: Optional[Expression] = None,
|
127
|
-
location: Optional[SourceLocation] = None) -> FunctionDefinition:
|
128
|
-
"""Create a function definition node."""
|
129
|
-
return FunctionDefinition(name, args, body, return_annotation, location)
|
130
|
-
|
131
|
-
def create_argument(self, name: str, annotation: Optional[Expression] = None,
|
132
|
-
default: Optional[Expression] = None,
|
133
|
-
location: Optional[SourceLocation] = None) -> Argument:
|
134
|
-
"""Create an argument node."""
|
135
|
-
return Argument(name, annotation, default, location)
|
136
|
-
|
137
|
-
def create_return_statement(self, value: Optional[Expression] = None,
|
138
|
-
location: Optional[SourceLocation] = None) -> ReturnStatement:
|
139
|
-
"""Create a return statement node."""
|
140
|
-
return ReturnStatement(value, location)
|
141
|
-
|
142
|
-
def create_break_statement(self,
|
143
|
-
location: Optional[SourceLocation] = None) -> BreakStatement:
|
144
|
-
"""Create a break statement node."""
|
145
|
-
return BreakStatement(location)
|
146
|
-
|
147
|
-
def create_continue_statement(self,
|
148
|
-
location: Optional[SourceLocation] = None) -> ContinueStatement:
|
149
|
-
"""Create a continue statement node."""
|
150
|
-
return ContinueStatement(location)
|
151
|
-
|
152
|
-
# --- VEX-specific Nodes ---
|
153
|
-
|
154
|
-
def create_vex_api_call(self, function: Expression, args: List[Expression],
|
155
|
-
keywords: List[KeywordArgument] = None,
|
156
|
-
location: Optional[SourceLocation] = None) -> VexAPICall:
|
157
|
-
"""Create a VEX API call node."""
|
158
|
-
return VexAPICall(function, args, keywords or [], location)
|
159
|
-
|
160
|
-
def create_motor_control(self, function: Expression, args: List[Expression],
|
161
|
-
keywords: List[KeywordArgument] = None,
|
162
|
-
location: Optional[SourceLocation] = None) -> MotorControl:
|
163
|
-
"""Create a motor control node."""
|
164
|
-
return MotorControl(function, args, keywords or [], location)
|
165
|
-
|
166
|
-
def create_sensor_reading(self, function: Expression, args: List[Expression],
|
167
|
-
keywords: List[KeywordArgument] = None,
|
168
|
-
location: Optional[SourceLocation] = None) -> SensorReading:
|
169
|
-
"""Create a sensor reading node."""
|
170
|
-
return SensorReading(function, args, keywords or [], location)
|
171
|
-
|
172
|
-
def create_timing_control(self, function: Expression, args: List[Expression],
|
173
|
-
keywords: List[KeywordArgument] = None,
|
174
|
-
location: Optional[SourceLocation] = None) -> TimingControl:
|
175
|
-
"""Create a timing control node."""
|
176
|
-
return TimingControl(function, args, keywords or [], location)
|
177
|
-
|
178
|
-
def create_display_output(self, function: Expression, args: List[Expression],
|
179
|
-
keywords: List[KeywordArgument] = None,
|
180
|
-
location: Optional[SourceLocation] = None) -> DisplayOutput:
|
181
|
-
"""Create a display output node."""
|
182
|
-
return DisplayOutput(function, args, keywords or [], location)
|
183
|
-
|
184
|
-
def create_program(self, body: List[Statement],
|
185
|
-
location: Optional[SourceLocation] = None) -> Program:
|
186
|
-
"""Create a program node."""
|
187
|
-
return Program(body, location)
|
188
|
-
|
189
|
-
# Global factory instance for simple use cases
|
190
|
-
default_factory = NodeFactory()
|
1
|
+
"""Node factory for creating AST nodes (Factory Pattern)."""
|
2
|
+
|
3
|
+
from typing import Any, Dict, Optional, Type, Union, cast, List
|
4
|
+
|
5
|
+
from ..ast.core import Expression, Program, Statement
|
6
|
+
from ..ast.expressions import (
|
7
|
+
AttributeAccess, BinaryOperation, ConditionalExpression, FunctionCall, Identifier, KeywordArgument,
|
8
|
+
UnaryOperation, VariableReference
|
9
|
+
)
|
10
|
+
from ..ast.literals import (
|
11
|
+
BooleanLiteral, NoneLiteral, NumberLiteral, StringLiteral
|
12
|
+
)
|
13
|
+
from ..ast.operators import Operator
|
14
|
+
from ..ast.statements import (
|
15
|
+
Assignment, BreakStatement, ContinueStatement, ExpressionStatement,
|
16
|
+
ForLoop, FunctionDefinition, IfStatement, ReturnStatement, WhileLoop, Argument
|
17
|
+
)
|
18
|
+
from ..ast.vex_nodes import (
|
19
|
+
DisplayOutput, MotorControl, SensorReading, TimingControl, VexAPICall
|
20
|
+
)
|
21
|
+
from ..utils.errors import ErrorHandler
|
22
|
+
from ..utils.source_location import SourceLocation
|
23
|
+
|
24
|
+
class NodeFactory:
|
25
|
+
"""Factory for creating AST nodes."""
|
26
|
+
|
27
|
+
def __init__(self, error_handler: Optional[ErrorHandler] = None):
|
28
|
+
"""Initialize with an optional error handler."""
|
29
|
+
self.error_handler = error_handler
|
30
|
+
|
31
|
+
# --- Literals ---
|
32
|
+
|
33
|
+
def create_number_literal(self, value: Union[int, float],
|
34
|
+
location: Optional[SourceLocation] = None) -> NumberLiteral:
|
35
|
+
"""Create a number literal node."""
|
36
|
+
return NumberLiteral(value, location)
|
37
|
+
|
38
|
+
def create_string_literal(self, value: str,
|
39
|
+
location: Optional[SourceLocation] = None) -> StringLiteral:
|
40
|
+
"""Create a string literal node."""
|
41
|
+
return StringLiteral(value, location)
|
42
|
+
|
43
|
+
def create_boolean_literal(self, value: bool,
|
44
|
+
location: Optional[SourceLocation] = None) -> BooleanLiteral:
|
45
|
+
"""Create a boolean literal node."""
|
46
|
+
return BooleanLiteral(value, location)
|
47
|
+
|
48
|
+
def create_none_literal(self,
|
49
|
+
location: Optional[SourceLocation] = None) -> NoneLiteral:
|
50
|
+
"""Create a None literal node."""
|
51
|
+
return NoneLiteral(location)
|
52
|
+
|
53
|
+
# --- Expressions ---
|
54
|
+
|
55
|
+
def create_identifier(self, name: str,
|
56
|
+
location: Optional[SourceLocation] = None) -> Identifier:
|
57
|
+
"""Create an identifier node."""
|
58
|
+
return Identifier(name, location)
|
59
|
+
|
60
|
+
def create_variable_reference(self, identifier: Identifier,
|
61
|
+
location: Optional[SourceLocation] = None) -> VariableReference:
|
62
|
+
"""Create a variable reference node."""
|
63
|
+
return VariableReference(identifier, location)
|
64
|
+
|
65
|
+
def create_attribute_access(self, object_expr: Expression, attribute: str,
|
66
|
+
location: Optional[SourceLocation] = None) -> AttributeAccess:
|
67
|
+
"""Create an attribute access node."""
|
68
|
+
return AttributeAccess(object_expr, attribute, location)
|
69
|
+
|
70
|
+
def create_binary_operation(self, left: Expression, op: Operator, right: Expression,
|
71
|
+
location: Optional[SourceLocation] = None) -> BinaryOperation:
|
72
|
+
"""Create a binary operation node."""
|
73
|
+
return BinaryOperation(left, op, right, location)
|
74
|
+
|
75
|
+
def create_unary_operation(self, op: Operator, operand: Expression,
|
76
|
+
location: Optional[SourceLocation] = None) -> UnaryOperation:
|
77
|
+
"""Create a unary operation node."""
|
78
|
+
return UnaryOperation(op, operand, location)
|
79
|
+
|
80
|
+
def create_conditional_expression(self, condition: Expression, true_expr: Expression, false_expr: Expression,
|
81
|
+
location: Optional[SourceLocation] = None) -> ConditionalExpression:
|
82
|
+
"""Create a conditional expression (ternary operator) node."""
|
83
|
+
return ConditionalExpression(condition, true_expr, false_expr, location)
|
84
|
+
|
85
|
+
def create_function_call(self, function: Expression, args: List[Expression] = None,
|
86
|
+
keywords: List[KeywordArgument] = None,
|
87
|
+
location: Optional[SourceLocation] = None) -> FunctionCall:
|
88
|
+
"""Create a function call node."""
|
89
|
+
return FunctionCall(function, args or [], keywords or [], location)
|
90
|
+
|
91
|
+
def create_keyword_argument(self, name: str, value: Expression,
|
92
|
+
location: Optional[SourceLocation] = None) -> KeywordArgument:
|
93
|
+
"""Create a keyword argument node."""
|
94
|
+
return KeywordArgument(name, value, location)
|
95
|
+
|
96
|
+
# --- Statements ---
|
97
|
+
|
98
|
+
def create_expression_statement(self, expression: Expression,
|
99
|
+
location: Optional[SourceLocation] = None) -> ExpressionStatement:
|
100
|
+
"""Create an expression statement node."""
|
101
|
+
return ExpressionStatement(expression, location)
|
102
|
+
|
103
|
+
def create_assignment(self, target: Expression, value: Expression,
|
104
|
+
location: Optional[SourceLocation] = None) -> Assignment:
|
105
|
+
"""Create an assignment statement node."""
|
106
|
+
return Assignment(target, value, location)
|
107
|
+
|
108
|
+
def create_if_statement(self, test: Expression, body: List[Statement],
|
109
|
+
orelse: Optional[Union[List[Statement], IfStatement]] = None,
|
110
|
+
location: Optional[SourceLocation] = None) -> IfStatement:
|
111
|
+
"""Create an if statement node."""
|
112
|
+
return IfStatement(test, body, orelse, location)
|
113
|
+
|
114
|
+
def create_while_loop(self, test: Expression, body: List[Statement],
|
115
|
+
location: Optional[SourceLocation] = None) -> WhileLoop:
|
116
|
+
"""Create a while loop node."""
|
117
|
+
return WhileLoop(test, body, location)
|
118
|
+
|
119
|
+
def create_for_loop(self, target: Expression, iterable: Expression,
|
120
|
+
body: List[Statement],
|
121
|
+
location: Optional[SourceLocation] = None) -> ForLoop:
|
122
|
+
"""Create a for loop node."""
|
123
|
+
return ForLoop(target, iterable, body, location)
|
124
|
+
|
125
|
+
def create_function_definition(self, name: str, args: List[Argument], body: List[Statement],
|
126
|
+
return_annotation: Optional[Expression] = None,
|
127
|
+
location: Optional[SourceLocation] = None) -> FunctionDefinition:
|
128
|
+
"""Create a function definition node."""
|
129
|
+
return FunctionDefinition(name, args, body, return_annotation, location)
|
130
|
+
|
131
|
+
def create_argument(self, name: str, annotation: Optional[Expression] = None,
|
132
|
+
default: Optional[Expression] = None,
|
133
|
+
location: Optional[SourceLocation] = None) -> Argument:
|
134
|
+
"""Create an argument node."""
|
135
|
+
return Argument(name, annotation, default, location)
|
136
|
+
|
137
|
+
def create_return_statement(self, value: Optional[Expression] = None,
|
138
|
+
location: Optional[SourceLocation] = None) -> ReturnStatement:
|
139
|
+
"""Create a return statement node."""
|
140
|
+
return ReturnStatement(value, location)
|
141
|
+
|
142
|
+
def create_break_statement(self,
|
143
|
+
location: Optional[SourceLocation] = None) -> BreakStatement:
|
144
|
+
"""Create a break statement node."""
|
145
|
+
return BreakStatement(location)
|
146
|
+
|
147
|
+
def create_continue_statement(self,
|
148
|
+
location: Optional[SourceLocation] = None) -> ContinueStatement:
|
149
|
+
"""Create a continue statement node."""
|
150
|
+
return ContinueStatement(location)
|
151
|
+
|
152
|
+
# --- VEX-specific Nodes ---
|
153
|
+
|
154
|
+
def create_vex_api_call(self, function: Expression, args: List[Expression],
|
155
|
+
keywords: List[KeywordArgument] = None,
|
156
|
+
location: Optional[SourceLocation] = None) -> VexAPICall:
|
157
|
+
"""Create a VEX API call node."""
|
158
|
+
return VexAPICall(function, args, keywords or [], location)
|
159
|
+
|
160
|
+
def create_motor_control(self, function: Expression, args: List[Expression],
|
161
|
+
keywords: List[KeywordArgument] = None,
|
162
|
+
location: Optional[SourceLocation] = None) -> MotorControl:
|
163
|
+
"""Create a motor control node."""
|
164
|
+
return MotorControl(function, args, keywords or [], location)
|
165
|
+
|
166
|
+
def create_sensor_reading(self, function: Expression, args: List[Expression],
|
167
|
+
keywords: List[KeywordArgument] = None,
|
168
|
+
location: Optional[SourceLocation] = None) -> SensorReading:
|
169
|
+
"""Create a sensor reading node."""
|
170
|
+
return SensorReading(function, args, keywords or [], location)
|
171
|
+
|
172
|
+
def create_timing_control(self, function: Expression, args: List[Expression],
|
173
|
+
keywords: List[KeywordArgument] = None,
|
174
|
+
location: Optional[SourceLocation] = None) -> TimingControl:
|
175
|
+
"""Create a timing control node."""
|
176
|
+
return TimingControl(function, args, keywords or [], location)
|
177
|
+
|
178
|
+
def create_display_output(self, function: Expression, args: List[Expression],
|
179
|
+
keywords: List[KeywordArgument] = None,
|
180
|
+
location: Optional[SourceLocation] = None) -> DisplayOutput:
|
181
|
+
"""Create a display output node."""
|
182
|
+
return DisplayOutput(function, args, keywords or [], location)
|
183
|
+
|
184
|
+
def create_program(self, body: List[Statement],
|
185
|
+
location: Optional[SourceLocation] = None) -> Program:
|
186
|
+
"""Create a program node."""
|
187
|
+
return Program(body, location)
|
188
|
+
|
189
|
+
# Global factory instance for simple use cases
|
190
|
+
default_factory = NodeFactory()
|
vex_ast/parser/interfaces.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
"""Parser interfaces and protocols."""
|
2
|
-
|
3
|
-
from abc import ABC, abstractmethod
|
4
|
-
from typing import Protocol, Optional
|
5
|
-
|
6
|
-
from ..ast.core import Program
|
7
|
-
from ..utils.errors import ErrorHandler
|
8
|
-
|
9
|
-
class IParser(Protocol):
|
10
|
-
"""Protocol for parser implementations."""
|
11
|
-
|
12
|
-
def parse(self) -> Program:
|
13
|
-
"""Parse the input and return an AST."""
|
14
|
-
...
|
15
|
-
|
16
|
-
@property
|
17
|
-
def error_handler(self) -> Optional[ErrorHandler]:
|
18
|
-
"""Get the parser's error handler."""
|
19
|
-
...
|
20
|
-
|
21
|
-
class BaseParser(ABC):
|
22
|
-
"""Abstract base class for parsers."""
|
23
|
-
|
24
|
-
def __init__(self, error_handler: Optional[ErrorHandler] = None):
|
25
|
-
self._error_handler = error_handler or ErrorHandler()
|
26
|
-
|
27
|
-
@property
|
28
|
-
def error_handler(self) -> ErrorHandler:
|
29
|
-
"""Get the parser's error handler."""
|
30
|
-
return self._error_handler
|
31
|
-
|
32
|
-
@abstractmethod
|
33
|
-
def parse(self) -> Program:
|
34
|
-
"""Parse the input and return an AST."""
|
1
|
+
"""Parser interfaces and protocols."""
|
2
|
+
|
3
|
+
from abc import ABC, abstractmethod
|
4
|
+
from typing import Protocol, Optional
|
5
|
+
|
6
|
+
from ..ast.core import Program
|
7
|
+
from ..utils.errors import ErrorHandler
|
8
|
+
|
9
|
+
class IParser(Protocol):
|
10
|
+
"""Protocol for parser implementations."""
|
11
|
+
|
12
|
+
def parse(self) -> Program:
|
13
|
+
"""Parse the input and return an AST."""
|
14
|
+
...
|
15
|
+
|
16
|
+
@property
|
17
|
+
def error_handler(self) -> Optional[ErrorHandler]:
|
18
|
+
"""Get the parser's error handler."""
|
19
|
+
...
|
20
|
+
|
21
|
+
class BaseParser(ABC):
|
22
|
+
"""Abstract base class for parsers."""
|
23
|
+
|
24
|
+
def __init__(self, error_handler: Optional[ErrorHandler] = None):
|
25
|
+
self._error_handler = error_handler or ErrorHandler()
|
26
|
+
|
27
|
+
@property
|
28
|
+
def error_handler(self) -> ErrorHandler:
|
29
|
+
"""Get the parser's error handler."""
|
30
|
+
return self._error_handler
|
31
|
+
|
32
|
+
@abstractmethod
|
33
|
+
def parse(self) -> Program:
|
34
|
+
"""Parse the input and return an AST."""
|
35
35
|
pass
|