From ba78e774518c530c00eaa4a3b91a5dbe8a860e6e Mon Sep 17 00:00:00 2001 From: David Hagen Date: Wed, 16 Oct 2024 22:03:27 -0400 Subject: [PATCH] Change ConversionParser.__repr__ to include converter --- src/parsita/parsers/_conversion.py | 2 +- tests/test_basic.py | 4 ++-- tests/test_regex.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/parsita/parsers/_conversion.py b/src/parsita/parsers/_conversion.py index 42503b1..d3ee8b2 100644 --- a/src/parsita/parsers/_conversion.py +++ b/src/parsita/parsers/_conversion.py @@ -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]): diff --git a/tests/test_basic.py b/tests/test_basic.py index 041f7a8..80d2edb 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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 > " + assert str(TestParsers.twentyone) == "twentyone = two & one > make_twentyone" def test_recursion(): diff --git a/tests/test_regex.py b/tests/test_regex.py index 3aada29..a3d8274 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -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(): @@ -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(): @@ -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(): @@ -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"