Skip to content

Commit

Permalink
Revert "Make concat also work on lists of bytes."
Browse files Browse the repository at this point in the history
This reverts commit a0c5d9a.
  • Loading branch information
spookylukey committed May 2, 2024
1 parent 9b85007 commit 7217c76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
19 changes: 3 additions & 16 deletions src/parsy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,10 @@ def combine_dict(self, combine_fn: Callable) -> Parser:

def concat(self) -> Parser:
"""
Returns a parser that concatenates together the previously produced values.
This parser will join the values using the type of the input stream, so
when feeding bytes to the parser, the items to be joined must also be bytes.
Returns a parser that concatenates together (as a string) the previously
produced values.
"""

@Parser
def parser(stream: bytes | str, index: int) -> Result:
joiner = type(stream)()
result = self(stream, index)
if result.status:
next_parser: Parser = success(joiner.join(result.value))
return next_parser(stream, result.index).aggregate(result)
else:
return result

return parser
return self.map("".join)

def then(self, other: Parser) -> Parser:
"""
Expand Down
7 changes: 1 addition & 6 deletions tests/test_parsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,11 @@ def test_combine_dict_skip_underscores(self):
).combine_dict(Pair)
self.assertEqual(parser.parse("ABC 123"), Pair(word="ABC", number=123))

def test_concat_str(self):
def test_concat(self):
parser = letter.many().concat()
self.assertEqual(parser.parse(""), "")
self.assertEqual(parser.parse("abc"), "abc")

def test_concat_bytes(self):
parser = any_char.many().concat()
self.assertEqual(parser.parse(b""), b"")
self.assertEqual(parser.parse(b"abc"), b"abc")

def test_generate(self):
x = y = None

Expand Down

0 comments on commit 7217c76

Please sign in to comment.