pylgen-core 0.5.4__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 (92) hide show
  1. pylgen_core-0.5.4/LICENSE +30 -0
  2. pylgen_core-0.5.4/MANIFEST.in +9 -0
  3. pylgen_core-0.5.4/PKG-INFO +194 -0
  4. pylgen_core-0.5.4/pylgen/__init__.py +0 -0
  5. pylgen_core-0.5.4/pylgen/analysis/__init__.py +5 -0
  6. pylgen_core-0.5.4/pylgen/analysis/context.c +13373 -0
  7. pylgen_core-0.5.4/pylgen/analysis/context.pxd +19 -0
  8. pylgen_core-0.5.4/pylgen/analysis/context.pyi +35 -0
  9. pylgen_core-0.5.4/pylgen/analysis/context.pyx +107 -0
  10. pylgen_core-0.5.4/pylgen/analysis/error.c +16566 -0
  11. pylgen_core-0.5.4/pylgen/analysis/error.pxd +18 -0
  12. pylgen_core-0.5.4/pylgen/analysis/error.pyi +46 -0
  13. pylgen_core-0.5.4/pylgen/analysis/error.pyx +88 -0
  14. pylgen_core-0.5.4/pylgen/analysis/error_type.py +7 -0
  15. pylgen_core-0.5.4/pylgen/analysis/lexical.c +11168 -0
  16. pylgen_core-0.5.4/pylgen/analysis/lexical.pxd +7 -0
  17. pylgen_core-0.5.4/pylgen/analysis/lexical.pyi +10 -0
  18. pylgen_core-0.5.4/pylgen/analysis/lexical.pyx +14 -0
  19. pylgen_core-0.5.4/pylgen/analysis/visitor.c +19915 -0
  20. pylgen_core-0.5.4/pylgen/analysis/visitor.pxd +47 -0
  21. pylgen_core-0.5.4/pylgen/analysis/visitor.pyi +49 -0
  22. pylgen_core-0.5.4/pylgen/analysis/visitor.pyx +178 -0
  23. pylgen_core-0.5.4/pylgen/automaton/__init__.py +12 -0
  24. pylgen_core-0.5.4/pylgen/automaton/automaton.c +40874 -0
  25. pylgen_core-0.5.4/pylgen/automaton/automaton.pxd +63 -0
  26. pylgen_core-0.5.4/pylgen/automaton/automaton.pyi +154 -0
  27. pylgen_core-0.5.4/pylgen/automaton/automaton.pyx +1631 -0
  28. pylgen_core-0.5.4/pylgen/common/__init__.py +1 -0
  29. pylgen_core-0.5.4/pylgen/common/enums.py +11 -0
  30. pylgen_core-0.5.4/pylgen/common/symbol.c +9883 -0
  31. pylgen_core-0.5.4/pylgen/common/table.c +11952 -0
  32. pylgen_core-0.5.4/pylgen/common/table.pxd +5 -0
  33. pylgen_core-0.5.4/pylgen/common/table.pyi +25 -0
  34. pylgen_core-0.5.4/pylgen/common/table.pyx +64 -0
  35. pylgen_core-0.5.4/pylgen/common/types.c +17784 -0
  36. pylgen_core-0.5.4/pylgen/common/types.pxd +30 -0
  37. pylgen_core-0.5.4/pylgen/common/types.pyi +70 -0
  38. pylgen_core-0.5.4/pylgen/common/types.pyx +159 -0
  39. pylgen_core-0.5.4/pylgen/grammar/__init__.py +1 -0
  40. pylgen_core-0.5.4/pylgen/grammar/grammar.c +29820 -0
  41. pylgen_core-0.5.4/pylgen/grammar/grammar.pxd +55 -0
  42. pylgen_core-0.5.4/pylgen/grammar/grammar.pyi +99 -0
  43. pylgen_core-0.5.4/pylgen/grammar/grammar.pyx +779 -0
  44. pylgen_core-0.5.4/pylgen/lexer/__init__.py +2 -0
  45. pylgen_core-0.5.4/pylgen/lexer/base_lexer.c +20874 -0
  46. pylgen_core-0.5.4/pylgen/lexer/base_lexer.pxd +38 -0
  47. pylgen_core-0.5.4/pylgen/lexer/base_lexer.pyi +25 -0
  48. pylgen_core-0.5.4/pylgen/lexer/base_lexer.pyx +313 -0
  49. pylgen_core-0.5.4/pylgen/lexer/lexer.c +16418 -0
  50. pylgen_core-0.5.4/pylgen/lexer/lexer.pxd +13 -0
  51. pylgen_core-0.5.4/pylgen/lexer/lexer.pyi +22 -0
  52. pylgen_core-0.5.4/pylgen/lexer/lexer.pyx +101 -0
  53. pylgen_core-0.5.4/pylgen/parser/__init__.py +3 -0
  54. pylgen_core-0.5.4/pylgen/parser/bottom_up_parser_actions.py +7 -0
  55. pylgen_core-0.5.4/pylgen/parser/lalr_parser.c +13756 -0
  56. pylgen_core-0.5.4/pylgen/parser/lalr_parser.pxd +11 -0
  57. pylgen_core-0.5.4/pylgen/parser/lalr_parser.pyi +35 -0
  58. pylgen_core-0.5.4/pylgen/parser/lalr_parser.pyx +99 -0
  59. pylgen_core-0.5.4/pylgen/parser/lr0_parser.c +13834 -0
  60. pylgen_core-0.5.4/pylgen/parser/lr0_parser.pxd +14 -0
  61. pylgen_core-0.5.4/pylgen/parser/lr0_parser.pyi +44 -0
  62. pylgen_core-0.5.4/pylgen/parser/lr0_parser.pyx +110 -0
  63. pylgen_core-0.5.4/pylgen/parser/parser.c +21455 -0
  64. pylgen_core-0.5.4/pylgen/parser/parser.pxd +48 -0
  65. pylgen_core-0.5.4/pylgen/parser/parser.pyi +47 -0
  66. pylgen_core-0.5.4/pylgen/parser/parser.pyx +348 -0
  67. pylgen_core-0.5.4/pylgen/parser/parser_builder.c +26850 -0
  68. pylgen_core-0.5.4/pylgen/parser/parser_builder.pxd +39 -0
  69. pylgen_core-0.5.4/pylgen/parser/parser_builder.pyi +85 -0
  70. pylgen_core-0.5.4/pylgen/parser/parser_builder.pyx +660 -0
  71. pylgen_core-0.5.4/pylgen/parser/parser_type.py +6 -0
  72. pylgen_core-0.5.4/pylgen/regex/__init__.py +1 -0
  73. pylgen_core-0.5.4/pylgen/regex/engine.c +24141 -0
  74. pylgen_core-0.5.4/pylgen/regex/engine.pxd +21 -0
  75. pylgen_core-0.5.4/pylgen/regex/engine.pyi +31 -0
  76. pylgen_core-0.5.4/pylgen/regex/engine.pyx +647 -0
  77. pylgen_core-0.5.4/pylgen/regex/enums.py +9 -0
  78. pylgen_core-0.5.4/pylgen/regex/regex_parser.c +53060 -0
  79. pylgen_core-0.5.4/pylgen/regex/regex_parser.pxd +82 -0
  80. pylgen_core-0.5.4/pylgen/regex/regex_parser.pyx +904 -0
  81. pylgen_core-0.5.4/pylgen/visual/__init__.py +806 -0
  82. pylgen_core-0.5.4/pylgen/visual/table.py +202 -0
  83. pylgen_core-0.5.4/pylgen_core.egg-info/PKG-INFO +194 -0
  84. pylgen_core-0.5.4/pylgen_core.egg-info/SOURCES.txt +107 -0
  85. pylgen_core-0.5.4/pylgen_core.egg-info/dependency_links.txt +1 -0
  86. pylgen_core-0.5.4/pylgen_core.egg-info/not-zip-safe +1 -0
  87. pylgen_core-0.5.4/pylgen_core.egg-info/requires.txt +38 -0
  88. pylgen_core-0.5.4/pylgen_core.egg-info/top_level.txt +1 -0
  89. pylgen_core-0.5.4/pyproject.toml +90 -0
  90. pylgen_core-0.5.4/readme.md +104 -0
  91. pylgen_core-0.5.4/setup.cfg +11 -0
  92. pylgen_core-0.5.4/setup.py +157 -0
@@ -0,0 +1,30 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, YonyUk
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ "IMPORTANT: The source code generated by (or with) this tool (i.e., the lexer, parser, AST classes, and evaluation/codegen methods produced from the user's specification) is NOT considered a derivative work of this repository. The user retains all copyright, intellectual property, and license choice rights over the generated code. This license (BSD 3-Clause) applies ONLY to the PyLGEN's source code and its supporting files, not to the output produced by it."
@@ -0,0 +1,9 @@
1
+ include *.pyx *.c *.py *.pxd
2
+ recursive-include pylgen/common *.c *.pyx *.py *.pxd
3
+ recursive-include pylgen/automaton *.c *.pyx *.py *.pxd
4
+ recursive-include pylgen/grammar *.c *.pyx *.py *.pxd
5
+ recursive-include pylgen/regex *.c *.pyx *.py *.pxd
6
+ recursive-include pylgen/parser *.c *.pyx *.py *.pxd
7
+ recursive-include pylgen/lexer *.c *.pyx *.py *.pxd
8
+ recursive-include pylgen/analysis *.c *.pyx *.py *.pxd
9
+ include requirements.txt
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: pylgen-core
3
+ Version: 0.5.4
4
+ Summary: From prototype to production: a Python-native compiler framework that brings the Dragon Book to life in Python, with clarity throughout.
5
+ Author-email: YonyUk <yonatanjoseguerraperez@gmail.com>
6
+ License: BSD 3-Clause License
7
+
8
+ Copyright (c) 2026, YonyUk
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ 3. Neither the name of the copyright holder nor the names of its
21
+ contributors may be used to endorse or promote products derived from
22
+ this software without specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+
35
+ "IMPORTANT: The source code generated by (or with) this tool (i.e., the lexer, parser, AST classes, and evaluation/codegen methods produced from the user's specification) is NOT considered a derivative work of this repository. The user retains all copyright, intellectual property, and license choice rights over the generated code. This license (BSD 3-Clause) applies ONLY to the PyLGEN's source code and its supporting files, not to the output produced by it."
36
+ Project-URL: Homepage, https://github.com/yonyuk/pylgen
37
+ Project-URL: Repository, https://github.com/yonyuk/pylgen
38
+ Project-URL: Bug Tracker, https://github.com/yonyuk/pylgen/issues
39
+ Project-URL: Documentation, https://pylgen.readthedocs.io/
40
+ Keywords: parser,lalr,lexer,compiler,grammar,attributed-grammar,automaton,regex,language-tool,pylgen,visualization,high-performs
41
+ Classifier: Development Status :: 4 - Beta
42
+ Classifier: Intended Audience :: Developers
43
+ Classifier: Topic :: Software Development :: Compilers
44
+ Classifier: Topic :: Text Processing :: Linguistic
45
+ Classifier: License :: OSI Approved :: BSD License
46
+ Classifier: Operating System :: OS Independent
47
+ Classifier: Programming Language :: Python :: 3
48
+ Classifier: Programming Language :: Python :: 3.11
49
+ Classifier: Programming Language :: Python :: 3.12
50
+ Classifier: Programming Language :: Python :: 3.13
51
+ Classifier: Programming Language :: Python :: 3 :: Only
52
+ Requires-Python: >=3.11
53
+ Description-Content-Type: text/markdown
54
+ License-File: LICENSE
55
+ Requires-Dist: colorama==0.4.6
56
+ Requires-Dist: decorator==5.2.1
57
+ Requires-Dist: Jinja2==3.1.6
58
+ Requires-Dist: jsonpickle==4.1.1
59
+ Requires-Dist: packaging==26.2
60
+ Requires-Dist: pyparsing==3.3.2
61
+ Requires-Dist: PyYAML==6.0.3
62
+ Provides-Extra: visual
63
+ Requires-Dist: matplotlib==3.10.9; extra == "visual"
64
+ Requires-Dist: networkx==3.6.1; extra == "visual"
65
+ Requires-Dist: pyvis==0.3.2; extra == "visual"
66
+ Provides-Extra: cython
67
+ Requires-Dist: build==1.5.0; extra == "cython"
68
+ Requires-Dist: Cython==3.2.4; extra == "cython"
69
+ Requires-Dist: setuptools==82.0.1; extra == "cython"
70
+ Requires-Dist: wheel==0.47.0; extra == "cython"
71
+ Provides-Extra: test
72
+ Requires-Dist: pytest==9.0.3; extra == "test"
73
+ Provides-Extra: all
74
+ Requires-Dist: colorama==0.4.6; extra == "all"
75
+ Requires-Dist: decorator==5.2.1; extra == "all"
76
+ Requires-Dist: Jinja2==3.1.6; extra == "all"
77
+ Requires-Dist: jsonpickle==4.1.1; extra == "all"
78
+ Requires-Dist: packaging==26.2; extra == "all"
79
+ Requires-Dist: pyparsing==3.3.2; extra == "all"
80
+ Requires-Dist: PyYAML==6.0.3; extra == "all"
81
+ Requires-Dist: matplotlib==3.10.9; extra == "all"
82
+ Requires-Dist: networkx==3.6.1; extra == "all"
83
+ Requires-Dist: pyvis==0.3.2; extra == "all"
84
+ Requires-Dist: build==1.5.0; extra == "all"
85
+ Requires-Dist: Cython==3.2.4; extra == "all"
86
+ Requires-Dist: setuptools==82.0.1; extra == "all"
87
+ Requires-Dist: wheel==0.47.0; extra == "all"
88
+ Requires-Dist: pytest==9.0.3; extra == "all"
89
+ Dynamic: license-file
90
+
91
+ # PyLGEN
92
+ ![PyPI - 0.3.5](https://img.shields.io/pypi/v/pylgen)
93
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/yonyuk/pylgen/ci.yml)
94
+ ![PyPI - 3.8](https://img.shields.io/pypi/pyversions/pylgen)
95
+ ![PyPI - LICENSE](https://img.shields.io/pypi/l/pylgen)
96
+
97
+ ![Codecov](https://img.shields.io/codecov/c/github/yonyuk/pylgen)
98
+
99
+ *From prototype to production: a **Python-native compiler framework** that brings the "**Dragon Book**" to life in Python, with clarity throughout.*
100
+
101
+ PyLGEN gives you **complete control** over every stage of language processing. Build interpreters and compilers from scratch without leaving the Python ecosystem. Prototype rapidly in pure Python, then compile to native speed with Cython for production workloads.
102
+
103
+ > [!note]
104
+ > **Cython compilation** requires a **C** compiler installed on system to compile the code
105
+
106
+ ## Why PyLGEN?
107
+
108
+ - **Full pipeline control**: You own every step: lexer, parser, AST, semantic analysis, and evaluation.
109
+
110
+ - **Dual‑nature design**: Pure Python for development and debugging; Cython for near‑C performance.
111
+
112
+ - **Built for scale**: Handles 2‑million‑line inputs with ~2.5x faster parsing than Lark + `lark_cython`.
113
+
114
+ - **Python ecosystem integration**: Leverage NumPy, SciPy, or any library from within your language.
115
+
116
+ ## 📊 Benchmark at a Glance
117
+
118
+ | | **Lark + `lark_cython`** | **PyLGEN** |
119
+ | :---: | :---: | :---: |
120
+ | **Parsing (2M lines, 40 MB)** | 151.9 s | 61.1 s |
121
+ | **AST Construction** | Separate pass | Integrated |
122
+ | **Full Interpreter** | — | ~65 s (incl. semantic checks + eval) |
123
+ | **Peak Memory** | ~4 GB | ~887 MB |
124
+
125
+ > PyLGEN is **not just a parser**, it's a complete, production‑ready interpreter framework that outperforms industry‑standard tools.
126
+
127
+ ## :rocket: Minimal Example
128
+
129
+ ```python
130
+ from pylgen.lexer import Lexer
131
+ from pylgen.grammar import AttributedGrammar
132
+ from pylgen.parser import ParserBuilder, ParserType
133
+
134
+ # 1. Define tokens & lexer
135
+ lexer = Lexer(mapping_function, r'\s+')
136
+ lexer[0, 'NUMBER'] = r'\d+'
137
+ lexer[1, 'PLUS'] = r'\+'
138
+
139
+ # 2. Define grammar with AST builders
140
+ G = AttributedGrammar(start=Symbol('E'))
141
+ G[E] += (E, plus, T), binary_reductor
142
+ G[E] += (T,), single_reductor
143
+
144
+ # 3. Build the parser
145
+ parser = ParserBuilder.build_parser_from_attributed(G, ParserType.LALR1)
146
+
147
+ # 4. Parse, analyse, execute
148
+ ast = parser.parse(lexer.tokens)
149
+ # ... your semantic visitors & evaluator ...
150
+ ```
151
+
152
+ ## 🧩 Architecture
153
+
154
+ ```mermaid
155
+ flowchart LR
156
+ Source["Source Code"] --> Lexer["Lexer"]
157
+ Lexer --> Parser["Parser LALR(1)"]
158
+ Parser --> AST["AST"]
159
+ AST --> Visitors["Visitors"]
160
+ Visitors --> Result["Result / Errors"]
161
+ ```
162
+
163
+ | **`Module`** | **Purpose** |
164
+ | :---: | :---: |
165
+ | **`common`** | Core types: `Symbol`, `AST`, `Token`, `ASTListView` |
166
+ | **`automaton`** | Finite automata(`DFA`/`NFA`), determinization, **Hopcroft minimisation** |
167
+ | **`regex`** | **Full regex engine** -> **automata conversion** |
168
+ | **`lexer`** | **Regex‑based tokenisation** with priority and validation |
169
+ | **`grammar`** | **CFG and attributed grammar** with reducers |
170
+ | **`parser`** | **LALR(1) parser generation** and runtime |
171
+ | **`analysis`** | **Visitor pattern**, **traversal strategies**, **context management** |
172
+ | **`visual`** | Interactive **HTML visualisation** of ASTs, parse trees, automata and parsing tables |
173
+
174
+ > **All modules are fully usable from Python and Cython**, prototype in Python, ship in C.
175
+
176
+ # ⚡ Quick Start
177
+
178
+ ```bash
179
+ pip install pylgen
180
+ ```
181
+
182
+ Then build your interpreter step by step, following the complete tutorial in the [documentation](https://pylgen.readthedocs.io/en/latest/section-1/example-1-first-approach/).
183
+
184
+ ## 📖 Learn More
185
+
186
+ - **Step‑by‑step tutorial**: Build a **full arithmetic REPL** from scratch.
187
+
188
+ - **VecLang case study**: Production‑grade language with vectors, functions, and slicing.
189
+
190
+ - **Deep‑dive API tour**: Understand every module inside out.
191
+
192
+ [Read the full documentation →](https://pylgen.readthedocs.io)
193
+
194
+ **PyLGEN**: Where compiler theory meets Python pragmatism.
File without changes
@@ -0,0 +1,5 @@
1
+ from .error_type import ErrorType
2
+ from .error import Error,LexicalError,SemanticError,SyntaxError,RuntimeError
3
+ from .lexical import LexicalRule
4
+ from .visitor import ASTChildrenSelector,ASTVisitor,ASTWalker
5
+ from .context import Context