syncraft 0.1.15__py3-none-any.whl → 0.1.16__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.
Potentially problematic release.
This version of syncraft might be problematic. Click here for more details.
- syncraft/algebra.py +1 -11
- syncraft/generator.py +25 -18
- {syncraft-0.1.15.dist-info → syncraft-0.1.16.dist-info}/METADATA +1 -1
- {syncraft-0.1.15.dist-info → syncraft-0.1.16.dist-info}/RECORD +7 -7
- {syncraft-0.1.15.dist-info → syncraft-0.1.16.dist-info}/WHEEL +0 -0
- {syncraft-0.1.15.dist-info → syncraft-0.1.16.dist-info}/licenses/LICENSE +0 -0
- {syncraft-0.1.15.dist-info → syncraft-0.1.16.dist-info}/top_level.txt +0 -0
syncraft/algebra.py
CHANGED
|
@@ -170,17 +170,7 @@ class ThenResult(Generic[A, B], StructuralResult):
|
|
|
170
170
|
right: B
|
|
171
171
|
def bimap(self, ctx: Any) -> Tuple[Any, Callable[[Any], StructuralResult]]:
|
|
172
172
|
def branch(b: Any) -> Tuple[Any, Callable[[Any], StructuralResult]]:
|
|
173
|
-
if isinstance(b,
|
|
174
|
-
value, backward = b.bimap(ctx)
|
|
175
|
-
if isinstance(value, tuple):
|
|
176
|
-
x, y = ThenResult.flat(value)
|
|
177
|
-
return x, lambda data: ThenResult(self.kind, y(data), self.right)
|
|
178
|
-
else:
|
|
179
|
-
return value, backward
|
|
180
|
-
elif isinstance(b, StructuralResult):
|
|
181
|
-
return b.bimap(ctx)
|
|
182
|
-
else:
|
|
183
|
-
return b, lambda x: x
|
|
173
|
+
return b.bimap(ctx) if isinstance(b, StructuralResult) else (b, lambda x: x)
|
|
184
174
|
match self.kind:
|
|
185
175
|
case ThenKind.BOTH:
|
|
186
176
|
left_value, left_bmap = branch(self.left)
|
syncraft/generator.py
CHANGED
|
@@ -147,24 +147,31 @@ class TokenGen(TokenSpec):
|
|
|
147
147
|
@dataclass(frozen=True)
|
|
148
148
|
class Generator(Algebra[GenResult[T], GenState[T]]):
|
|
149
149
|
def flat_map(self, f: Callable[[GenResult[T]], Algebra[B, GenState[T]]]) -> Algebra[B, GenState[T]]:
|
|
150
|
-
def flat_map_run(
|
|
151
|
-
wrapper =
|
|
152
|
-
input =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
150
|
+
def flat_map_run(original: GenState[T], use_cache:bool) -> Either[Any, Tuple[B, GenState[T]]]:
|
|
151
|
+
wrapper = original.wrapper()
|
|
152
|
+
input = original if not original.is_named else original.down(0) # If the input is named, we need to go down to the first child
|
|
153
|
+
try:
|
|
154
|
+
lft = input.left()
|
|
155
|
+
match self.run(lft, use_cache=use_cache):
|
|
156
|
+
case Left(error):
|
|
157
|
+
return Left(error)
|
|
158
|
+
case Right((value, next_input)):
|
|
159
|
+
r = input.right()
|
|
160
|
+
match f(value).run(r, use_cache):
|
|
161
|
+
case Left(e):
|
|
162
|
+
return Left(e)
|
|
163
|
+
case Right((result, next_input)):
|
|
164
|
+
return Right((wrapper(result), next_input))
|
|
165
|
+
raise ValueError("flat_map should always return a value or an error.")
|
|
166
|
+
except Exception as e:
|
|
167
|
+
return Left(Error(
|
|
168
|
+
message=str(e),
|
|
169
|
+
this=self,
|
|
170
|
+
state=original,
|
|
171
|
+
error=e
|
|
172
|
+
))
|
|
173
|
+
return Generator(run_f = flat_map_run, name=self.name) # type: ignore
|
|
174
|
+
|
|
168
175
|
|
|
169
176
|
def many(self, *, at_least: int, at_most: Optional[int]) -> Algebra[ManyResult[GenResult[T]], GenState[T]]:
|
|
170
177
|
assert at_least > 0, "at_least must be greater than 0"
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
syncraft/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
syncraft/algebra.py,sha256=
|
|
2
|
+
syncraft/algebra.py,sha256=l_ptzSkXbRGSLzu46GXixcNQPdXAi1s5R9nRDI86JkY,22785
|
|
3
3
|
syncraft/ast.py,sha256=s3BDm67IKd8WNEPszkGRgJ-SJAKewbERL0baLgfkXaQ,4634
|
|
4
4
|
syncraft/cmd.py,sha256=DzXgU8QLVOg0YTFKpmOyzbf02LKPphQ4EeKSLzqpJ_s,2012
|
|
5
5
|
syncraft/diagnostic.py,sha256=_kLbl1LlU4Y2PtsLLZFA_OLqeZqq1f2rjT_LRXLnDaI,2813
|
|
6
6
|
syncraft/dsl.py,sha256=AxAZKu6MBfaG7Wzss3UISbQsrFaigc1L-hS3p_CAXWQ,13620
|
|
7
|
-
syncraft/generator.py,sha256=
|
|
7
|
+
syncraft/generator.py,sha256=wUOe0h9Nl8EczcExcofvG2-L1lgnYEqVdn6fk9t5cjQ,11268
|
|
8
8
|
syncraft/parser.py,sha256=c1cCCW0RNw2y4XlNIUkrMf7q5lkm8wes4v5xbjLAUGg,11573
|
|
9
9
|
syncraft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
syncraft/sqlite3.py,sha256=WR4wFf2CraRkb7C5rph3wsu6sGbG_7EjEZDUsPH8xqU,34677
|
|
11
|
-
syncraft-0.1.
|
|
12
|
-
syncraft-0.1.
|
|
13
|
-
syncraft-0.1.
|
|
14
|
-
syncraft-0.1.
|
|
15
|
-
syncraft-0.1.
|
|
11
|
+
syncraft-0.1.16.dist-info/licenses/LICENSE,sha256=wHSV424U5csa3339dy1AZbsz2xsd0hrkMx2QK48CcUk,1062
|
|
12
|
+
syncraft-0.1.16.dist-info/METADATA,sha256=tSjOId_YaSbZxfoGieLiOGw-qnyQNxb_s9CoVo87tRo,946
|
|
13
|
+
syncraft-0.1.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
syncraft-0.1.16.dist-info/top_level.txt,sha256=Kq3t8ESXB2xW1Xt3uPmkENFc-c4f2pamNmaURBk7zc8,9
|
|
15
|
+
syncraft-0.1.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|