Skip to content

Commit

Permalink
Change ConversionParser.__repr__ to include converter
Browse files Browse the repository at this point in the history
  • Loading branch information
drhagen committed Oct 17, 2024
1 parent 65e7db3 commit 8448aa6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/parsita/parsers/_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _consume(
return None

def __repr__(self):
return self.name_or_nothing() + repr(self.parser)
return self.name_or_nothing() + f"{self.parser!r} > {self.converter.__name__}"


class TransformationParser(Generic[Input, Output, Convert], Parser[Input, Convert]):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def make_twentyone(x):
assert TestParsers.one.parse("1") == Success(1)
assert TestParsers.twelve.parse("12") == Success(12)
assert TestParsers.twentyone.parse("21") == Success(21)
assert str(TestParsers.twelve) == "twelve = one & two"
assert str(TestParsers.twentyone) == "twentyone = two & one"
assert str(TestParsers.twelve) == "twelve = one & two > <lambda>"
assert str(TestParsers.twentyone) == "twentyone = two & one > make_twentyone"


def test_recursion():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestParsers(ParserContext, whitespace="[ ]*"):
assert TestParsers.hundred.parse(" 100") == Success(100)
assert TestParsers.hundred.parse("100 ") == Success(100)
assert TestParsers.hundred.parse(" 100 ") == Success(100)
assert str(TestParsers.hundred) == "hundred = '100'"
assert str(TestParsers.hundred) == "hundred = '100' > float"


def test_literal_no_whitespace():
Expand All @@ -48,7 +48,7 @@ class TestParsers(ParserContext):
assert TestParsers.hundred.parse("100 ") == Failure(
ParseError(StringReader("100 ", 3), ["end of source"])
)
assert str(TestParsers.hundred) == "hundred = '100'"
assert str(TestParsers.hundred) == "hundred = '100' > float"


def test_literal_multiple():
Expand Down Expand Up @@ -122,7 +122,7 @@ class TestParsers(ParserContext):
assert TestParsers.digits.parse("100 ") == Failure(
ParseError(StringReader("100 ", 3), ["end of source"])
)
assert str(TestParsers.digits) == r"digits = reg(r'\d+')"
assert str(TestParsers.digits) == r"digits = reg(r'\d+') > float"


def test_regex_custom_whitespace():
Expand All @@ -142,7 +142,7 @@ class TestParsers(ParserContext, whitespace="[ ]*"):
assert TestParsers.pair.parse("100\n100") == Failure(
ParseError(StringReader("100\n100", 3), [r"r'\d+'"])
)
assert str(TestParsers.digits) == r"digits = reg(r'\d+')"
assert str(TestParsers.digits) == r"digits = reg(r'\d+') > float"
assert str(TestParsers.pair) == "pair = digits & digits"


Expand Down

0 comments on commit 8448aa6

Please sign in to comment.