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.

Files changed (32) hide show
  1. {syncraft-0.2.8/syncraft.egg-info → syncraft-0.2.9}/PKG-INFO +1 -1
  2. {syncraft-0.2.8 → syncraft-0.2.9}/pyproject.toml +1 -1
  3. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/ast.py +1 -1
  4. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/cache.py +2 -2
  5. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/walker.py +27 -23
  6. {syncraft-0.2.8 → syncraft-0.2.9/syncraft.egg-info}/PKG-INFO +1 -1
  7. {syncraft-0.2.8 → syncraft-0.2.9}/LICENSE +0 -0
  8. {syncraft-0.2.8 → syncraft-0.2.9}/README.md +0 -0
  9. {syncraft-0.2.8 → syncraft-0.2.9}/setup.cfg +0 -0
  10. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/__init__.py +0 -0
  11. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/algebra.py +0 -0
  12. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/constraint.py +0 -0
  13. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/dev.py +0 -0
  14. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/finder.py +0 -0
  15. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/generator.py +0 -0
  16. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/lexer.py +0 -0
  17. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/parser.py +0 -0
  18. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/py.typed +0 -0
  19. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/sqlite3.py +0 -0
  20. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/syntax.py +0 -0
  21. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft/utils.py +0 -0
  22. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/SOURCES.txt +0 -0
  23. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/dependency_links.txt +0 -0
  24. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/requires.txt +0 -0
  25. {syncraft-0.2.8 → syncraft-0.2.9}/syncraft.egg-info/top_level.txt +0 -0
  26. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_bimap.py +0 -0
  27. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_constraint.py +0 -0
  28. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_find.py +0 -0
  29. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_lazy.py +0 -0
  30. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_parse.py +0 -0
  31. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_to.py +0 -0
  32. {syncraft-0.2.8 → syncraft-0.2.9}/tests/test_walk.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncraft
3
- Version: 0.2.8
3
+ Version: 0.2.9
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.2.8"
3
+ version = "0.2.9"
4
4
  description = "Parser combinator library"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -488,7 +488,7 @@ class ChoiceSpec(SyntaxSpec, Generic[A, B]):
488
488
 
489
489
  @dataclass(frozen=True)
490
490
  class LazySpec(SyntaxSpec, Generic[A]):
491
- value: A
491
+ value: None | A
492
492
  @dataclass(frozen=True)
493
493
  class ThenSpec(SyntaxSpec, Generic[A, B]):
494
494
  kind: ThenKind
@@ -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 parser", offending=f, state=args)
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 parser", offending=f, state=args)
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
- thunk_result = yield from alg.run(input, use_cache)
83
- match thunk_result:
84
- case Right((value, from_thunk)):
85
- data = LazySpec(value=value)
86
- return Right((data, from_thunk.reduce(data)))
87
- raise SyncraftError("flat_map should always return a value or an error.", offending=thunk_result, expect=(Left, Right))
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)-> Tuple[Any, None | 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, alg=Walker, use_cache=False, reducer=reducer, init=init)
143
- return v, s
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncraft
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: Parser combinator library
5
5
  Author-email: Michael Afmokt <michael@esacca.com>
6
6
  License-Expression: MIT
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