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,103 +1,103 @@
1
- """Analysis visitors for AST."""
2
-
3
- from typing import Any, Dict, List, Optional, Set
4
-
5
- from .base import AstVisitor
6
- from ..ast.interfaces import IAstNode
7
-
8
- class NodeCounter(AstVisitor[int]):
9
- """Visitor that counts nodes in the AST."""
10
-
11
- def __init__(self):
12
- self.count = 0
13
- self.counts_by_type: Dict[str, int] = {}
14
-
15
- def generic_visit(self, node: IAstNode) -> int:
16
- """Count this node and visit its children."""
17
- self.count += 1
18
-
19
- # Count by node type
20
- node_type = node.__class__.__name__
21
- self.counts_by_type[node_type] = self.counts_by_type.get(node_type, 0) + 1
22
-
23
- # Visit all children
24
- for child in node.get_children():
25
- self.visit(child)
26
-
27
- return self.count
28
-
29
- # Implement all the required visit methods by delegating to generic_visit
30
- visit_program = generic_visit
31
- visit_expression = generic_visit
32
- visit_statement = generic_visit
33
- visit_identifier = generic_visit
34
- visit_variablereference = generic_visit
35
- visit_binaryoperation = generic_visit
36
- visit_unaryoperation = generic_visit
37
- visit_functioncall = generic_visit
38
- visit_keywordargument = generic_visit
39
- visit_numberliteral = generic_visit
40
- visit_stringliteral = generic_visit
41
- visit_booleanliteral = generic_visit
42
- visit_noneliteral = generic_visit
43
- visit_expressionstatement = generic_visit
44
- visit_assignment = generic_visit
45
- visit_ifstatement = generic_visit
46
- visit_whileloop = generic_visit
47
- visit_forloop = generic_visit
48
- visit_functiondefinition = generic_visit
49
- visit_argument = generic_visit
50
- visit_returnstatement = generic_visit
51
- visit_breakstatement = generic_visit
52
- visit_continuestatement = generic_visit
53
- visit_vexapicall = generic_visit
54
- visit_motorcontrol = generic_visit
55
- visit_sensorreading = generic_visit
56
- visit_timingcontrol = generic_visit
57
- visit_displayoutput = generic_visit
58
-
59
- class VariableCollector(AstVisitor[Set[str]]):
60
- """Visitor that collects variable names used in the AST."""
61
-
62
- def __init__(self):
63
- self.variables: Set[str] = set()
64
-
65
- def generic_visit(self, node: IAstNode) -> Set[str]:
66
- """Collect variables from children."""
67
- for child in node.get_children():
68
- self.visit(child)
69
- return self.variables
70
-
71
- def visit_variablereference(self, node: Any) -> Set[str]:
72
- """Collect a variable reference."""
73
- self.variables.add(node.name)
74
- return self.generic_visit(node)
75
-
76
- # Delegate all other methods to generic_visit
77
- visit_program = generic_visit
78
- visit_expression = generic_visit
79
- visit_statement = generic_visit
80
- visit_identifier = generic_visit
81
- visit_binaryoperation = generic_visit
82
- visit_unaryoperation = generic_visit
83
- visit_functioncall = generic_visit
84
- visit_keywordargument = generic_visit
85
- visit_numberliteral = generic_visit
86
- visit_stringliteral = generic_visit
87
- visit_booleanliteral = generic_visit
88
- visit_noneliteral = generic_visit
89
- visit_expressionstatement = generic_visit
90
- visit_assignment = generic_visit
91
- visit_ifstatement = generic_visit
92
- visit_whileloop = generic_visit
93
- visit_forloop = generic_visit
94
- visit_functiondefinition = generic_visit
95
- visit_argument = generic_visit
96
- visit_returnstatement = generic_visit
97
- visit_breakstatement = generic_visit
98
- visit_continuestatement = generic_visit
99
- visit_vexapicall = generic_visit
100
- visit_motorcontrol = generic_visit
101
- visit_sensorreading = generic_visit
102
- visit_timingcontrol = generic_visit
1
+ """Analysis visitors for AST."""
2
+
3
+ from typing import Any, Dict, List, Optional, Set
4
+
5
+ from .base import AstVisitor
6
+ from ..ast.interfaces import IAstNode
7
+
8
+ class NodeCounter(AstVisitor[int]):
9
+ """Visitor that counts nodes in the AST."""
10
+
11
+ def __init__(self):
12
+ self.count = 0
13
+ self.counts_by_type: Dict[str, int] = {}
14
+
15
+ def generic_visit(self, node: IAstNode) -> int:
16
+ """Count this node and visit its children."""
17
+ self.count += 1
18
+
19
+ # Count by node type
20
+ node_type = node.__class__.__name__
21
+ self.counts_by_type[node_type] = self.counts_by_type.get(node_type, 0) + 1
22
+
23
+ # Visit all children
24
+ for child in node.get_children():
25
+ self.visit(child)
26
+
27
+ return self.count
28
+
29
+ # Implement all the required visit methods by delegating to generic_visit
30
+ visit_program = generic_visit
31
+ visit_expression = generic_visit
32
+ visit_statement = generic_visit
33
+ visit_identifier = generic_visit
34
+ visit_variablereference = generic_visit
35
+ visit_binaryoperation = generic_visit
36
+ visit_unaryoperation = generic_visit
37
+ visit_functioncall = generic_visit
38
+ visit_keywordargument = generic_visit
39
+ visit_numberliteral = generic_visit
40
+ visit_stringliteral = generic_visit
41
+ visit_booleanliteral = generic_visit
42
+ visit_noneliteral = generic_visit
43
+ visit_expressionstatement = generic_visit
44
+ visit_assignment = generic_visit
45
+ visit_ifstatement = generic_visit
46
+ visit_whileloop = generic_visit
47
+ visit_forloop = generic_visit
48
+ visit_functiondefinition = generic_visit
49
+ visit_argument = generic_visit
50
+ visit_returnstatement = generic_visit
51
+ visit_breakstatement = generic_visit
52
+ visit_continuestatement = generic_visit
53
+ visit_vexapicall = generic_visit
54
+ visit_motorcontrol = generic_visit
55
+ visit_sensorreading = generic_visit
56
+ visit_timingcontrol = generic_visit
57
+ visit_displayoutput = generic_visit
58
+
59
+ class VariableCollector(AstVisitor[Set[str]]):
60
+ """Visitor that collects variable names used in the AST."""
61
+
62
+ def __init__(self):
63
+ self.variables: Set[str] = set()
64
+
65
+ def generic_visit(self, node: IAstNode) -> Set[str]:
66
+ """Collect variables from children."""
67
+ for child in node.get_children():
68
+ self.visit(child)
69
+ return self.variables
70
+
71
+ def visit_variablereference(self, node: Any) -> Set[str]:
72
+ """Collect a variable reference."""
73
+ self.variables.add(node.name)
74
+ return self.generic_visit(node)
75
+
76
+ # Delegate all other methods to generic_visit
77
+ visit_program = generic_visit
78
+ visit_expression = generic_visit
79
+ visit_statement = generic_visit
80
+ visit_identifier = generic_visit
81
+ visit_binaryoperation = generic_visit
82
+ visit_unaryoperation = generic_visit
83
+ visit_functioncall = generic_visit
84
+ visit_keywordargument = generic_visit
85
+ visit_numberliteral = generic_visit
86
+ visit_stringliteral = generic_visit
87
+ visit_booleanliteral = generic_visit
88
+ visit_noneliteral = generic_visit
89
+ visit_expressionstatement = generic_visit
90
+ visit_assignment = generic_visit
91
+ visit_ifstatement = generic_visit
92
+ visit_whileloop = generic_visit
93
+ visit_forloop = generic_visit
94
+ visit_functiondefinition = generic_visit
95
+ visit_argument = generic_visit
96
+ visit_returnstatement = generic_visit
97
+ visit_breakstatement = generic_visit
98
+ visit_continuestatement = generic_visit
99
+ visit_vexapicall = generic_visit
100
+ visit_motorcontrol = generic_visit
101
+ visit_sensorreading = generic_visit
102
+ visit_timingcontrol = generic_visit
103
103
  visit_displayoutput = generic_visit
vex_ast/visitors/base.py CHANGED
@@ -1,133 +1,133 @@
1
- """Base visitor classes for AST traversal."""
2
-
3
- from abc import ABC, abstractmethod
4
- from typing import Any, Dict, Generic, List, Optional, TypeVar, cast, Type
5
-
6
- from ..ast.interfaces import IAstNode, T_VisitorResult
7
-
8
- class AstVisitor(Generic[T_VisitorResult], ABC):
9
- """Base class for AST visitors using the Visitor pattern."""
10
-
11
- def visit(self, node: IAstNode) -> T_VisitorResult:
12
- """Visit a node by dispatching to its accept method."""
13
- return node.accept(self)
14
-
15
- def visit_children(self, node: IAstNode) -> List[T_VisitorResult]:
16
- """Visit all children of a node and return results."""
17
- return [self.visit(child) for child in node.get_children()]
18
-
19
- @abstractmethod
20
- def generic_visit(self, node: IAstNode) -> T_VisitorResult:
21
- """Default visitor method for nodes without a specific method."""
22
- pass
23
-
24
- # Required visit methods for core node types
25
- def visit_program(self, node: Any) -> T_VisitorResult:
26
- return self.generic_visit(node)
27
-
28
- def visit_expression(self, node: Any) -> T_VisitorResult:
29
- return self.generic_visit(node)
30
-
31
- def visit_statement(self, node: Any) -> T_VisitorResult:
32
- return self.generic_visit(node)
33
-
34
- # Visit methods for expressions
35
- def visit_identifier(self, node: Any) -> T_VisitorResult:
36
- return self.generic_visit(node)
37
-
38
- def visit_variablereference(self, node: Any) -> T_VisitorResult:
39
- return self.generic_visit(node)
40
-
41
- def visit_attributeaccess(self, node: Any) -> T_VisitorResult:
42
- return self.generic_visit(node)
43
-
44
- def visit_binaryoperation(self, node: Any) -> T_VisitorResult:
45
- return self.generic_visit(node)
46
-
47
- def visit_unaryoperation(self, node: Any) -> T_VisitorResult:
48
- return self.generic_visit(node)
49
-
50
- def visit_conditionalexpression(self, node: Any) -> T_VisitorResult:
51
- return self.generic_visit(node)
52
-
53
- def visit_functioncall(self, node: Any) -> T_VisitorResult:
54
- return self.generic_visit(node)
55
-
56
- def visit_keywordargument(self, node: Any) -> T_VisitorResult:
57
- return self.generic_visit(node)
58
-
59
- # Visit methods for literals
60
- def visit_numberliteral(self, node: Any) -> T_VisitorResult:
61
- return self.generic_visit(node)
62
-
63
- def visit_stringliteral(self, node: Any) -> T_VisitorResult:
64
- return self.generic_visit(node)
65
-
66
- def visit_booleanliteral(self, node: Any) -> T_VisitorResult:
67
- return self.generic_visit(node)
68
-
69
- def visit_noneliteral(self, node: Any) -> T_VisitorResult:
70
- return self.generic_visit(node)
71
-
72
- # Visit methods for statements
73
- def visit_expressionstatement(self, node: Any) -> T_VisitorResult:
74
- return self.generic_visit(node)
75
-
76
- def visit_assignment(self, node: Any) -> T_VisitorResult:
77
- return self.generic_visit(node)
78
-
79
- def visit_ifstatement(self, node: Any) -> T_VisitorResult:
80
- return self.generic_visit(node)
81
-
82
- def visit_whileloop(self, node: Any) -> T_VisitorResult:
83
- return self.generic_visit(node)
84
-
85
- def visit_forloop(self, node: Any) -> T_VisitorResult:
86
- return self.generic_visit(node)
87
-
88
- def visit_functiondefinition(self, node: Any) -> T_VisitorResult:
89
- return self.generic_visit(node)
90
-
91
- def visit_argument(self, node: Any) -> T_VisitorResult:
92
- return self.generic_visit(node)
93
-
94
- def visit_returnstatement(self, node: Any) -> T_VisitorResult:
95
- return self.generic_visit(node)
96
-
97
- def visit_breakstatement(self, node: Any) -> T_VisitorResult:
98
- return self.generic_visit(node)
99
-
100
- def visit_continuestatement(self, node: Any) -> T_VisitorResult:
101
- return self.generic_visit(node)
102
-
103
- # Visit methods for VEX-specific nodes
104
- def visit_vexapicall(self, node: Any) -> T_VisitorResult:
105
- return self.generic_visit(node)
106
-
107
- def visit_motorcontrol(self, node: Any) -> T_VisitorResult:
108
- return self.generic_visit(node)
109
-
110
- def visit_sensorreading(self, node: Any) -> T_VisitorResult:
111
- return self.generic_visit(node)
112
-
113
- def visit_timingcontrol(self, node: Any) -> T_VisitorResult:
114
- return self.generic_visit(node)
115
-
116
- def visit_displayoutput(self, node: Any) -> T_VisitorResult:
117
- return self.generic_visit(node)
118
-
119
-
120
- class TypedVisitorMixin:
121
- """Mixin to provide type-specific dispatch methods."""
122
-
123
- @staticmethod
124
- def node_type_to_method_name(node_type: Type) -> str:
125
- """Convert a node type to a visitor method name."""
126
- return f"visit_{node_type.__name__.lower()}"
127
-
128
- def dispatch_by_type(self, node: IAstNode) -> Any:
129
- """Dispatch to the appropriate visit method based on the node's type."""
130
- method_name = self.node_type_to_method_name(type(node))
131
- if hasattr(self, method_name):
132
- return getattr(self, method_name)(node)
133
- return self.generic_visit(node)
1
+ """Base visitor classes for AST traversal."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Any, Dict, Generic, List, Optional, TypeVar, cast, Type
5
+
6
+ from ..ast.interfaces import IAstNode, T_VisitorResult
7
+
8
+ class AstVisitor(Generic[T_VisitorResult], ABC):
9
+ """Base class for AST visitors using the Visitor pattern."""
10
+
11
+ def visit(self, node: IAstNode) -> T_VisitorResult:
12
+ """Visit a node by dispatching to its accept method."""
13
+ return node.accept(self)
14
+
15
+ def visit_children(self, node: IAstNode) -> List[T_VisitorResult]:
16
+ """Visit all children of a node and return results."""
17
+ return [self.visit(child) for child in node.get_children()]
18
+
19
+ @abstractmethod
20
+ def generic_visit(self, node: IAstNode) -> T_VisitorResult:
21
+ """Default visitor method for nodes without a specific method."""
22
+ pass
23
+
24
+ # Required visit methods for core node types
25
+ def visit_program(self, node: Any) -> T_VisitorResult:
26
+ return self.generic_visit(node)
27
+
28
+ def visit_expression(self, node: Any) -> T_VisitorResult:
29
+ return self.generic_visit(node)
30
+
31
+ def visit_statement(self, node: Any) -> T_VisitorResult:
32
+ return self.generic_visit(node)
33
+
34
+ # Visit methods for expressions
35
+ def visit_identifier(self, node: Any) -> T_VisitorResult:
36
+ return self.generic_visit(node)
37
+
38
+ def visit_variablereference(self, node: Any) -> T_VisitorResult:
39
+ return self.generic_visit(node)
40
+
41
+ def visit_attributeaccess(self, node: Any) -> T_VisitorResult:
42
+ return self.generic_visit(node)
43
+
44
+ def visit_binaryoperation(self, node: Any) -> T_VisitorResult:
45
+ return self.generic_visit(node)
46
+
47
+ def visit_unaryoperation(self, node: Any) -> T_VisitorResult:
48
+ return self.generic_visit(node)
49
+
50
+ def visit_conditionalexpression(self, node: Any) -> T_VisitorResult:
51
+ return self.generic_visit(node)
52
+
53
+ def visit_functioncall(self, node: Any) -> T_VisitorResult:
54
+ return self.generic_visit(node)
55
+
56
+ def visit_keywordargument(self, node: Any) -> T_VisitorResult:
57
+ return self.generic_visit(node)
58
+
59
+ # Visit methods for literals
60
+ def visit_numberliteral(self, node: Any) -> T_VisitorResult:
61
+ return self.generic_visit(node)
62
+
63
+ def visit_stringliteral(self, node: Any) -> T_VisitorResult:
64
+ return self.generic_visit(node)
65
+
66
+ def visit_booleanliteral(self, node: Any) -> T_VisitorResult:
67
+ return self.generic_visit(node)
68
+
69
+ def visit_noneliteral(self, node: Any) -> T_VisitorResult:
70
+ return self.generic_visit(node)
71
+
72
+ # Visit methods for statements
73
+ def visit_expressionstatement(self, node: Any) -> T_VisitorResult:
74
+ return self.generic_visit(node)
75
+
76
+ def visit_assignment(self, node: Any) -> T_VisitorResult:
77
+ return self.generic_visit(node)
78
+
79
+ def visit_ifstatement(self, node: Any) -> T_VisitorResult:
80
+ return self.generic_visit(node)
81
+
82
+ def visit_whileloop(self, node: Any) -> T_VisitorResult:
83
+ return self.generic_visit(node)
84
+
85
+ def visit_forloop(self, node: Any) -> T_VisitorResult:
86
+ return self.generic_visit(node)
87
+
88
+ def visit_functiondefinition(self, node: Any) -> T_VisitorResult:
89
+ return self.generic_visit(node)
90
+
91
+ def visit_argument(self, node: Any) -> T_VisitorResult:
92
+ return self.generic_visit(node)
93
+
94
+ def visit_returnstatement(self, node: Any) -> T_VisitorResult:
95
+ return self.generic_visit(node)
96
+
97
+ def visit_breakstatement(self, node: Any) -> T_VisitorResult:
98
+ return self.generic_visit(node)
99
+
100
+ def visit_continuestatement(self, node: Any) -> T_VisitorResult:
101
+ return self.generic_visit(node)
102
+
103
+ # Visit methods for VEX-specific nodes
104
+ def visit_vexapicall(self, node: Any) -> T_VisitorResult:
105
+ return self.generic_visit(node)
106
+
107
+ def visit_motorcontrol(self, node: Any) -> T_VisitorResult:
108
+ return self.generic_visit(node)
109
+
110
+ def visit_sensorreading(self, node: Any) -> T_VisitorResult:
111
+ return self.generic_visit(node)
112
+
113
+ def visit_timingcontrol(self, node: Any) -> T_VisitorResult:
114
+ return self.generic_visit(node)
115
+
116
+ def visit_displayoutput(self, node: Any) -> T_VisitorResult:
117
+ return self.generic_visit(node)
118
+
119
+
120
+ class TypedVisitorMixin:
121
+ """Mixin to provide type-specific dispatch methods."""
122
+
123
+ @staticmethod
124
+ def node_type_to_method_name(node_type: Type) -> str:
125
+ """Convert a node type to a visitor method name."""
126
+ return f"visit_{node_type.__name__.lower()}"
127
+
128
+ def dispatch_by_type(self, node: IAstNode) -> Any:
129
+ """Dispatch to the appropriate visit method based on the node's type."""
130
+ method_name = self.node_type_to_method_name(type(node))
131
+ if hasattr(self, method_name):
132
+ return getattr(self, method_name)(node)
133
+ return self.generic_visit(node)