syncraft 0.2.8__tar.gz → 0.2.9__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.
- {syncraft-0.2.8/syncraft.egg-info → syncraft-0.2.9}/PKG-INFO +1 -1
- {syncraft-0.2.8 → syncraft-0.2.9}/pyproject.toml +1 -1
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/ast.py +1 -1
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/cache.py +2 -2
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/walker.py +27 -23
- {syncraft-0.2.8 → syncraft-0.2.9/syncraft.egg-info}/PKG-INFO +1 -1
- {syncraft-0.2.8 → syncraft-0.2.9}/LICENSE +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/README.md +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/setup.cfg +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/__init__.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/algebra.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/constraint.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/dev.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/finder.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/generator.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/lexer.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/parser.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/py.typed +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/sqlite3.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/syntax.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/utils.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/SOURCES.txt +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/dependency_links.txt +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/requires.txt +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/top_level.txt +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_bimap.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_constraint.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_find.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_lazy.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_parse.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_to.py +0 -0
- {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_walk.py +0 -0
|
@@ -70,7 +70,7 @@ class Cache(Generic[Ret]):
|
|
|
70
70
|
if key in c:
|
|
71
71
|
v = c[key]
|
|
72
72
|
if isinstance(v, InProgress):
|
|
73
|
-
raise RecursionError("Left-recursion detected in
|
|
73
|
+
raise RecursionError(f"Left-recursion detected in Algebra {f}", offending=f, state=args)
|
|
74
74
|
else:
|
|
75
75
|
return v
|
|
76
76
|
try:
|
|
@@ -98,7 +98,7 @@ class Cache(Generic[Ret]):
|
|
|
98
98
|
if key in c:
|
|
99
99
|
v = c[key]
|
|
100
100
|
if isinstance(v, InProgress):
|
|
101
|
-
raise RecursionError("Left-recursion detected in
|
|
101
|
+
raise RecursionError(f"Left-recursion detected in Algebra {f}", offending=f, state=args)
|
|
102
102
|
else:
|
|
103
103
|
return v
|
|
104
104
|
try:
|
|
@@ -13,7 +13,7 @@ from syncraft.constraint import Bindable, FrozenDict
|
|
|
13
13
|
|
|
14
14
|
import re
|
|
15
15
|
from syncraft.syntax import Syntax
|
|
16
|
-
from syncraft.cache import Cache
|
|
16
|
+
from syncraft.cache import Cache, RecursionError
|
|
17
17
|
from rich import print
|
|
18
18
|
|
|
19
19
|
|
|
@@ -23,17 +23,11 @@ B = TypeVar('B')
|
|
|
23
23
|
SS = TypeVar('SS', bound=Hashable)
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
26
|
@dataclass(frozen=True)
|
|
32
27
|
class WalkerState(Bindable, Generic[SS]):
|
|
33
28
|
reducer: Optional[Callable[[Any, SS], SS]] = None
|
|
34
29
|
acc: Optional[SS] = None
|
|
35
30
|
|
|
36
|
-
|
|
37
31
|
def reduce(self, value: Any) -> WalkerState[SS]:
|
|
38
32
|
if self.reducer:
|
|
39
33
|
new_acc = self.reducer(value, self.acc) if self.acc is not None else value
|
|
@@ -42,9 +36,6 @@ class WalkerState(Bindable, Generic[SS]):
|
|
|
42
36
|
return replace(self, acc=value)
|
|
43
37
|
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
39
|
@dataclass(frozen=True)
|
|
49
40
|
class Walker(Algebra[SS, WalkerState[SS]]):
|
|
50
41
|
@classmethod
|
|
@@ -75,16 +66,19 @@ class Walker(Algebra[SS, WalkerState[SS]]):
|
|
|
75
66
|
cache: Cache) -> Algebra[Any, WalkerState[SS]]:
|
|
76
67
|
def algebra_lazy_run(input: WalkerState[SS], use_cache:bool) -> PyGenerator[Incomplete[WalkerState[SS]], WalkerState[SS], Either[Any, Tuple[Any, WalkerState[SS]]]]:
|
|
77
68
|
alg = thunk()
|
|
78
|
-
print('--' * 20, "Walker.lazy.algebra_lazy_run", '--' * 20)
|
|
79
|
-
print('thunk', thunk, id(thunk))
|
|
80
|
-
print('input', input, id(input))
|
|
81
|
-
print('alg', alg, id(alg))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
# print('--' * 20, "Walker.lazy.algebra_lazy_run", '--' * 20)
|
|
70
|
+
# print('thunk', thunk, id(thunk))
|
|
71
|
+
# print('input', input, id(input))
|
|
72
|
+
# print('alg', alg, id(alg))
|
|
73
|
+
try:
|
|
74
|
+
thunk_result = yield from alg.run(input, use_cache)
|
|
75
|
+
match thunk_result:
|
|
76
|
+
case Right((value, from_thunk)):
|
|
77
|
+
data: LazySpec[Any] = LazySpec(value=value)
|
|
78
|
+
return Right((data, from_thunk.reduce(data)))
|
|
79
|
+
raise SyncraftError("flat_map should always return a value or an error.", offending=thunk_result, expect=(Left, Right))
|
|
80
|
+
except RecursionError as e:
|
|
81
|
+
return Right((LazySpec(value=None), input))
|
|
88
82
|
return cls(algebra_lazy_run, name=cls.__name__ + '.lazy', cache=cache)
|
|
89
83
|
|
|
90
84
|
|
|
@@ -137,7 +131,17 @@ class Walker(Algebra[SS, WalkerState[SS]]):
|
|
|
137
131
|
|
|
138
132
|
|
|
139
133
|
|
|
140
|
-
def walk(syntax: Syntax[Any, Any], reducer: Callable[[Any, Any], SS], init: SS
|
|
134
|
+
def walk(syntax: Syntax[Any, Any], reducer: Optional[Callable[[Any, Any], SS]] = None, init: Optional[SS] = None) -> Any:
|
|
141
135
|
from syncraft.syntax import run
|
|
142
|
-
v, s = run(syntax=syntax,
|
|
143
|
-
|
|
136
|
+
v, s = run(syntax=syntax,
|
|
137
|
+
alg=Walker,
|
|
138
|
+
use_cache=True,
|
|
139
|
+
reducer=reducer or (lambda a, s: s),
|
|
140
|
+
init=init)
|
|
141
|
+
if reducer is None:
|
|
142
|
+
return v
|
|
143
|
+
else:
|
|
144
|
+
if s is not None:
|
|
145
|
+
return s.acc
|
|
146
|
+
else:
|
|
147
|
+
return None
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|