syncraft 0.1.15__py3-none-any.whl → 0.1.17__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/ast.py +2 -0
- syncraft/generator.py +29 -19
- {syncraft-0.1.15.dist-info → syncraft-0.1.17.dist-info}/METADATA +1 -1
- {syncraft-0.1.15.dist-info → syncraft-0.1.17.dist-info}/RECORD +8 -8
- {syncraft-0.1.15.dist-info → syncraft-0.1.17.dist-info}/WHEEL +0 -0
- {syncraft-0.1.15.dist-info → syncraft-0.1.17.dist-info}/licenses/LICENSE +0 -0
- {syncraft-0.1.15.dist-info → syncraft-0.1.17.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/ast.py
CHANGED
syncraft/generator.py
CHANGED
|
@@ -111,6 +111,7 @@ def token_type_from_string(token_type: Optional[TokenType], text: str, case_sens
|
|
|
111
111
|
|
|
112
112
|
@dataclass(frozen=True)
|
|
113
113
|
class TokenGen(TokenSpec):
|
|
114
|
+
|
|
114
115
|
def __str__(self) -> str:
|
|
115
116
|
tt = self.token_type.name if self.token_type else ""
|
|
116
117
|
txt = self.text if self.text else ""
|
|
@@ -141,30 +142,39 @@ class TokenGen(TokenSpec):
|
|
|
141
142
|
self.case_sensitive),
|
|
142
143
|
text=text)
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
@staticmethod
|
|
146
|
+
def from_string(string: str)->Token:
|
|
147
|
+
return Token(token_type=token_type_from_string(None, string, case_sensitive=False), text=string)
|
|
145
148
|
|
|
146
149
|
|
|
147
150
|
@dataclass(frozen=True)
|
|
148
151
|
class Generator(Algebra[GenResult[T], GenState[T]]):
|
|
149
152
|
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
|
-
|
|
153
|
+
def flat_map_run(original: GenState[T], use_cache:bool) -> Either[Any, Tuple[B, GenState[T]]]:
|
|
154
|
+
wrapper = original.wrapper()
|
|
155
|
+
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
|
|
156
|
+
try:
|
|
157
|
+
lft = input.left()
|
|
158
|
+
match self.run(lft, use_cache=use_cache):
|
|
159
|
+
case Left(error):
|
|
160
|
+
return Left(error)
|
|
161
|
+
case Right((value, next_input)):
|
|
162
|
+
r = input.right()
|
|
163
|
+
match f(value).run(r, use_cache):
|
|
164
|
+
case Left(e):
|
|
165
|
+
return Left(e)
|
|
166
|
+
case Right((result, next_input)):
|
|
167
|
+
return Right((wrapper(result), next_input))
|
|
168
|
+
raise ValueError("flat_map should always return a value or an error.")
|
|
169
|
+
except Exception as e:
|
|
170
|
+
return Left(Error(
|
|
171
|
+
message=str(e),
|
|
172
|
+
this=self,
|
|
173
|
+
state=original,
|
|
174
|
+
error=e
|
|
175
|
+
))
|
|
176
|
+
return Generator(run_f = flat_map_run, name=self.name) # type: ignore
|
|
177
|
+
|
|
168
178
|
|
|
169
179
|
def many(self, *, at_least: int, at_most: Optional[int]) -> Algebra[ManyResult[GenResult[T]], GenState[T]]:
|
|
170
180
|
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=
|
|
3
|
-
syncraft/ast.py,sha256=
|
|
2
|
+
syncraft/algebra.py,sha256=l_ptzSkXbRGSLzu46GXixcNQPdXAi1s5R9nRDI86JkY,22785
|
|
3
|
+
syncraft/ast.py,sha256=9CuHqXRiw_7UMDLd4x2def3kHgTVQ0hnPxyIbBlx1Zc,4640
|
|
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=FpKfRPYvA0Wu-eKy7GUj_Xahz3e58sD0fZ3bXoTVIzY,11432
|
|
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.17.dist-info/licenses/LICENSE,sha256=wHSV424U5csa3339dy1AZbsz2xsd0hrkMx2QK48CcUk,1062
|
|
12
|
+
syncraft-0.1.17.dist-info/METADATA,sha256=U93n9WX9x0HqZO_8MlShfzahjAnCIi7tq8B3wkC9AVM,946
|
|
13
|
+
syncraft-0.1.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
syncraft-0.1.17.dist-info/top_level.txt,sha256=Kq3t8ESXB2xW1Xt3uPmkENFc-c4f2pamNmaURBk7zc8,9
|
|
15
|
+
syncraft-0.1.17.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|