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.
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 -72
  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 -120
  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 -786
  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 -0
  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 -28
  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 -275
  39. vex_ast/serialization/json_serializer.py +148 -148
  40. vex_ast/serialization/schema.py +492 -470
  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 -97
  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 -146
  58. {vex_ast-0.2.4.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.4.dist-info/RECORD +0 -63
  61. {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/WHEEL +0 -0
  62. {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/licenses/LICENSE +0 -0
  63. {vex_ast-0.2.4.dist-info → vex_ast-0.2.6.dist-info}/top_level.txt +0 -0
@@ -1,29 +1,107 @@
1
- # VEX AST Registry Package (vex_ast.registry)
2
-
3
- This package manages the registration and organization of VEX V5 Robot Python language features, including functions, objects, and other elements.
4
-
5
- Purpose
6
-
7
- The registry provides a centralized system for defining and accessing information about VEX-specific language constructs. This information is used by the parser, type checker, and other tools to understand and process VEX code.
8
-
9
- Structure
10
-
11
- The package is organized into several modules:
12
-
13
- * `categories.py`: Defines categories for organizing registry entries.
14
- * `language_map.py`: Maps VEX language features to their Python equivalents.
15
- * `registry.py`: Implements the core registry logic.
16
- * `signature.py`: Defines the structure for function signatures.
17
- * `simulation_behavior.py`: Specifies how VEX features should behave in a simulation environment.
18
- * `validation.py`: Provides validation rules for registry entries.
19
- * `functions/`: Contains submodules for specific function categories (e.g., drivetrain, motor, sensors).
20
-
21
- Key Concepts
22
-
23
- * Registration: VEX language features are registered with the registry, providing metadata about their syntax, semantics, and simulation behavior.
24
- * Organization: The registry organizes features into categories and subcategories for easy access and management.
25
- * Validation: Registry entries are validated to ensure consistency and correctness.
26
-
27
- Usage
28
-
29
- The registry is used internally by the VEX AST parser and other tools. It is not typically accessed directly by users.
1
+ # VEX AST Registry Package (vex_ast.registry)
2
+
3
+ This package manages the registration and organization of VEX V5 Robot Python language features, including functions, objects, and their semantic behaviors.
4
+
5
+ ## Purpose
6
+
7
+ The registry provides a centralized system for defining and accessing information about VEX-specific language constructs. It powers intelligent parsing, type checking, and simulation capabilities by maintaining a comprehensive database of VEX functions and their properties.
8
+
9
+ ## Architecture
10
+
11
+ ### Core Components
12
+
13
+ * `categories.py`: Implements the dual-axis categorization system
14
+ - `VexCategory`: Defines what a component is (MOTOR, SENSOR, DISPLAY, etc.)
15
+ - `BehaviorType`: Defines what a component does (CONTROL, READ, CONFIG, etc.)
16
+ - `SubCategory`: Provides granular classification within categories
17
+ - `FunctionCategorizer`: Intelligent categorization based on name and description
18
+
19
+ * `api.py`: Clean API layer for registry access
20
+ - Abstracts internal implementation details
21
+ - Provides intuitive query methods
22
+ - Maintains backward compatibility
23
+
24
+ * `registry.py`: Core registry implementation
25
+ - Thread-safe singleton pattern
26
+ - Efficient lookup structures
27
+ - Category/behavior indexing
28
+
29
+ * `signature.py`: Function signature system
30
+ - Parameter definitions and validation
31
+ - Return type tracking
32
+ - Language mapping (Python/C++)
33
+
34
+ ### Function Organization
35
+
36
+ Functions are registered using a multi-dimensional classification:
37
+
38
+ ```
39
+ Component → Category (what it is) → Behavior (what it does) → Subcategory (specific role)
40
+ Example: motor.spin → MOTOR → CONTROL → MOTOR_SPIN
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### Basic Registry Access
46
+
47
+ ```python
48
+ from vex_ast.registry.api import registry_api
49
+
50
+ # Get functions by category
51
+ motor_functions = registry_api.get_functions_by_category(VexCategory.MOTOR)
52
+
53
+ # Get functions by behavior
54
+ control_functions = registry_api.get_functions_by_behavior(BehaviorType.CONTROL)
55
+
56
+ # Combined queries
57
+ motor_control = registry_api.get_functions_by_category_and_behavior(
58
+ VexCategory.MOTOR,
59
+ BehaviorType.CONTROL
60
+ )
61
+
62
+ # Validate function calls
63
+ valid, error = registry_api.validate_call("motor.spin", args, kwargs)
64
+ ```
65
+
66
+ ### Function Registration
67
+
68
+ ```python
69
+ from vex_ast.registry.signature import VexFunctionSignature, VexFunctionParameter
70
+ from vex_ast.registry.categories import VexCategory, BehaviorType
71
+
72
+ # Define function signature
73
+ signature = VexFunctionSignature(
74
+ name="spin",
75
+ return_type=VOID,
76
+ parameters=[
77
+ VexFunctionParameter("direction", DIRECTION_TYPE),
78
+ VexFunctionParameter("velocity", FLOAT, 50.0),
79
+ VexFunctionParameter("units", VELOCITY_UNITS, "RPM")
80
+ ],
81
+ description="Spin the motor in the specified direction",
82
+ category=VexCategory.MOTOR,
83
+ behavior=BehaviorType.CONTROL,
84
+ python_name="spin",
85
+ cpp_name="spin",
86
+ object_type=MOTOR,
87
+ method_name="spin"
88
+ )
89
+
90
+ # Register the function
91
+ registry.register_function(signature)
92
+ ```
93
+
94
+ ## Backward Compatibility
95
+
96
+ The registry maintains full backward compatibility with legacy systems:
97
+ - `SimulationCategory` enum is preserved and mapped to new categories
98
+ - Old API methods continue to work
99
+ - Automatic conversion between old and new category systems
100
+
101
+ ## Extension Points
102
+
103
+ Extend the registry by:
104
+ 1. Adding new `VexCategory` values
105
+ 2. Defining new `BehaviorType` entries
106
+ 3. Creating custom `SubCategory` classifications
107
+ 4. Implementing specialized validation logic
@@ -1,51 +1,51 @@
1
- """Registry package for VEX AST functions and types."""
2
-
3
- from .registry import registry, VexFunctionRegistry
4
- from .signature import (
5
- VexFunctionSignature,
6
- VexFunctionParameter,
7
- ParameterMode,
8
- SimulationCategory
9
- )
10
- from .categories import (
11
- FunctionCategory,
12
- SubCategory,
13
- categorizer
14
- )
15
- from .language_map import language_mapper
16
- from .validation import validator
17
- from .simulation_behavior import SimulationBehavior
18
- from .api import registry_api, RegistryAPI
19
-
20
- # Initialize registry with default values
21
- def initialize():
22
- """Initialize the registry with all VEX functions"""
23
- from .functions.initialize import initialize_registry
24
- initialize_registry()
25
-
26
- __all__ = [
27
- # Legacy direct access (deprecated)
28
- 'registry',
29
- 'VexFunctionRegistry',
30
-
31
- # Preferred API access
32
- 'registry_api',
33
- 'RegistryAPI',
34
-
35
- # Common types and enums
36
- 'VexFunctionSignature',
37
- 'VexFunctionParameter',
38
- 'ParameterMode',
39
- 'SimulationCategory',
40
- 'SimulationBehavior',
41
- 'FunctionCategory',
42
- 'SubCategory',
43
-
44
- # Utility objects
45
- 'categorizer',
46
- 'language_mapper',
47
- 'validator',
48
-
49
- # Functions
50
- 'initialize'
51
- ]
1
+ """Registry package for VEX AST functions and types."""
2
+
3
+ from .registry import registry, VexFunctionRegistry
4
+ from .signature import (
5
+ VexFunctionSignature,
6
+ VexFunctionParameter,
7
+ ParameterMode,
8
+ SimulationCategory
9
+ )
10
+ from .categories import (
11
+ FunctionCategory,
12
+ SubCategory,
13
+ categorizer
14
+ )
15
+ from .language_map import language_mapper
16
+ from .validation import validator
17
+ from .simulation_behavior import SimulationBehavior
18
+ from .api import registry_api, RegistryAPI
19
+
20
+ # Initialize registry with default values
21
+ def initialize():
22
+ """Initialize the registry with all VEX functions"""
23
+ from .functions.initialize import initialize_registry
24
+ initialize_registry()
25
+
26
+ __all__ = [
27
+ # Legacy direct access (deprecated)
28
+ 'registry',
29
+ 'VexFunctionRegistry',
30
+
31
+ # Preferred API access
32
+ 'registry_api',
33
+ 'RegistryAPI',
34
+
35
+ # Common types and enums
36
+ 'VexFunctionSignature',
37
+ 'VexFunctionParameter',
38
+ 'ParameterMode',
39
+ 'SimulationCategory',
40
+ 'SimulationBehavior',
41
+ 'FunctionCategory',
42
+ 'SubCategory',
43
+
44
+ # Utility objects
45
+ 'categorizer',
46
+ 'language_mapper',
47
+ 'validator',
48
+
49
+ # Functions
50
+ 'initialize'
51
+ ]
vex_ast/registry/api.py CHANGED
@@ -1,155 +1,190 @@
1
- """API layer for the VEX function registry.
2
-
3
- This module provides a clean API for accessing the VEX function registry,
4
- hiding implementation details and providing a more stable interface.
5
- """
6
-
7
- from typing import Dict, List, Optional, Union, Tuple, Any, Set
8
-
9
- from .registry import registry, VexFunctionRegistry
10
- from .signature import VexFunctionSignature, SimulationCategory
11
- from .categories import FunctionCategory, SubCategory
12
- from ..types.base import VexType
13
-
14
- class RegistryAPI:
15
- """API layer for the VEX function registry."""
16
-
17
- def __init__(self, registry_instance: VexFunctionRegistry = None):
18
- """Initialize with a registry instance or use the singleton."""
19
- self._registry = registry_instance or registry
20
-
21
- def get_function(self, name: str, language: str = "python") -> Optional[VexFunctionSignature]:
22
- """Get a function signature by name.
23
-
24
- Args:
25
- name: The function name
26
- language: The language to use for name resolution ("python" or "cpp")
27
-
28
- Returns:
29
- The function signature if found, None otherwise
30
- """
31
- return self._registry.get_function(name, language)
32
-
33
- def get_method(self, object_type: Union[VexType, str],
34
- method_name: str) -> Optional[VexFunctionSignature]:
35
- """Get a method signature for an object type and method name.
36
-
37
- Args:
38
- object_type: The object type or type name
39
- method_name: The method name
40
-
41
- Returns:
42
- The method signature if found, None otherwise
43
- """
44
- return self._registry.get_method(object_type, method_name)
45
-
46
- def get_functions_by_category(self, category: FunctionCategory) -> List[VexFunctionSignature]:
47
- """Get all functions in a category.
48
-
49
- Args:
50
- category: The function category
51
-
52
- Returns:
53
- List of function signatures in the category
54
- """
55
- return self._registry.get_functions_by_category(category)
56
-
57
- def get_functions_by_subcategory(self, subcategory: SubCategory) -> List[VexFunctionSignature]:
58
- """Get all functions in a subcategory.
59
-
60
- Args:
61
- subcategory: The function subcategory
62
-
63
- Returns:
64
- List of function signatures in the subcategory
65
- """
66
- return self._registry.get_functions_by_subcategory(subcategory)
67
-
68
- def get_functions_by_simulation(self,
69
- sim_category: SimulationCategory) -> List[VexFunctionSignature]:
70
- """Get all functions with a specific simulation category.
71
-
72
- Args:
73
- sim_category: The simulation category
74
-
75
- Returns:
76
- List of function signatures with the simulation category
77
- """
78
- return self._registry.get_functions_by_simulation(sim_category)
79
-
80
- def validate_call(self, function_name: str,
81
- args: List[Any],
82
- kwargs: Dict[str, Any],
83
- language: str = "python") -> Tuple[bool, Optional[str]]:
84
- """Validate a function call.
85
-
86
- Args:
87
- function_name: The function name
88
- args: The positional arguments
89
- kwargs: The keyword arguments
90
- language: The language to use for name resolution
91
-
92
- Returns:
93
- A tuple of (valid, error_message)
94
- """
95
- return self._registry.validate_call(function_name, args, kwargs, language)
96
-
97
- def validate_method_call(self, object_type: Union[VexType, str],
98
- method_name: str,
99
- args: List[Any],
100
- kwargs: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
101
- """Validate a method call on an object.
102
-
103
- Args:
104
- object_type: The object type or type name
105
- method_name: The method name
106
- args: The positional arguments
107
- kwargs: The keyword arguments
108
-
109
- Returns:
110
- A tuple of (valid, error_message)
111
- """
112
- return self._registry.validate_method_call(object_type, method_name, args, kwargs)
113
-
114
- def get_all_functions(self) -> List[VexFunctionSignature]:
115
- """Get all registered functions.
116
-
117
- Returns:
118
- List of all function signatures
119
- """
120
- return self._registry.get_all_functions()
121
-
122
- def get_function_names(self) -> Set[str]:
123
- """Get all registered function names.
124
-
125
- Returns:
126
- Set of function names
127
- """
128
- return {func.name for func in self.get_all_functions()}
129
-
130
- def get_categories(self) -> List[FunctionCategory]:
131
- """Get all available function categories.
132
-
133
- Returns:
134
- List of function categories
135
- """
136
- return list(FunctionCategory)
137
-
138
- def get_subcategories(self) -> List[SubCategory]:
139
- """Get all available function subcategories.
140
-
141
- Returns:
142
- List of function subcategories
143
- """
144
- return list(SubCategory)
145
-
146
- def get_simulation_categories(self) -> List[SimulationCategory]:
147
- """Get all available simulation categories.
148
-
149
- Returns:
150
- List of simulation categories
151
- """
152
- return list(SimulationCategory)
153
-
154
- # Singleton instance
155
- registry_api = RegistryAPI()
1
+ """API layer for the VEX function registry.
2
+
3
+ This module provides a clean API for accessing the VEX function registry,
4
+ hiding implementation details and providing a more stable interface.
5
+ """
6
+
7
+ from typing import Dict, List, Optional, Union, Tuple, Any, Set
8
+
9
+ from .registry import registry, VexFunctionRegistry
10
+ from .signature import VexFunctionSignature, SimulationCategory
11
+ from .categories import VexCategory, BehaviorType, SubCategory
12
+ from ..types.base import VexType
13
+
14
+ class RegistryAPI:
15
+ """API layer for the VEX function registry."""
16
+
17
+ def __init__(self, registry_instance: VexFunctionRegistry = None):
18
+ """Initialize with a registry instance or use the singleton."""
19
+ self._registry = registry_instance or registry
20
+
21
+ def get_function(self, name: str, language: str = "python") -> Optional[VexFunctionSignature]:
22
+ """Get a function signature by name.
23
+
24
+ Args:
25
+ name: The function name
26
+ language: The language to use for name resolution ("python" or "cpp")
27
+
28
+ Returns:
29
+ The function signature if found, None otherwise
30
+ """
31
+ return self._registry.get_function(name, language)
32
+
33
+ def get_method(self, object_type: Union[VexType, str],
34
+ method_name: str) -> Optional[VexFunctionSignature]:
35
+ """Get a method signature for an object type and method name.
36
+
37
+ Args:
38
+ object_type: The object type or type name
39
+ method_name: The method name
40
+
41
+ Returns:
42
+ The method signature if found, None otherwise
43
+ """
44
+ return self._registry.get_method(object_type, method_name)
45
+
46
+ def get_functions_by_category(self, category: VexCategory) -> List[VexFunctionSignature]:
47
+ """Get all functions in a category.
48
+
49
+ Args:
50
+ category: The function category
51
+
52
+ Returns:
53
+ List of function signatures in the category
54
+ """
55
+ return self._registry.get_functions_by_category(category)
56
+
57
+ def get_functions_by_behavior(self, behavior: BehaviorType) -> List[VexFunctionSignature]:
58
+ """Get all functions with a specific behavior type.
59
+
60
+ Args:
61
+ behavior: The behavior type
62
+
63
+ Returns:
64
+ List of function signatures with the behavior type
65
+ """
66
+ return self._registry.get_functions_by_behavior(behavior)
67
+
68
+ def get_functions_by_subcategory(self, subcategory: SubCategory) -> List[VexFunctionSignature]:
69
+ """Get all functions in a subcategory.
70
+
71
+ Args:
72
+ subcategory: The function subcategory
73
+
74
+ Returns:
75
+ List of function signatures in the subcategory
76
+ """
77
+ return self._registry.get_functions_by_subcategory(subcategory)
78
+
79
+ def get_functions_by_simulation(self,
80
+ sim_category: SimulationCategory) -> List[VexFunctionSignature]:
81
+ """Get all functions with a specific simulation category.
82
+
83
+ Args:
84
+ sim_category: The simulation category
85
+
86
+ Returns:
87
+ List of function signatures with the simulation category
88
+ """
89
+ return self._registry.get_functions_by_simulation(sim_category)
90
+
91
+ def validate_call(self, function_name: str,
92
+ args: List[Any],
93
+ kwargs: Dict[str, Any],
94
+ language: str = "python") -> Tuple[bool, Optional[str]]:
95
+ """Validate a function call.
96
+
97
+ Args:
98
+ function_name: The function name
99
+ args: The positional arguments
100
+ kwargs: The keyword arguments
101
+ language: The language to use for name resolution
102
+
103
+ Returns:
104
+ A tuple of (valid, error_message)
105
+ """
106
+ return self._registry.validate_call(function_name, args, kwargs, language)
107
+
108
+ def validate_method_call(self, object_type: Union[VexType, str],
109
+ method_name: str,
110
+ args: List[Any],
111
+ kwargs: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
112
+ """Validate a method call on an object.
113
+
114
+ Args:
115
+ object_type: The object type or type name
116
+ method_name: The method name
117
+ args: The positional arguments
118
+ kwargs: The keyword arguments
119
+
120
+ Returns:
121
+ A tuple of (valid, error_message)
122
+ """
123
+ return self._registry.validate_method_call(object_type, method_name, args, kwargs)
124
+
125
+ def get_all_functions(self) -> List[VexFunctionSignature]:
126
+ """Get all registered functions.
127
+
128
+ Returns:
129
+ List of all function signatures
130
+ """
131
+ return self._registry.get_all_functions()
132
+
133
+ def get_function_names(self) -> Set[str]:
134
+ """Get all registered function names.
135
+
136
+ Returns:
137
+ Set of function names
138
+ """
139
+ return {func.name for func in self.get_all_functions()}
140
+
141
+ def get_categories(self) -> List[VexCategory]:
142
+ """Get all available function categories.
143
+
144
+ Returns:
145
+ List of function categories
146
+ """
147
+ return list(VexCategory)
148
+
149
+ def get_behaviors(self) -> List[BehaviorType]:
150
+ """Get all available behavior types.
151
+
152
+ Returns:
153
+ List of behavior types
154
+ """
155
+ return list(BehaviorType)
156
+
157
+ def get_subcategories(self) -> List[SubCategory]:
158
+ """Get all available function subcategories.
159
+
160
+ Returns:
161
+ List of function subcategories
162
+ """
163
+ return list(SubCategory)
164
+
165
+ def get_simulation_categories(self) -> List[SimulationCategory]:
166
+ """Get all available simulation categories.
167
+
168
+ Returns:
169
+ List of simulation categories
170
+ """
171
+ return list(SimulationCategory)
172
+
173
+ def get_functions_by_category_and_behavior(self,
174
+ category: VexCategory,
175
+ behavior: BehaviorType) -> List[VexFunctionSignature]:
176
+ """Get all functions with a specific category and behavior.
177
+
178
+ Args:
179
+ category: The function category
180
+ behavior: The behavior type
181
+
182
+ Returns:
183
+ List of function signatures with the category and behavior
184
+ """
185
+ category_funcs = self.get_functions_by_category(category)
186
+ behavior_funcs = self.get_functions_by_behavior(behavior)
187
+ return list(set(category_funcs) & set(behavior_funcs))
188
+
189
+ # Singleton instance
190
+ registry_api = RegistryAPI()