syncraft 0.2.2__py3-none-any.whl → 0.2.4__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.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: syncraft
3
+ Version: 0.2.4
4
+ Summary: Parser combinator library
5
+ Author-email: Michael Afmokt <michael@esacca.com>
6
+ License-Expression: MIT
7
+ Keywords: parser,combinator,sql,sqlite,generator,printer
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: rich>=14.1.0
12
+ Requires-Dist: rstr>=3.2.2
13
+ Requires-Dist: sqlglot>=27.7.0
14
+ Dynamic: license-file
15
+
16
+ # Syncraft
17
+
18
+ Syncraft is a parser/generator combinator library for Python. It helps you
19
+
20
+ - Build grammars
21
+ - Parse SQL statement to AST
22
+ - Search AST by grammar
23
+ - Convert AST to dataclass
24
+ - Check constraints over the AST/dataclass
25
+ - Change dataclass and convert back to AST
26
+
27
+
28
+ ## Installation
29
+
30
+ ### pip
31
+ ```bash
32
+ pip install syncraft
33
+ ```
34
+
35
+ ### uv
36
+ ```bash
37
+ uv add syncraft
38
+ ```
39
+
40
+ Python 3.10+ is required.
41
+
42
+ ## Quickstart
43
+
44
+ !. Define grammar
45
+
46
+ ```python
47
+ from dataclasses import dataclass
48
+ from syncraft import literal, parse, generate
49
+
50
+ A = literal("a")
51
+ B = literal("b")
52
+ syntax = A + B # sequence
53
+
54
+ ast, _ = parse(syntax, "a b", dialect="sqlite")
55
+ gen, _ = generate(syntax, ast)
56
+ assert ast == gen
57
+ ```
58
+
59
+ Collect parsed pieces into dataclasses using marks and `.to()`:
60
+
61
+ ```python
62
+ from dataclasses import dataclass
63
+ from syncraft import literal
64
+
65
+ @dataclass
66
+ class Pair:
67
+ first: any
68
+ second: any
69
+
70
+ A = literal("a").mark("first")
71
+ B = literal("b").mark("second")
72
+ syntax = (A + B).to(Pair)
73
+
74
+ ast, _ = parse(syntax, "a b", dialect="sqlite")
75
+ value, invert = ast.bimap()
76
+ # value is Pair(first=VAR(a), second=VAR(b))
77
+ round_tripped, _ = generate(syntax, invert(value))
78
+ assert round_tripped == ast
79
+ ```
80
+
81
+ Use the built‑in SQLite grammar snippets to parse statements:
82
+
83
+ ```python
84
+ from syncraft import parse
85
+ from syncraft.sqlite3 import select_stmt
86
+
87
+ ast, _ = parse(select_stmt, "select a from t where a > 1", dialect="sqlite")
88
+ ```
89
+
90
+ ## Core ideas
91
+
92
+ - Syntax describes structure and transforms values; Algebra executes it.
93
+ - AST types: Then, Choice, Many, Marked, Collect, Nothing, Token.
94
+ - Operators: `+` (both), `>>` (keep right), `//` (keep left), `|` (choice), `~` (optional), `many()`, `sep_by()`, `between()`.
95
+ - Error model supports backtracking and commit (`cut()`).
96
+
97
+ ## Documentation
98
+
99
+ - Tutorials and API reference are built with MkDocs. Local preview:
100
+ 1) install dev deps (see `pyproject.toml` dev group)
101
+ 2) activate your venv and run `mkdocs serve`
102
+
103
+ - Version injection: pages can use `{{ version }}`. It is provided by mkdocs-macros via `docs/main.py`, which resolves the version in this order:
104
+ - `[project].version` from `pyproject.toml`
105
+ - installed package metadata (`importlib.metadata.version('syncraft')`)
106
+ - fallback `"0.0.0"`
107
+
108
+ The macros plugin is configured in `mkdocs.yml` with `module_name: docs/main`.
109
+
110
+ ## Contributing / Roadmap
111
+
112
+ - Improve performance and add benchmarks
113
+ - Expand tutorials and SQLite coverage examples
@@ -0,0 +1,16 @@
1
+ syncraft/__init__.py,sha256=8LIO0m0XEAsgKd--G8u6uT-lljLDtKMeIequNRNv2dc,894
2
+ syncraft/algebra.py,sha256=zm6HzaE2XeyhWInoKDSJrVtnkjJV6BsD0zPBRz7iDAI,23333
3
+ syncraft/ast.py,sha256=F6aRdxZ6IBNvnk1xe_ugEBvL-BXNXdkN4s1YDIuNw3Y,19134
4
+ syncraft/constraint.py,sha256=vJ61XwjIENpji4HxoBaNA3kqKI8oCFVwb6pNJs4Fvek,9298
5
+ syncraft/diagnostic.py,sha256=cgwcQnCcgrCRX3h-oGTDb5rcJAtitPV3LfH9eLvO93E,2837
6
+ syncraft/finder.py,sha256=FCOHGdJf2NHG_letl8-IArfBywEolmtZcTJQPOj1iYw,4147
7
+ syncraft/generator.py,sha256=biTX66WzZIxKdWbkQMIj3QZzKQkRTdBeDF6oUROwp-Y,19638
8
+ syncraft/parser.py,sha256=9z9Iq9_Ih3mlXkuz85gsND4xshZARgAqo5-R_DpgA9I,17338
9
+ syncraft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ syncraft/sqlite3.py,sha256=Pq09IHZOwuWg5W82l9D1flzd36QV0TOHQpTJ5U02V8g,34701
11
+ syncraft/syntax.py,sha256=nSWE1SHvVDYON0UQM8kgp14kx54hbKBYHV0xB6fgwkk,22366
12
+ syncraft-0.2.4.dist-info/licenses/LICENSE,sha256=wHSV424U5csa3339dy1AZbsz2xsd0hrkMx2QK48CcUk,1062
13
+ syncraft-0.2.4.dist-info/METADATA,sha256=w7b7nLYTVUvWGaT88dsHkUMyq1dNUF_QHLyuUzJ4GNs,2821
14
+ syncraft-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ syncraft-0.2.4.dist-info/top_level.txt,sha256=Kq3t8ESXB2xW1Xt3uPmkENFc-c4f2pamNmaURBk7zc8,9
16
+ syncraft-0.2.4.dist-info/RECORD,,
@@ -1,34 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: syncraft
3
- Version: 0.2.2
4
- Summary: Parser combinator library
5
- Author-email: Michael Afmokt <michael@esacca.com>
6
- License-Expression: MIT
7
- Keywords: parser,combinator,sql,sqlite,generator,printer
8
- Requires-Python: >=3.10
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
- Requires-Dist: rich>=14.1.0
12
- Requires-Dist: rstr>=3.2.2
13
- Requires-Dist: sqlglot>=27.7.0
14
- Dynamic: license-file
15
-
16
- # Syncraft
17
-
18
- Syncraft is a parser/generator combinator library with full round-trip support:
19
-
20
- - Parse source code into AST or dataclasses
21
- - Generate source code from dataclasses
22
- - SQLite syntax support included
23
-
24
- ## Installation
25
-
26
- ```bash
27
- pip install syncraft
28
- ```
29
-
30
-
31
- ## TODO
32
- - [ ] define DSL over Variable to construct predicates
33
- - [ ] Try the parsing, generation, and data processing machinery on SQLite3 syntax. So that I can have direct feedback on the usability of this library and a fully functional SQLite3 library.
34
- - [ ] Make the library as fast as possible and feasible.
@@ -1,16 +0,0 @@
1
- syncraft/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- syncraft/algebra.py,sha256=2pyxbllcRsaDS_rEXfagBenZ_etSjMNdlVYxPkoU7cQ,15849
3
- syncraft/ast.py,sha256=TAHj8IOgx_QtlI4zxFr2DRGZ4dwNGsb6TiH0TH9adIg,14556
4
- syncraft/constraint.py,sha256=4HDWXgq9ZKacKBViBxIWhbRqgZNP7cZHXOSFMyGMaaA,7274
5
- syncraft/diagnostic.py,sha256=cgwcQnCcgrCRX3h-oGTDb5rcJAtitPV3LfH9eLvO93E,2837
6
- syncraft/finder.py,sha256=Wr7wiBuO9IaXBmYBA4DNXmoeEWteRIp-UetnuRScapM,1920
7
- syncraft/generator.py,sha256=sa0Uyq2azFh5kW3RVsPS7aFmtR5sfBYODa5K2Fg_Jy8,13074
8
- syncraft/parser.py,sha256=azO1P7c2QJK_XPZtrMnK6CyTHRdlQaT9rAqfyZNtUK0,11293
9
- syncraft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- syncraft/sqlite3.py,sha256=Pq09IHZOwuWg5W82l9D1flzd36QV0TOHQpTJ5U02V8g,34701
11
- syncraft/syntax.py,sha256=kKECtd-yIIho6DjG0fHYNpqNkJ9_zo01S7bOWUUT0VA,16294
12
- syncraft-0.2.2.dist-info/licenses/LICENSE,sha256=wHSV424U5csa3339dy1AZbsz2xsd0hrkMx2QK48CcUk,1062
13
- syncraft-0.2.2.dist-info/METADATA,sha256=VlHmCHpIuBIfamHJ6jPr6PbGCShaR0mcTE6foAtk8nI,988
14
- syncraft-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- syncraft-0.2.2.dist-info/top_level.txt,sha256=Kq3t8ESXB2xW1Xt3uPmkENFc-c4f2pamNmaURBk7zc8,9
16
- syncraft-0.2.2.dist-info/RECORD,,