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.
- 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 +225 -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.6.dist-info}/METADATA +206 -174
- vex_ast-0.2.6.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.6.dist-info}/WHEEL +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/licenses/LICENSE +0 -0
- {vex_ast-0.2.5.dist-info → vex_ast-0.2.6.dist-info}/top_level.txt +0 -0
vex_ast/registry/categories.py
CHANGED
@@ -1,136 +1,179 @@
|
|
1
|
-
from enum import Enum, auto
|
2
|
-
from typing import Set, Dict, List, Optional, Tuple
|
3
|
-
|
4
|
-
class
|
5
|
-
"""Categories for VEX functions"""
|
6
|
-
MOTOR =
|
7
|
-
DRIVETRAIN =
|
8
|
-
SENSOR =
|
9
|
-
DISPLAY =
|
10
|
-
TIMING =
|
11
|
-
COMPETITION =
|
12
|
-
CONTROLLER =
|
13
|
-
BRAIN =
|
14
|
-
UTILITY =
|
15
|
-
EVENT =
|
16
|
-
OTHER =
|
17
|
-
|
18
|
-
class
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
VexFunctionParameter("
|
17
|
-
VexFunctionParameter("
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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()
|