vex-ast 0.2.5__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.
Files changed (63) hide show
  1. vex_ast/README.md +101 -51
  2. vex_ast/READMEAPI.md +133 -318
  3. vex_ast/__init__.py +81 -81
  4. vex_ast/ast/README.md +87 -87
  5. vex_ast/ast/__init__.py +74 -74
  6. vex_ast/ast/core.py +71 -71
  7. vex_ast/ast/expressions.py +276 -276
  8. vex_ast/ast/interfaces.py +208 -208
  9. vex_ast/ast/literals.py +80 -80
  10. vex_ast/ast/navigator.py +225 -225
  11. vex_ast/ast/operators.py +135 -135
  12. vex_ast/ast/statements.py +351 -351
  13. vex_ast/ast/validators.py +121 -121
  14. vex_ast/ast/vex_nodes.py +279 -279
  15. vex_ast/parser/README.md +47 -47
  16. vex_ast/parser/__init__.py +26 -26
  17. vex_ast/parser/factory.py +190 -190
  18. vex_ast/parser/interfaces.py +34 -34
  19. vex_ast/parser/python_parser.py +831 -831
  20. vex_ast/registry/README.md +107 -29
  21. vex_ast/registry/__init__.py +51 -51
  22. vex_ast/registry/api.py +190 -155
  23. vex_ast/registry/categories.py +179 -136
  24. vex_ast/registry/functions/__init__.py +10 -10
  25. vex_ast/registry/functions/constructors.py +71 -35
  26. vex_ast/registry/functions/display.py +146 -146
  27. vex_ast/registry/functions/drivetrain.py +163 -163
  28. vex_ast/registry/functions/initialize.py +31 -31
  29. vex_ast/registry/functions/motor.py +140 -140
  30. vex_ast/registry/functions/sensors.py +194 -194
  31. vex_ast/registry/functions/timing.py +103 -103
  32. vex_ast/registry/language_map.py +77 -77
  33. vex_ast/registry/registry.py +164 -153
  34. vex_ast/registry/signature.py +269 -191
  35. vex_ast/registry/simulation_behavior.py +8 -8
  36. vex_ast/registry/validation.py +43 -43
  37. vex_ast/serialization/__init__.py +37 -37
  38. vex_ast/serialization/json_deserializer.py +284 -284
  39. vex_ast/serialization/json_serializer.py +148 -148
  40. vex_ast/serialization/schema.py +492 -492
  41. vex_ast/types/README.md +78 -26
  42. vex_ast/types/__init__.py +140 -140
  43. vex_ast/types/base.py +83 -83
  44. vex_ast/types/enums.py +122 -122
  45. vex_ast/types/objects.py +64 -64
  46. vex_ast/types/primitives.py +68 -68
  47. vex_ast/types/type_checker.py +31 -31
  48. vex_ast/utils/README.md +39 -39
  49. vex_ast/utils/__init__.py +37 -37
  50. vex_ast/utils/errors.py +112 -112
  51. vex_ast/utils/source_location.py +38 -38
  52. vex_ast/utils/type_definitions.py +8 -8
  53. vex_ast/visitors/README.md +49 -49
  54. vex_ast/visitors/__init__.py +27 -27
  55. vex_ast/visitors/analyzer.py +102 -102
  56. vex_ast/visitors/base.py +133 -133
  57. vex_ast/visitors/printer.py +196 -196
  58. {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/METADATA +206 -174
  59. vex_ast-0.2.6.dist-info/RECORD +64 -0
  60. vex_ast-0.2.5.dist-info/RECORD +0 -64
  61. {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/WHEEL +0 -0
  62. {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/licenses/LICENSE +0 -0
  63. {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/top_level.txt +0 -0
vex_ast/ast/validators.py CHANGED
@@ -1,121 +1,121 @@
1
- """AST validators that use the function registry."""
2
-
3
- from typing import List, Dict, Set, Optional, Tuple
4
- from .core import Program
5
- from .expressions import FunctionCall, AttributeAccess, Identifier
6
- from .vex_nodes import VexAPICall
7
- from ..visitors.base import AstVisitor
8
- from ..registry.api import registry_api
9
-
10
- class VexFunctionValidator(AstVisitor[List[Tuple[VexAPICall, str]]]):
11
- """Validates VEX function calls in the AST"""
12
-
13
- def __init__(self):
14
- self.errors: List[Tuple[VexAPICall, str]] = []
15
-
16
- def generic_visit(self, node):
17
- """Visit children of non-VEX-specific nodes"""
18
- for child in node.get_children():
19
- self.visit(child)
20
- return self.errors
21
-
22
- def visit_vexapicall(self, node: VexAPICall):
23
- """Validate a VEX API call"""
24
- valid, error = node.validate()
25
- if not valid and error:
26
- self.errors.append((node, error))
27
-
28
- # Still visit children for nested calls
29
- for child in node.get_children():
30
- self.visit(child)
31
-
32
- return self.errors
33
-
34
- visit_program = generic_visit
35
- visit_expression = generic_visit
36
- visit_statement = generic_visit
37
- visit_identifier = generic_visit
38
- visit_variablereference = generic_visit
39
- visit_attributeaccess = generic_visit
40
- visit_binaryoperation = generic_visit
41
- visit_unaryoperation = generic_visit
42
- visit_keywordargument = generic_visit
43
- visit_numberliteral = generic_visit
44
- visit_stringliteral = generic_visit
45
- visit_booleanliteral = generic_visit
46
- visit_noneliteral = generic_visit
47
- visit_expressionstatement = generic_visit
48
- visit_assignment = generic_visit
49
- visit_ifstatement = generic_visit
50
- visit_whileloop = generic_visit
51
- visit_forloop = generic_visit
52
- visit_functiondefinition = generic_visit
53
- visit_argument = generic_visit
54
- visit_returnstatement = generic_visit
55
- visit_breakstatement = generic_visit
56
- visit_continuestatement = generic_visit
57
- visit_motorcontrol = visit_vexapicall
58
- visit_sensorreading = visit_vexapicall
59
- visit_timingcontrol = visit_vexapicall
60
- visit_displayoutput = visit_vexapicall
61
-
62
- def visit_functioncall(self, node: FunctionCall):
63
- """Check if a regular function call is actually a VEX API call"""
64
- # Try to determine if this is a VEX function call
65
- function_name = None
66
-
67
- # Direct function name
68
- if isinstance(node.function, Identifier):
69
- function_name = node.function.name
70
-
71
- # Method call like motor.spin()
72
- elif isinstance(node.function, AttributeAccess):
73
- obj = node.function.object
74
- if isinstance(obj, Identifier):
75
- function_name = f"{obj.name}.{node.function.attribute}"
76
-
77
- # Initialize is_vex_function to False by default
78
- is_vex_function = False
79
-
80
- # Check if this is a known VEX function
81
- if function_name:
82
- # Check if this is a method call on a known object type
83
- if '.' in function_name:
84
- obj_name, method_name = function_name.split('.', 1)
85
-
86
- # First check if the method exists in the registry
87
- if registry_api.get_function(method_name):
88
- is_vex_function = True
89
- else:
90
- # Try to check if it's a method on any known object type
91
- from ..types.objects import MOTOR, TIMER, BRAIN, CONTROLLER
92
- for obj_type in [MOTOR, TIMER, BRAIN, CONTROLLER]:
93
- if registry_api.get_method(obj_type, method_name):
94
- is_vex_function = True
95
- break
96
- # Or check if it's a direct function
97
- elif registry_api.get_function(function_name):
98
- is_vex_function = True
99
-
100
- if is_vex_function:
101
- # Convert to VexAPICall and validate
102
- vex_call = VexAPICall(
103
- node.function,
104
- node.args,
105
- node.keywords,
106
- node.location
107
- )
108
- valid, error = vex_call.validate()
109
- if not valid and error:
110
- self.errors.append((vex_call, error))
111
-
112
- # Still visit children
113
- for child in node.get_children():
114
- self.visit(child)
115
-
116
- return self.errors
117
-
118
- def validate_vex_functions(ast: Program) -> List[Tuple[VexAPICall, str]]:
119
- """Validate all VEX function calls in the AST"""
120
- validator = VexFunctionValidator()
121
- return validator.visit(ast)
1
+ """AST validators that use the function registry."""
2
+
3
+ from typing import List, Dict, Set, Optional, Tuple
4
+ from .core import Program
5
+ from .expressions import FunctionCall, AttributeAccess, Identifier
6
+ from .vex_nodes import VexAPICall
7
+ from ..visitors.base import AstVisitor
8
+ from ..registry.api import registry_api
9
+
10
+ class VexFunctionValidator(AstVisitor[List[Tuple[VexAPICall, str]]]):
11
+ """Validates VEX function calls in the AST"""
12
+
13
+ def __init__(self):
14
+ self.errors: List[Tuple[VexAPICall, str]] = []
15
+
16
+ def generic_visit(self, node):
17
+ """Visit children of non-VEX-specific nodes"""
18
+ for child in node.get_children():
19
+ self.visit(child)
20
+ return self.errors
21
+
22
+ def visit_vexapicall(self, node: VexAPICall):
23
+ """Validate a VEX API call"""
24
+ valid, error = node.validate()
25
+ if not valid and error:
26
+ self.errors.append((node, error))
27
+
28
+ # Still visit children for nested calls
29
+ for child in node.get_children():
30
+ self.visit(child)
31
+
32
+ return self.errors
33
+
34
+ visit_program = generic_visit
35
+ visit_expression = generic_visit
36
+ visit_statement = generic_visit
37
+ visit_identifier = generic_visit
38
+ visit_variablereference = generic_visit
39
+ visit_attributeaccess = generic_visit
40
+ visit_binaryoperation = generic_visit
41
+ visit_unaryoperation = generic_visit
42
+ visit_keywordargument = generic_visit
43
+ visit_numberliteral = generic_visit
44
+ visit_stringliteral = generic_visit
45
+ visit_booleanliteral = generic_visit
46
+ visit_noneliteral = generic_visit
47
+ visit_expressionstatement = generic_visit
48
+ visit_assignment = generic_visit
49
+ visit_ifstatement = generic_visit
50
+ visit_whileloop = generic_visit
51
+ visit_forloop = generic_visit
52
+ visit_functiondefinition = generic_visit
53
+ visit_argument = generic_visit
54
+ visit_returnstatement = generic_visit
55
+ visit_breakstatement = generic_visit
56
+ visit_continuestatement = generic_visit
57
+ visit_motorcontrol = visit_vexapicall
58
+ visit_sensorreading = visit_vexapicall
59
+ visit_timingcontrol = visit_vexapicall
60
+ visit_displayoutput = visit_vexapicall
61
+
62
+ def visit_functioncall(self, node: FunctionCall):
63
+ """Check if a regular function call is actually a VEX API call"""
64
+ # Try to determine if this is a VEX function call
65
+ function_name = None
66
+
67
+ # Direct function name
68
+ if isinstance(node.function, Identifier):
69
+ function_name = node.function.name
70
+
71
+ # Method call like motor.spin()
72
+ elif isinstance(node.function, AttributeAccess):
73
+ obj = node.function.object
74
+ if isinstance(obj, Identifier):
75
+ function_name = f"{obj.name}.{node.function.attribute}"
76
+
77
+ # Initialize is_vex_function to False by default
78
+ is_vex_function = False
79
+
80
+ # Check if this is a known VEX function
81
+ if function_name:
82
+ # Check if this is a method call on a known object type
83
+ if '.' in function_name:
84
+ obj_name, method_name = function_name.split('.', 1)
85
+
86
+ # First check if the method exists in the registry
87
+ if registry_api.get_function(method_name):
88
+ is_vex_function = True
89
+ else:
90
+ # Try to check if it's a method on any known object type
91
+ from ..types.objects import MOTOR, TIMER, BRAIN, CONTROLLER
92
+ for obj_type in [MOTOR, TIMER, BRAIN, CONTROLLER]:
93
+ if registry_api.get_method(obj_type, method_name):
94
+ is_vex_function = True
95
+ break
96
+ # Or check if it's a direct function
97
+ elif registry_api.get_function(function_name):
98
+ is_vex_function = True
99
+
100
+ if is_vex_function:
101
+ # Convert to VexAPICall and validate
102
+ vex_call = VexAPICall(
103
+ node.function,
104
+ node.args,
105
+ node.keywords,
106
+ node.location
107
+ )
108
+ valid, error = vex_call.validate()
109
+ if not valid and error:
110
+ self.errors.append((vex_call, error))
111
+
112
+ # Still visit children
113
+ for child in node.get_children():
114
+ self.visit(child)
115
+
116
+ return self.errors
117
+
118
+ def validate_vex_functions(ast: Program) -> List[Tuple[VexAPICall, str]]:
119
+ """Validate all VEX function calls in the AST"""
120
+ validator = VexFunctionValidator()
121
+ return validator.visit(ast)