syncraft 0.1.11__tar.gz → 0.1.12__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.11
3
+ Version: 0.1.12
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.11"
3
+ version = "0.1.12"
4
4
  description = "Parser combinator library"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -142,7 +142,8 @@ class TokenGen(TokenSpec):
142
142
  class Generator(Algebra[GenResult[T], GenState[T]]):
143
143
  def flat_map(self, f: Callable[[GenResult[T]], Algebra[B, GenState[T]]]) -> Algebra[B, GenState[T]]:
144
144
  def flat_map_run(input: GenState[T], use_cache:bool) -> Either[Any, Tuple[B, GenState[T]]]:
145
- match self.run(input.left(), use_cache=use_cache):
145
+ lft = input.left()
146
+ match self.run(lft, use_cache=use_cache):
146
147
  case Left(error):
147
148
  return Left(error)
148
149
  case Right((value, next_input)):
@@ -175,8 +176,20 @@ class Generator(Algebra[GenResult[T], GenState[T]]):
175
176
  match self.run(input.down(index), use_cache):
176
177
  case Right((value, next_input)):
177
178
  ret.append(value)
179
+ if at_most is not None and len(ret) > at_most:
180
+ return Left(Error(
181
+ message=f"Expected at most {at_most} matches, got {len(ret)}",
182
+ this=self,
183
+ state=input.down(index)
184
+ ))
178
185
  case Left(_):
179
186
  pass
187
+ if len(ret) < at_least:
188
+ return Left(Error(
189
+ message=f"Expected at least {at_least} matches, got {len(ret)}",
190
+ this=self,
191
+ state=input.down(index)
192
+ ))
180
193
  return Right((ManyResult(tuple(ret)), input))
181
194
  return self.__class__(many_run, name=f"many({self.name})") # type: ignore
182
195
 
@@ -203,7 +216,7 @@ class Generator(Algebra[GenResult[T], GenState[T]]):
203
216
  case Left(error):
204
217
  return Left(error)
205
218
  raise ValueError("or_else should always return a value or an error.")
206
- return self.__class__(or_else_run, name=f"free_or({self.name} | {other.name})") # type: ignore
219
+ return self.__class__(or_else_run, name=f"or_else({self.name} | {other.name})") # type: ignore
207
220
 
208
221
  @classmethod
209
222
  def token(cls,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: syncraft
3
- Version: 0.1.11
3
+ Version: 0.1.12
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