syncraft 0.1.14__tar.gz → 0.1.15__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.

Potentially problematic release.


This version of syncraft might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncraft
3
- Version: 0.1.14
3
+ Version: 0.1.15
4
4
  Summary: Parser combinator library
5
5
  Author-email: Michael Afmokt <michael@esacca.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "syncraft"
3
- version = "0.1.14"
3
+ version = "0.1.15"
4
4
  description = "Parser combinator library"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncraft
3
- Version: 0.1.14
3
+ Version: 0.1.15
4
4
  Summary: Parser combinator library
5
5
  Author-email: Michael Afmokt <michael@esacca.com>
6
6
  License-Expression: MIT
@@ -16,5 +16,6 @@ syncraft.egg-info/SOURCES.txt
16
16
  syncraft.egg-info/dependency_links.txt
17
17
  syncraft.egg-info/requires.txt
18
18
  syncraft.egg-info/top_level.txt
19
+ tests/test_bimap.py
19
20
  tests/test_parse.py
20
21
  tests/test_until.py
@@ -0,0 +1,88 @@
1
+ from __future__ import annotations
2
+ from syncraft.parser import literal, variable, parse, Parser
3
+ from syncraft.ast import AST
4
+ import syncraft.generator as gen
5
+ from typing import Any
6
+ from rich import print
7
+
8
+
9
+ def test1_simple_then() -> None:
10
+ A, B, C = literal("a"), literal("b"), literal("c")
11
+ syntax = A // B // C
12
+ sql = "a b c"
13
+ ast = parse(syntax(Parser), sql, dialect="sqlite")
14
+ print("---" * 40)
15
+ print(ast)
16
+ generated = gen.generate(syntax(gen.Generator), ast)
17
+ print("---" * 40)
18
+ print(generated)
19
+ assert ast == generated
20
+ value, bmap = generated.bimap(None)
21
+ print(value)
22
+ assert bmap(value) == generated
23
+
24
+
25
+ def test2_named_results() -> None:
26
+ A, B = literal("a").bind("x").bind('z'), literal("b").bind("y")
27
+ syntax = A // B
28
+ sql = "a b"
29
+ ast = parse(syntax(Parser), sql, dialect="sqlite")
30
+ print("---" * 40)
31
+ print(ast)
32
+ generated = gen.generate(syntax(gen.Generator), ast)
33
+ print("---" * 40)
34
+ print(generated)
35
+ assert ast == generated
36
+ value, bmap = generated.bimap(None)
37
+ print(value)
38
+ print(bmap(value))
39
+ assert bmap(value) == generated
40
+
41
+
42
+ def test3_many_literals() -> None:
43
+ A = literal("a")
44
+ syntax = A.many()
45
+ sql = "a a a"
46
+ ast = parse(syntax(Parser), sql, dialect="sqlite")
47
+ print("---" * 40)
48
+ print(ast)
49
+ generated = gen.generate(syntax(gen.Generator), ast)
50
+ print("---" * 40)
51
+ print(generated)
52
+ assert ast == generated
53
+ value, bmap = generated.bimap(None)
54
+ print(value)
55
+ assert bmap(value) == generated
56
+
57
+
58
+ def test4_mixed_many_named() -> None:
59
+ A = literal("a").bind("x")
60
+ B = literal("b")
61
+ syntax = (A | B).many()
62
+ sql = "a b a"
63
+ ast = parse(syntax(Parser), sql, dialect="sqlite")
64
+ print("---" * 40)
65
+ print(ast)
66
+ generated = gen.generate(syntax(gen.Generator), ast)
67
+ print("---" * 40)
68
+ print(generated)
69
+ assert ast == generated
70
+ value, bmap = generated.bimap(None)
71
+ print(value)
72
+ assert bmap(value) == generated
73
+
74
+
75
+ def test5_nested_then_many() -> None:
76
+ IF, THEN, END = literal("if"), literal("then"), literal("end")
77
+ syntax = (IF.many() // THEN.many()).many() // END
78
+ sql = "if if then end"
79
+ ast = parse(syntax(Parser), sql, dialect="sqlite")
80
+ print("---" * 40)
81
+ print(ast)
82
+ generated = gen.generate(syntax(gen.Generator), ast)
83
+ print("---" * 40)
84
+ print(generated)
85
+ # assert ast == generated
86
+ value, bmap = generated.bimap(None)
87
+ print(value)
88
+ assert bmap(value) == generated
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes