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
@@ -1,136 +1,179 @@
1
- from enum import Enum, auto
2
- from typing import Set, Dict, List, Optional, Tuple
3
-
4
- class FunctionCategory(Enum):
5
- """Categories for VEX functions"""
6
- MOTOR = auto() # Motor control functions
7
- DRIVETRAIN = auto() # Drivetrain control functions
8
- SENSOR = auto() # Sensor reading functions
9
- DISPLAY = auto() # Display output functions
10
- TIMING = auto() # Timing control functions
11
- COMPETITION = auto() # Competition control functions
12
- CONTROLLER = auto() # Controller input functions
13
- BRAIN = auto() # Brain functions
14
- UTILITY = auto() # Utility functions
15
- EVENT = auto() # Event handling
16
- OTHER = auto() # Other functions
17
-
18
- class SubCategory(Enum):
19
- """Subcategories for more fine-grained classification"""
20
- # Motor subcategories
21
- MOTOR_SPIN = auto()
22
- MOTOR_STOP = auto()
23
- MOTOR_CONFIGURATION = auto()
24
- MOTOR_MEASUREMENT = auto()
25
-
26
- # Drivetrain subcategories
27
- DRIVE_MOVEMENT = auto()
28
- DRIVE_TURN = auto()
29
- DRIVE_CONFIGURATION = auto()
30
-
31
- # Sensor subcategories
32
- DISTANCE_SENSOR = auto()
33
- INERTIAL_SENSOR = auto()
34
- ROTATION_SENSOR = auto()
35
- OPTICAL_SENSOR = auto()
36
- VISION_SENSOR = auto()
37
- LIMIT_SWITCH = auto()
38
- BUMPER = auto()
39
- GPS_SENSOR = auto()
40
-
41
- # Display subcategories
42
- SCREEN_DRAWING = auto()
43
- SCREEN_TEXT = auto()
44
- SCREEN_CLEARING = auto()
45
-
46
- # Timing subcategories
47
- WAIT = auto()
48
- TIMER = auto()
49
-
50
- # Competition subcategories
51
- COMPETITION_STATUS = auto()
52
- COMPETITION_CONTROL = auto()
53
-
54
- # Controller subcategories
55
- BUTTON_INPUT = auto()
56
- JOYSTICK_INPUT = auto()
57
- CONTROLLER_SCREEN = auto()
58
- CONTROLLER_RUMBLE = auto()
59
-
60
- # Brain subcategories
61
- BRAIN_BATTERY = auto()
62
- BRAIN_SCREEN = auto()
63
- BRAIN_BUTTONS = auto()
64
- BRAIN_SD_CARD = auto()
65
-
66
- # Utility subcategories
67
- MATH = auto()
68
- RANDOM = auto()
69
- COLOR = auto()
70
-
71
- # Event subcategories
72
- CALLBACK = auto()
73
- EVENT_REGISTRATION = auto()
74
-
75
- # Other subcategories
76
- SYSTEM = auto()
77
- DEBUGGING = auto()
78
-
79
- class FunctionCategorizer:
80
- """Utility for categorizing VEX functions"""
81
-
82
- def __init__(self):
83
- self.category_patterns: Dict[FunctionCategory, List[str]] = {
84
- FunctionCategory.MOTOR: ["motor", "spin", "velocity", "torque", "efficiency"],
85
- FunctionCategory.DRIVETRAIN: ["drive", "turn", "drivetrain"],
86
- FunctionCategory.SENSOR: ["sensor", "distance", "inertial", "rotation", "optical", "vision", "limit", "bumper", "gps"],
87
- FunctionCategory.DISPLAY: ["display", "print", "draw", "screen", "clear"],
88
- FunctionCategory.TIMING: ["wait", "sleep", "delay", "timer"],
89
- FunctionCategory.COMPETITION: ["competition", "autonomous", "driver"],
90
- FunctionCategory.CONTROLLER: ["controller", "button", "joystick", "rumble"],
91
- FunctionCategory.BRAIN: ["brain", "battery"],
92
- FunctionCategory.UTILITY: ["random", "math", "color"],
93
- FunctionCategory.EVENT: ["event", "callback", "when", "register"],
94
- }
95
-
96
- self.subcategory_patterns: Dict[SubCategory, List[str]] = {
97
- # Motor subcategories
98
- SubCategory.MOTOR_SPIN: ["spin", "rotate"],
99
- SubCategory.MOTOR_STOP: ["stop", "brake"],
100
- SubCategory.MOTOR_CONFIGURATION: ["set_", "configure"],
101
- SubCategory.MOTOR_MEASUREMENT: ["current", "temperature", "velocity", "position"],
102
-
103
- # Additional subcategory patterns can be added as needed
104
- }
105
-
106
- def categorize_function(self,
107
- function_name: str,
108
- description: str = "") -> Tuple[FunctionCategory, Optional[SubCategory]]:
109
- """Categorize a function based on its name and description"""
110
- function_name = function_name.lower()
111
- description = description.lower()
112
-
113
- # Try to find the main category
114
- category = FunctionCategory.OTHER
115
- for cat, patterns in self.category_patterns.items():
116
- for pattern in patterns:
117
- if pattern in function_name or pattern in description:
118
- category = cat
119
- break
120
- if category != FunctionCategory.OTHER:
121
- break
122
-
123
- # Try to find the subcategory
124
- subcategory = None
125
- for subcat, patterns in self.subcategory_patterns.items():
126
- for pattern in patterns:
127
- if pattern in function_name or pattern in description:
128
- subcategory = subcat
129
- break
130
- if subcategory:
131
- break
132
-
133
- return category, subcategory
134
-
135
- # Singleton instance
136
- categorizer = FunctionCategorizer()
1
+ from enum import Enum, auto, StrEnum
2
+ from typing import Set, Dict, List, Optional, Tuple
3
+
4
+ class VexCategory(StrEnum):
5
+ """Categories for VEX functions"""
6
+ MOTOR = "MOTOR" # Motor control functions
7
+ DRIVETRAIN = "DRIVETRAIN" # Drivetrain control functions
8
+ SENSOR = "SENSOR" # Sensor reading functions
9
+ DISPLAY = "DISPLAY" # Display output functions
10
+ TIMING = "TIMING" # Timing control functions
11
+ COMPETITION = "COMPETITION" # Competition control functions
12
+ CONTROLLER = "CONTROLLER" # Controller input functions
13
+ BRAIN = "BRAIN" # Brain functions
14
+ UTILITY = "UTILITY" # Utility functions
15
+ EVENT = "EVENT" # Event handling
16
+ OTHER = "OTHER" # Other functions
17
+
18
+ class BehaviorType(StrEnum):
19
+ """Behavior types for VEX functions"""
20
+ CONTROL = "CONTROL" # Actively controls/changes state
21
+ READ = "READ" # Reads/retrieves information
22
+ CONFIG = "CONFIG" # Configuration/setup
23
+ OUTPUT = "OUTPUT" # Produces output (display, signals)
24
+ EVENT = "EVENT" # Event handling/callbacks
25
+ OTHER = "OTHER" # Other behaviors
26
+
27
+ # For backward compatibility
28
+ FunctionCategory = VexCategory
29
+
30
+ class SubCategory(Enum):
31
+ """Subcategories for more fine-grained classification"""
32
+ # Motor subcategories
33
+ MOTOR_SPIN = auto()
34
+ MOTOR_STOP = auto()
35
+ MOTOR_CONFIGURATION = auto()
36
+ MOTOR_MEASUREMENT = auto()
37
+
38
+ # Drivetrain subcategories
39
+ DRIVE_MOVEMENT = auto()
40
+ DRIVE_TURN = auto()
41
+ DRIVE_CONFIGURATION = auto()
42
+
43
+ # Sensor subcategories
44
+ DISTANCE_SENSOR = auto()
45
+ INERTIAL_SENSOR = auto()
46
+ ROTATION_SENSOR = auto()
47
+ OPTICAL_SENSOR = auto()
48
+ VISION_SENSOR = auto()
49
+ LIMIT_SWITCH = auto()
50
+ BUMPER = auto()
51
+ GPS_SENSOR = auto()
52
+
53
+ # Display subcategories
54
+ SCREEN_DRAWING = auto()
55
+ SCREEN_TEXT = auto()
56
+ SCREEN_CLEARING = auto()
57
+
58
+ # Timing subcategories
59
+ WAIT = auto()
60
+ TIMER = auto()
61
+
62
+ # Competition subcategories
63
+ COMPETITION_STATUS = auto()
64
+ COMPETITION_CONTROL = auto()
65
+
66
+ # Controller subcategories
67
+ BUTTON_INPUT = auto()
68
+ JOYSTICK_INPUT = auto()
69
+ CONTROLLER_SCREEN = auto()
70
+ CONTROLLER_RUMBLE = auto()
71
+
72
+ # Brain subcategories
73
+ BRAIN_BATTERY = auto()
74
+ BRAIN_SCREEN = auto()
75
+ BRAIN_BUTTONS = auto()
76
+ BRAIN_SD_CARD = auto()
77
+
78
+ # Utility subcategories
79
+ MATH = auto()
80
+ RANDOM = auto()
81
+ COLOR = auto()
82
+
83
+ # Event subcategories
84
+ CALLBACK = auto()
85
+ EVENT_REGISTRATION = auto()
86
+
87
+ # Other subcategories
88
+ SYSTEM = auto()
89
+ DEBUGGING = auto()
90
+
91
+ class FunctionCategorizer:
92
+ """Utility for categorizing VEX functions"""
93
+
94
+ def __init__(self):
95
+ self.category_patterns: Dict[VexCategory, List[str]] = {
96
+ VexCategory.MOTOR: ["motor", "spin", "velocity", "torque", "efficiency"],
97
+ VexCategory.DRIVETRAIN: ["drive", "turn", "drivetrain"],
98
+ VexCategory.SENSOR: ["sensor", "distance", "inertial", "rotation", "optical", "vision", "limit", "bumper", "gps"],
99
+ VexCategory.DISPLAY: ["display", "print", "draw", "screen", "clear"],
100
+ VexCategory.TIMING: ["wait", "sleep", "delay", "timer"],
101
+ VexCategory.COMPETITION: ["competition", "autonomous", "driver"],
102
+ VexCategory.CONTROLLER: ["controller", "button", "joystick", "rumble"],
103
+ VexCategory.BRAIN: ["brain", "battery"],
104
+ VexCategory.UTILITY: ["random", "math", "color"],
105
+ VexCategory.EVENT: ["event", "callback", "when", "register"],
106
+ }
107
+
108
+ self.behavior_patterns: Dict[BehaviorType, List[str]] = {
109
+ BehaviorType.CONTROL: ["spin", "drive", "turn", "stop", "brake", "set", "clear"],
110
+ BehaviorType.READ: ["get", "read", "measure", "is_", "has_", "current", "temperature", "position"],
111
+ BehaviorType.CONFIG: ["configure", "calibrate", "initialize", "setup"],
112
+ BehaviorType.OUTPUT: ["print", "draw", "display", "rumble"],
113
+ BehaviorType.EVENT: ["event", "callback", "when", "register", "handler"],
114
+ }
115
+
116
+ self.subcategory_patterns: Dict[SubCategory, List[str]] = {
117
+ # Motor subcategories
118
+ SubCategory.MOTOR_SPIN: ["spin", "rotate"],
119
+ SubCategory.MOTOR_STOP: ["stop", "brake"],
120
+ SubCategory.MOTOR_CONFIGURATION: ["set_", "configure"],
121
+ SubCategory.MOTOR_MEASUREMENT: ["current", "temperature", "velocity", "position"],
122
+
123
+ # Additional subcategory patterns can be added as needed
124
+ }
125
+
126
+ # Mapping from old SimulationCategory to new BehaviorType
127
+ self.simulation_to_behavior = {
128
+ "MOTOR_CONTROL": BehaviorType.CONTROL,
129
+ "SENSOR_READING": BehaviorType.READ,
130
+ "DISPLAY_OUTPUT": BehaviorType.OUTPUT,
131
+ "TIMING_CONTROL": BehaviorType.CONTROL,
132
+ "COMPETITION": BehaviorType.OTHER,
133
+ "CONFIGURATION": BehaviorType.CONFIG,
134
+ "CALCULATION": BehaviorType.OTHER,
135
+ "EVENT_HANDLING": BehaviorType.EVENT,
136
+ "OTHER": BehaviorType.OTHER
137
+ }
138
+
139
+ def categorize_function(self,
140
+ function_name: str,
141
+ description: str = "") -> Tuple[VexCategory, BehaviorType, Optional[SubCategory]]:
142
+ """Categorize a function based on its name and description"""
143
+ function_name = function_name.lower()
144
+ description = description.lower()
145
+
146
+ # Try to find the main category
147
+ category = VexCategory.OTHER
148
+ for cat, patterns in self.category_patterns.items():
149
+ for pattern in patterns:
150
+ if pattern in function_name or pattern in description:
151
+ category = cat
152
+ break
153
+ if category != VexCategory.OTHER:
154
+ break
155
+
156
+ # Try to find the behavior type
157
+ behavior = BehaviorType.OTHER
158
+ for behav, patterns in self.behavior_patterns.items():
159
+ for pattern in patterns:
160
+ if pattern in function_name or pattern in description:
161
+ behavior = behav
162
+ break
163
+ if behavior != BehaviorType.OTHER:
164
+ break
165
+
166
+ # Try to find the subcategory
167
+ subcategory = None
168
+ for subcat, patterns in self.subcategory_patterns.items():
169
+ for pattern in patterns:
170
+ if pattern in function_name or pattern in description:
171
+ subcategory = subcat
172
+ break
173
+ if subcategory:
174
+ break
175
+
176
+ return category, behavior, subcategory
177
+
178
+ # Singleton instance
179
+ categorizer = FunctionCategorizer()
@@ -1,11 +1,11 @@
1
- """
2
- Registry functions package for VEX AST.
3
-
4
- This package contains the function definitions for the VEX API registry.
5
- """
6
-
7
- from .initialize import initialize_registry
8
-
9
- __all__ = [
10
- "initialize_registry"
1
+ """
2
+ Registry functions package for VEX AST.
3
+
4
+ This package contains the function definitions for the VEX API registry.
5
+ """
6
+
7
+ from .initialize import initialize_registry
8
+
9
+ __all__ = [
10
+ "initialize_registry"
11
11
  ]
@@ -1,35 +1,71 @@
1
- """Register constructors for VEX objects in the registry."""
2
-
3
- from ..registry import registry
4
- from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode, SimulationCategory
5
- from ...types.base import VOID
6
- from ...types.primitives import INT, FLOAT, BOOL, STRING
7
- from ...types.enums import PORT_TYPE
8
- from ...types.objects import MOTOR
9
-
10
- def register_constructor_functions():
11
- """Register constructor functions in the registry"""
12
-
13
- # Motor constructor
14
- motor_params = [
15
- VexFunctionParameter("port", PORT_TYPE, description="The port the motor is connected to"),
16
- VexFunctionParameter("gear_ratio", FLOAT, None, ParameterMode.VALUE, description="The gear ratio of the motor"),
17
- VexFunctionParameter("reverse", BOOL, False, ParameterMode.VALUE, description="Whether to reverse the motor direction")
18
- ]
19
-
20
- motor_signature = VexFunctionSignature(
21
- name="Motor",
22
- return_type=MOTOR,
23
- parameters=motor_params,
24
- description="Create a new Motor object",
25
- category=SimulationCategory.CONFIGURATION,
26
- python_name="Motor",
27
- cpp_name="motor"
28
- )
29
-
30
- registry.register_function(motor_signature)
31
-
32
- # Add other constructors as needed (MotorGroup, Drivetrain, etc.)
33
-
34
- if __name__ == "__main__":
35
- register_constructor_functions()
1
+ """Register constructors for VEX objects in the registry."""
2
+
3
+ from ..registry import registry
4
+ from ..signature import VexFunctionSignature, VexFunctionParameter, ParameterMode
5
+ from ...types.base import VOID
6
+ from ...types.primitives import INT, FLOAT, BOOL, STRING
7
+ from ...types.enums import PORT_TYPE
8
+ from ...types.objects import MOTOR, BRAIN, CONTROLLER
9
+ from ..categories import VexCategory, BehaviorType
10
+
11
+ def register_constructor_functions():
12
+ """Register constructor functions in the registry"""
13
+
14
+ # Motor constructor
15
+ motor_params = [
16
+ VexFunctionParameter("port", PORT_TYPE, description="The port the motor is connected to"),
17
+ VexFunctionParameter("gear_ratio", FLOAT, None, ParameterMode.VALUE, description="The gear ratio of the motor"),
18
+ VexFunctionParameter("reverse", BOOL, False, ParameterMode.VALUE, description="Whether to reverse the motor direction")
19
+ ]
20
+
21
+ motor_signature = VexFunctionSignature(
22
+ name="Motor",
23
+ return_type=MOTOR,
24
+ parameters=motor_params,
25
+ description="Create a new Motor object",
26
+ category=VexCategory.MOTOR,
27
+ behavior=BehaviorType.CONFIG,
28
+ python_name="Motor",
29
+ cpp_name="motor"
30
+ )
31
+
32
+ registry.register_function(motor_signature)
33
+
34
+ # Brain constructor
35
+ brain_params = [] # Brain doesn't take any parameters
36
+
37
+ brain_signature = VexFunctionSignature(
38
+ name="Brain",
39
+ return_type=BRAIN,
40
+ parameters=brain_params,
41
+ description="Create a new Brain object",
42
+ category=VexCategory.BRAIN,
43
+ behavior=BehaviorType.CONFIG,
44
+ python_name="Brain",
45
+ cpp_name="brain"
46
+ )
47
+
48
+ registry.register_function(brain_signature)
49
+
50
+ # Controller constructor
51
+ controller_params = [
52
+ VexFunctionParameter("id", INT, 1, ParameterMode.VALUE, description="The controller ID (primary = 1, partner = 2)")
53
+ ]
54
+
55
+ controller_signature = VexFunctionSignature(
56
+ name="Controller",
57
+ return_type=CONTROLLER,
58
+ parameters=controller_params,
59
+ description="Create a new Controller object",
60
+ category=VexCategory.CONTROLLER,
61
+ behavior=BehaviorType.CONFIG,
62
+ python_name="Controller",
63
+ cpp_name="controller"
64
+ )
65
+
66
+ registry.register_function(controller_signature)
67
+
68
+ # Add other constructors as needed (MotorGroup, Drivetrain, etc.)
69
+
70
+ if __name__ == "__main__":
71
+ register_constructor_functions()