vex-ast 0.1.0__tar.gz → 0.2.1__tar.gz

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 (86) hide show
  1. vex_ast-0.2.1/LICENSE +1 -0
  2. vex_ast-0.2.1/MANIFEST.in +20 -0
  3. {vex_ast-0.1.0 → vex_ast-0.2.1}/PKG-INFO +9 -11
  4. {vex_ast-0.1.0 → vex_ast-0.2.1}/README.md +2 -2
  5. vex_ast-0.2.1/pyproject.toml +28 -0
  6. vex_ast-0.2.1/pytest.ini +8 -0
  7. vex_ast-0.2.1/requirements.txt +5 -0
  8. {vex_ast-0.1.0 → vex_ast-0.2.1}/setup.py +5 -9
  9. vex_ast-0.2.1/tests/conftest.py +11 -0
  10. vex_ast-0.2.1/vex_ast/README.md +51 -0
  11. vex_ast-0.2.1/vex_ast/READMEAPI.md +318 -0
  12. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/__init__.py +20 -17
  13. vex_ast-0.2.1/vex_ast/ast/README.md +87 -0
  14. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/__init__.py +1 -1
  15. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/navigator.py +12 -0
  16. vex_ast-0.2.1/vex_ast/parser/README.md +47 -0
  17. vex_ast-0.2.1/vex_ast/parser/__init__.py +27 -0
  18. vex_ast-0.2.1/vex_ast/registry/README.md +29 -0
  19. vex_ast-0.2.1/vex_ast/registry/functions/__init__.py +11 -0
  20. vex_ast-0.2.1/vex_ast/registry/functions/display.py +147 -0
  21. vex_ast-0.2.1/vex_ast/registry/functions/drivetrain.py +163 -0
  22. vex_ast-0.2.1/vex_ast/registry/functions/initialize.py +28 -0
  23. vex_ast-0.2.1/vex_ast/registry/functions/motor.py +140 -0
  24. vex_ast-0.2.1/vex_ast/registry/functions/sensors.py +195 -0
  25. vex_ast-0.2.1/vex_ast/registry/functions/timing.py +104 -0
  26. vex_ast-0.2.1/vex_ast/types/README.md +26 -0
  27. vex_ast-0.2.1/vex_ast/types/__init__.py +140 -0
  28. vex_ast-0.2.1/vex_ast/types/base.py +84 -0
  29. vex_ast-0.2.1/vex_ast/types/enums.py +97 -0
  30. vex_ast-0.2.1/vex_ast/types/objects.py +64 -0
  31. vex_ast-0.2.1/vex_ast/types/primitives.py +69 -0
  32. vex_ast-0.2.1/vex_ast/types/type_checker.py +32 -0
  33. vex_ast-0.2.1/vex_ast/utils/README.md +39 -0
  34. vex_ast-0.2.1/vex_ast/utils/__init__.py +38 -0
  35. vex_ast-0.2.1/vex_ast/utils/type_definitions.py +9 -0
  36. vex_ast-0.2.1/vex_ast/visitors/README.md +49 -0
  37. vex_ast-0.2.1/vex_ast/visitors/__init__.py +28 -0
  38. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast.egg-info/PKG-INFO +9 -11
  39. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast.egg-info/SOURCES.txt +27 -0
  40. vex_ast-0.1.0/vex_ast/parser/__init__.py +0 -0
  41. vex_ast-0.1.0/vex_ast/utils/__init__.py +0 -0
  42. vex_ast-0.1.0/vex_ast/utils/type_definitions.py +0 -0
  43. vex_ast-0.1.0/vex_ast/visitors/__init__.py +0 -0
  44. {vex_ast-0.1.0 → vex_ast-0.2.1}/setup.cfg +0 -0
  45. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_core.py +0 -0
  46. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_integration.py +0 -0
  47. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_literals.py +0 -0
  48. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_navigator.py +0 -0
  49. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_parser.py +0 -0
  50. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_registry.py +0 -0
  51. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_serialization.py +0 -0
  52. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_statements.py +0 -0
  53. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_vex_nodes.py +0 -0
  54. {vex_ast-0.1.0 → vex_ast-0.2.1}/tests/test_visitors.py +0 -0
  55. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/core.py +0 -0
  56. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/expressions.py +0 -0
  57. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/interfaces.py +0 -0
  58. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/literals.py +0 -0
  59. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/operators.py +0 -0
  60. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/statements.py +0 -0
  61. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/validators.py +0 -0
  62. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/ast/vex_nodes.py +0 -0
  63. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/parser/factory.py +0 -0
  64. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/parser/interfaces.py +0 -0
  65. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/parser/python_parser.py +0 -0
  66. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/parser/strategies.py +0 -0
  67. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/__init__.py +0 -0
  68. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/api.py +0 -0
  69. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/categories.py +0 -0
  70. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/language_map.py +0 -0
  71. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/registry.py +0 -0
  72. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/signature.py +0 -0
  73. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/simulation_behavior.py +0 -0
  74. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/registry/validation.py +0 -0
  75. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/serialization/__init__.py +0 -0
  76. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/serialization/json_deserializer.py +0 -0
  77. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/serialization/json_serializer.py +0 -0
  78. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/serialization/schema.py +0 -0
  79. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/utils/errors.py +0 -0
  80. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/utils/source_location.py +0 -0
  81. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/visitors/analyzer.py +0 -0
  82. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/visitors/base.py +0 -0
  83. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/visitors/printer.py +0 -0
  84. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast/visitors/transformer.py +0 -0
  85. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast.egg-info/dependency_links.txt +0 -0
  86. {vex_ast-0.1.0 → vex_ast-0.2.1}/vex_ast.egg-info/top_level.txt +0 -0
vex_ast-0.2.1/LICENSE ADDED
@@ -0,0 +1 @@
1
+ HX2's Vex AST © 2025 by charkwayteowy is licensed under CC BY-NC 4.0
@@ -0,0 +1,20 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ include pytest.ini
5
+ include pyproject.toml
6
+
7
+ # Include all documentation files
8
+ recursive-include vex_ast *README.md
9
+ recursive-include vex_ast *READMEAPI.md
10
+
11
+ # Include test files
12
+ recursive-include tests *.py
13
+
14
+ # Exclude cache files
15
+ global-exclude __pycache__
16
+ global-exclude *.py[cod]
17
+ global-exclude *.so
18
+ global-exclude .DS_Store
19
+ global-exclude .env
20
+ global-exclude .coverage
@@ -1,13 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vex_ast
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: A Python package for generating Abstract Syntax Trees for VEX V5 code.
5
- Home-page: https://github.com/teowy/vex_ast
5
+ Home-page: https://github.com/heartx2/vex_ast
6
6
  Author: Chaze
7
- Author-email: chazelexander@example.com
7
+ Author-email: Chaze <chazelexander@gmail.com>
8
+ License: HX2's Vex AST © 2025 by charkwayteowy is licensed under CC BY-NC 4.0
9
+ Project-URL: Repository, https://github.com/heartx2/vex_ast
8
10
  Classifier: Development Status :: 3 - Alpha
9
11
  Classifier: Intended Audience :: Developers
10
- Classifier: License :: OSI Approved :: MIT License
11
12
  Classifier: Programming Language :: Python :: 3
12
13
  Classifier: Programming Language :: Python :: 3.8
13
14
  Classifier: Programming Language :: Python :: 3.9
@@ -17,14 +18,11 @@ Classifier: Topic :: Software Development :: Compilers
17
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
19
  Requires-Python: >=3.8
19
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
20
22
  Dynamic: author
21
- Dynamic: author-email
22
- Dynamic: classifier
23
- Dynamic: description
24
- Dynamic: description-content-type
25
23
  Dynamic: home-page
24
+ Dynamic: license-file
26
25
  Dynamic: requires-python
27
- Dynamic: summary
28
26
 
29
27
  # VEX AST Generator
30
28
 
@@ -60,7 +58,7 @@ The core library is within the `vex_ast` directory:
60
58
 
61
59
  1. **Clone the repository:**
62
60
  ```bash
63
- git clone https://github.com/yourusername/vex_ast.git # Replace with actual URL
61
+ git clone https://github.com/heartx2/vex_ast # Replace with actual URL
64
62
  cd vex_ast
65
63
  ```
66
64
 
@@ -173,4 +171,4 @@ Contributions are welcome! Please follow the established coding standards and en
173
171
 
174
172
  ## License
175
173
 
176
- This project is licensed under the MIT License - see the LICENSE file for details (You'll need to add a LICENSE file).
174
+ HX2's Vex AST © 2025 by charkwayteowy is licensed under CC BY-NC 4.0
@@ -32,7 +32,7 @@ The core library is within the `vex_ast` directory:
32
32
 
33
33
  1. **Clone the repository:**
34
34
  ```bash
35
- git clone https://github.com/yourusername/vex_ast.git # Replace with actual URL
35
+ git clone https://github.com/heartx2/vex_ast # Replace with actual URL
36
36
  cd vex_ast
37
37
  ```
38
38
 
@@ -145,4 +145,4 @@ Contributions are welcome! Please follow the established coding standards and en
145
145
 
146
146
  ## License
147
147
 
148
- This project is licensed under the MIT License - see the LICENSE file for details (You'll need to add a LICENSE file).
148
+ HX2's Vex AST © 2025 by charkwayteowy is licensed under CC BY-NC 4.0
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=45", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vex_ast"
7
+ version = "0.2.1"
8
+ description = "A Python package for generating Abstract Syntax Trees for VEX V5 code."
9
+ readme = "README.md"
10
+ authors = [
11
+ {name = "Chaze", email = "chazelexander@gmail.com"},
12
+ ]
13
+ license = {file = "LICENSE"}
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Topic :: Software Development :: Compilers",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ ]
26
+
27
+ [project.urls]
28
+ Repository = "https://github.com/heartx2/vex_ast" # Replace with actual URL
@@ -0,0 +1,8 @@
1
+ [pytest]
2
+ minversion = 6.0
3
+ testpaths = tests
4
+ python_files = test_*.py
5
+ addopts =
6
+ # You can add markers here later, e.g.,
7
+ # markers =
8
+ # slow: marks tests as slow (deselect with '-m "not slow"')
@@ -0,0 +1,5 @@
1
+ pytest
2
+ pytest-cov
3
+ mypy
4
+ black
5
+ flake8
@@ -2,21 +2,17 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='vex_ast',
5
- version='0.1.0',
5
+ version='0.2.1',
6
6
  description='A Python package for generating Abstract Syntax Trees for VEX V5 code.',
7
7
  long_description=open('README.md').read(),
8
8
  long_description_content_type='text/markdown',
9
- author='Chaze', # Replace with your actual name
10
- author_email='chazelexander@example.com', # Replace with your actual email
11
- url='https://github.com/teowy/vex_ast', # Replace with your actual repository URL
12
- packages=find_packages(exclude=['tests*']),
13
- install_requires=[
14
- # Add runtime dependencies here if any
15
- ],
9
+ author='Chaze',
10
+ author_email='chazelexander@gmail.com',
11
+ url='https://github.com/heartx2/vex_ast',
12
+ packages=find_packages(),
16
13
  classifiers=[
17
14
  'Development Status :: 3 - Alpha',
18
15
  'Intended Audience :: Developers',
19
- 'License :: OSI Approved :: MIT License',
20
16
  'Programming Language :: Python :: 3',
21
17
  'Programming Language :: Python :: 3.8',
22
18
  'Programming Language :: Python :: 3.9',
@@ -0,0 +1,11 @@
1
+ # tests/conftest.py
2
+ import os
3
+ import sys
4
+ import pytest
5
+
6
+ # Get the absolute path to the project root directory
7
+ project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
8
+
9
+ # Add the project root to the Python path if it's not already there
10
+ if project_root not in sys.path:
11
+ sys.path.insert(0, project_root)
@@ -0,0 +1,51 @@
1
+ VEX AST Package (vex_ast)
2
+
3
+ This directory is the root of the vex_ast Python package. It orchestrates the different components of the VEX AST generation and processing system.
4
+
5
+ Purpose
6
+
7
+ The vex_ast package provides a unified interface for parsing VEX V5 Python code into an Abstract Syntax Tree (AST) and tools for working with that AST.
8
+
9
+ Structure
10
+
11
+ The package is organized into several sub-packages:
12
+
13
+ ast/: Contains the definitions for all AST node types, representing the structure of the parsed code. See vex_ast/ast/README.md.
14
+
15
+ parser/: Includes the parsing logic responsible for converting source code text into an AST instance. See vex_ast/parser/README.md.
16
+
17
+ visitors/: Provides implementations of the Visitor pattern for traversing, analyzing, or transforming the AST. See vex_ast/visitors/README.md.
18
+
19
+ utils/: Contains utility classes and functions, primarily for error handling and source location tracking. See vex_ast/utils/README.md.
20
+
21
+ Core Exports
22
+
23
+ The main components are exposed through the vex_ast/__init__.py file, making them easily accessible:
24
+
25
+ parse_string(source, ...): Parses Python code from a string.
26
+
27
+ parse_file(filepath, ...): Parses Python code from a file.
28
+
29
+ Program: The root node type of the generated AST.
30
+
31
+ PrintVisitor: A visitor to generate a string representation of the AST.
32
+
33
+ NodeCounter: A visitor to count nodes in the AST.
34
+
35
+ VariableCollector: A visitor to collect variable names used in the AST.
36
+
37
+ ErrorHandler: Class for managing errors during parsing and processing.
38
+
39
+ VexSyntaxError, VexAstError: Custom exception types.
40
+
41
+ Workflow
42
+
43
+ The typical workflow involves:
44
+
45
+ Using parse_string or parse_file from this package to generate an AST (Program object) from source code.
46
+
47
+ Instantiating one or more visitors from vex_ast.visitors (or custom ones).
48
+
49
+ Calling the visit method of the visitor with the root Program node to perform analysis, transformation, or other operations on the AST.
50
+
51
+ Using the ErrorHandler to manage and inspect any errors encountered during the process.
@@ -0,0 +1,318 @@
1
+ # VEX AST (`vex_ast`) - Public API Reference
2
+
3
+ This document describes the main functions and classes exposed by the `vex_ast` package, intended for users who want to parse VEX V5 Python code and interact with the resulting Abstract Syntax Tree (AST).
4
+
5
+ ## Overview
6
+
7
+ The core workflow typically involves:
8
+
9
+ 1. Parsing source code (from a string or file) using `parse_string` or `parse_file`. This requires an optional `ErrorHandler` instance.
10
+ 2. Receiving a `Program` object, which is the root of the generated AST.
11
+ 3. Instantiating one or more `AstVisitor` subclasses (like `PrintVisitor`, `NodeCounter`, `VariableCollector`, or custom ones).
12
+ 4. Calling the visitor's `visit()` method with the `Program` node to traverse the AST and perform actions.
13
+ 5. Checking the `ErrorHandler` instance for any reported errors during parsing or visiting.
14
+
15
+ ---
16
+
17
+ ## Parsing Functions
18
+
19
+ These functions are the entry points for converting source code into an AST.
20
+
21
+ ### `parse_string`
22
+
23
+ Parses VEX V5 Python code provided as a string.
24
+
25
+ **Signature:**
26
+
27
+ ```python
28
+ def parse_string(
29
+ source: str,
30
+ filename: str = "<string>",
31
+ error_handler: Optional[ErrorHandler] = None
32
+ ) -> Program:
33
+
34
+
35
+ Arguments:
36
+
37
+ source (str): The string containing the Python code to parse.
38
+
39
+ filename (str, optional): The name to associate with the source code, used in error messages and source locations. Defaults to "<string>".
40
+
41
+ error_handler (Optional[ErrorHandler], optional): An instance of ErrorHandler to collect parsing errors. If None, a default ErrorHandler is created internally (which will raise VexSyntaxError on the first syntax error). It's recommended to provide your own handler to manage errors more flexibly.
42
+
43
+ Returns:
44
+
45
+ Program: The root node of the generated Abstract Syntax Tree.
46
+
47
+ Raises:
48
+
49
+ VexSyntaxError: If a syntax error is encountered during parsing and the error_handler is configured to raise errors immediately (or if no handler is provided).
50
+
51
+ VexAstError: For other internal parsing or AST conversion issues if the error_handler is configured to raise errors.
52
+
53
+ parse_file
54
+
55
+ Parses VEX V5 Python code read from a specified file.
56
+
57
+ Signature:
58
+
59
+ def parse_file(
60
+ filepath: str,
61
+ error_handler: Optional[ErrorHandler] = None
62
+ ) -> Program:
63
+ IGNORE_WHEN_COPYING_START
64
+ content_copy
65
+ download
66
+ Use code with caution.
67
+ Python
68
+ IGNORE_WHEN_COPYING_END
69
+
70
+ Arguments:
71
+
72
+ filepath (str): The path to the Python file to be parsed.
73
+
74
+ error_handler (Optional[ErrorHandler], optional): An instance of ErrorHandler to collect parsing errors. See parse_string for details.
75
+
76
+ Returns:
77
+
78
+ Program: The root node of the generated Abstract Syntax Tree.
79
+
80
+ Raises:
81
+
82
+ FileNotFoundError: If the specified filepath does not exist.
83
+
84
+ IOError: If there is an error reading the file.
85
+
86
+ VexSyntaxError: If a syntax error is encountered (see parse_string).
87
+
88
+ VexAstError: For other internal parsing errors (see parse_string).
89
+
90
+ Core AST Node
91
+ Program
92
+
93
+ Represents the root node of the entire Abstract Syntax Tree.
94
+
95
+ Description:
96
+
97
+ The Program node is the object returned by parse_string and parse_file. It serves as the entry point for traversing the AST using visitors.
98
+
99
+ Key Attribute:
100
+
101
+ body (List[IStatement]): A list containing the top-level statements (like function definitions, assignments, expression statements) found in the parsed code.
102
+
103
+ Usage:
104
+
105
+ You typically don't instantiate Program directly. You receive it from a parsing function and pass it to the visit() method of an AstVisitor.
106
+
107
+ ast_root: Program = parse_string("x = 1")
108
+ printer = PrintVisitor()
109
+ printer.visit(ast_root) # Pass the Program node to the visitor
110
+ IGNORE_WHEN_COPYING_START
111
+ content_copy
112
+ download
113
+ Use code with caution.
114
+ Python
115
+ IGNORE_WHEN_COPYING_END
116
+ Standard Visitors
117
+
118
+ Visitors provide mechanisms to traverse and process the AST. You instantiate a visitor and then call its visit method on an AST node (usually the Program root).
119
+
120
+ PrintVisitor
121
+
122
+ Generates a formatted, indented string representation of the AST structure. Useful for debugging and inspection.
123
+
124
+ Instantiation:
125
+
126
+ printer = PrintVisitor()
127
+ IGNORE_WHEN_COPYING_START
128
+ content_copy
129
+ download
130
+ Use code with caution.
131
+ Python
132
+ IGNORE_WHEN_COPYING_END
133
+
134
+ Core Method:
135
+
136
+ visit(node: IAstNode) -> str: Traverses the AST starting from node (typically the Program root) and returns a multi-line string representing the tree.
137
+
138
+ Example:
139
+
140
+ ast_root = parse_string("y = a + 5")
141
+ visitor = PrintVisitor()
142
+ ast_string_representation = visitor.visit(ast_root)
143
+ print(ast_string_representation)
144
+ IGNORE_WHEN_COPYING_START
145
+ content_copy
146
+ download
147
+ Use code with caution.
148
+ Python
149
+ IGNORE_WHEN_COPYING_END
150
+ NodeCounter
151
+
152
+ Counts the number of nodes in the AST.
153
+
154
+ Instantiation:
155
+
156
+ counter = NodeCounter()
157
+ IGNORE_WHEN_COPYING_START
158
+ content_copy
159
+ download
160
+ Use code with caution.
161
+ Python
162
+ IGNORE_WHEN_COPYING_END
163
+
164
+ Core Method:
165
+
166
+ visit(node: IAstNode) -> int: Traverses the AST starting from node and returns the total count of nodes visited.
167
+
168
+ Additional Attribute:
169
+
170
+ counts_by_type (Dict[str, int]): After calling visit, this dictionary holds the counts for each specific node type encountered (e.g., {'Assignment': 1, 'BinaryOperation': 1, ...}).
171
+
172
+ Example:
173
+
174
+ ast_root = parse_string("def f():\n return 10")
175
+ visitor = NodeCounter()
176
+ total_nodes = visitor.visit(ast_root)
177
+ print(f"Total nodes: {total_nodes}")
178
+ print(f"Nodes by type: {visitor.counts_by_type}")
179
+ IGNORE_WHEN_COPYING_START
180
+ content_copy
181
+ download
182
+ Use code with caution.
183
+ Python
184
+ IGNORE_WHEN_COPYING_END
185
+ VariableCollector
186
+
187
+ Collects the names of all variables referenced (read from) in the AST. Does not include variables only assigned to or function/class names being defined.
188
+
189
+ Instantiation:
190
+
191
+ collector = VariableCollector()
192
+ IGNORE_WHEN_COPYING_START
193
+ content_copy
194
+ download
195
+ Use code with caution.
196
+ Python
197
+ IGNORE_WHEN_COPYING_END
198
+
199
+ Core Method:
200
+
201
+ visit(node: IAstNode) -> Set[str]: Traverses the AST starting from node and returns a set containing the names of all referenced variables (identifiers used in a Load context).
202
+
203
+ Example:
204
+
205
+ code = """
206
+ x = 10
207
+ y = x + z
208
+ def my_func(p):
209
+ q = p
210
+ """
211
+ ast_root = parse_string(code)
212
+ visitor = VariableCollector()
213
+ referenced_vars = visitor.visit(ast_root)
214
+ print(f"Referenced variables: {referenced_vars}") # Output: {'x', 'z', 'p'}
215
+ IGNORE_WHEN_COPYING_START
216
+ content_copy
217
+ download
218
+ Use code with caution.
219
+ Python
220
+ IGNORE_WHEN_COPYING_END
221
+ Error Handling
222
+
223
+ Components for managing and reporting errors during parsing and processing.
224
+
225
+ ErrorHandler
226
+
227
+ Manages the collection and reporting of errors.
228
+
229
+ Instantiation:
230
+
231
+ # Option 1: Collect errors, don't raise exceptions immediately
232
+ handler = ErrorHandler(raise_on_error=False)
233
+
234
+ # Option 2: Raise VexSyntaxError/VexAstError on the first error
235
+ handler = ErrorHandler(raise_on_error=True) # Default behavior if omitted
236
+ IGNORE_WHEN_COPYING_START
237
+ content_copy
238
+ download
239
+ Use code with caution.
240
+ Python
241
+ IGNORE_WHEN_COPYING_END
242
+
243
+ Key Methods:
244
+
245
+ get_errors() -> List[Error]: Returns a list of all Error objects collected so far.
246
+
247
+ has_errors() -> bool: Returns True if any errors have been collected, False otherwise. Useful after parsing with raise_on_error=False.
248
+
249
+ clear_errors() -> None: Removes all collected errors.
250
+
251
+ add_observer(observer: ErrorObserver) -> None: (Advanced) Registers a custom object to be notified whenever an error is added.
252
+
253
+ remove_observer(observer: ErrorObserver) -> None: (Advanced) Unregisters an observer.
254
+
255
+ Usage:
256
+
257
+ Typically, you create an ErrorHandler instance and pass it to parse_string or parse_file.
258
+
259
+ error_handler = ErrorHandler(raise_on_error=False)
260
+ try:
261
+ ast = parse_string("x = 1 + ", error_handler=error_handler)
262
+ if error_handler.has_errors():
263
+ print("Parsing completed with non-fatal errors:")
264
+ for err in error_handler.get_errors():
265
+ print(f"- {err}")
266
+ else:
267
+ print("Parsing successful.")
268
+ # Proceed with AST processing...
269
+ except VexAstError as e:
270
+ # This shouldn't happen if raise_on_error=False, but good practice
271
+ print(f"Unexpected VexAstError: {e}")
272
+ IGNORE_WHEN_COPYING_START
273
+ content_copy
274
+ download
275
+ Use code with caution.
276
+ Python
277
+ IGNORE_WHEN_COPYING_END
278
+ ErrorType
279
+
280
+ An Enum used within Error objects to categorize the type of error.
281
+
282
+ Values:
283
+
284
+ LEXER_ERROR
285
+
286
+ PARSER_ERROR
287
+
288
+ TYPE_ERROR
289
+
290
+ SEMANTIC_ERROR
291
+
292
+ INTERNAL_ERROR
293
+
294
+ Usage:
295
+
296
+ You typically check the error_type attribute of Error objects retrieved from ErrorHandler.get_errors().
297
+
298
+ VexSyntaxError
299
+
300
+ Exception raised specifically for syntax errors encountered during parsing when the ErrorHandler is configured to raise errors.
301
+
302
+ Inheritance: VexSyntaxError -> VexAstError -> Exception
303
+
304
+ Attribute:
305
+
306
+ location (Optional[SourceLocation]): May contain the location (line, column) where the syntax error occurred.
307
+
308
+ VexAstError
309
+
310
+ The base exception class for all errors originating from the vex_ast library. VexSyntaxError is a subclass.
311
+
312
+ This reference covers the main components needed to use the vex_ast library effectively for parsing and basic AST interaction. For more advanced use cases, you might need to delve into the specific AST node types in vex_ast.ast or create custom visitors inheriting from vex_ast.visitors.AstVisitor.
313
+
314
+ IGNORE_WHEN_COPYING_START
315
+ content_copy
316
+ download
317
+ Use code with caution.
318
+ IGNORE_WHEN_COPYING_END
@@ -4,13 +4,25 @@ VEX AST Generator Package.
4
4
  Provides tools for parsing VEX V5 code and generating an Abstract Syntax Tree (AST).
5
5
  """
6
6
 
7
+ # Core functionality
7
8
  from .ast.core import Program
8
- from .ast.navigator import AstNavigator
9
9
  from .parser.python_parser import parse_string, parse_file
10
+
11
+ # AST Navigation
12
+ from .ast.navigator import AstNavigator, create_navigator
13
+
14
+ # Visitors
10
15
  from .visitors.printer import PrintVisitor
11
16
  from .visitors.analyzer import NodeCounter, VariableCollector
12
- from .utils.errors import ErrorHandler, ErrorType, VexSyntaxError
13
- from .registry import registry_api, initialize as initialize_registry
17
+
18
+ # Error handling
19
+ from .utils.errors import ErrorHandler, ErrorType, VexSyntaxError, VexAstError, Error
20
+
21
+ # Registry
22
+ from .registry.api import registry_api
23
+ from .registry import initialize
24
+
25
+ # Serialization
14
26
  from .serialization.json_serializer import serialize_ast_to_dict, serialize_ast_to_json
15
27
  from .serialization.json_deserializer import deserialize_ast_from_dict, deserialize_ast_from_json
16
28
  from .serialization.schema import generate_ast_schema, export_schema_to_file
@@ -18,18 +30,7 @@ from .serialization.schema import generate_ast_schema, export_schema_to_file
18
30
  __version__ = "0.2.0"
19
31
 
20
32
  # Initialize the registry with default functions
21
- initialize_registry()
22
-
23
- def create_navigator(ast: Program) -> AstNavigator:
24
- """Create an AST navigator for the given AST.
25
-
26
- Args:
27
- ast: The AST to navigate
28
-
29
- Returns:
30
- An AST navigator for traversing and querying the AST
31
- """
32
- return AstNavigator(ast)
33
+ initialize()
33
34
 
34
35
  __all__ = [
35
36
  # Core functionality
@@ -50,10 +51,12 @@ __all__ = [
50
51
  "ErrorHandler",
51
52
  "ErrorType",
52
53
  "VexSyntaxError",
54
+ "VexAstError",
55
+ "Error",
53
56
 
54
57
  # Registry
55
58
  "registry_api",
56
- "initialize_registry",
59
+ "initialize",
57
60
 
58
61
  # Serialization
59
62
  "serialize_ast_to_dict",
@@ -62,4 +65,4 @@ __all__ = [
62
65
  "deserialize_ast_from_json",
63
66
  "generate_ast_schema",
64
67
  "export_schema_to_file"
65
- ]
68
+ ]