From b8f4bdd2b80fb9b640102a369d4632eb18ebb9b6 Mon Sep 17 00:00:00 2001 From: apalala Date: Wed, 29 Nov 2023 20:32:33 -0400 Subject: [PATCH] [ngcodegen][python] debut with what unit tests say --- tatsu/ngcodegen/python.py | 10 +++++----- test/grammar/keyword_test.py | 1 + test/grammar/pattern_test.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tatsu/ngcodegen/python.py b/tatsu/ngcodegen/python.py index ca03350f..c4305483 100644 --- a/tatsu/ngcodegen/python.py +++ b/tatsu/ngcodegen/python.py @@ -127,11 +127,11 @@ def param_repr(p): self.print() self.print( f""" - @tatsumasu({params})\ - {leftrec}\ - {nomemo}\ - {isname} - def _{rule.name}_(self): + @tatsumasu({params})\ + {leftrec}\ + {nomemo}\ + {isname}\ + \ndef _{rule.name}_(self): """, ) with self.indent(): diff --git a/test/grammar/keyword_test.py b/test/grammar/keyword_test.py index 43452d07..2b6ed8bc 100644 --- a/test/grammar/keyword_test.py +++ b/test/grammar/keyword_test.py @@ -72,6 +72,7 @@ def test_check_keywords(self): """ model = compile(grammar, 'test') c = codegen(model) + print(c) parse(c) ast = model.parse('hello world') diff --git a/test/grammar/pattern_test.py b/test/grammar/pattern_test.py index 009ba9f5..9b1de687 100644 --- a/test/grammar/pattern_test.py +++ b/test/grammar/pattern_test.py @@ -112,7 +112,7 @@ def test_multiline_pattern(self): model = compile(grammar=trim(grammar)) print(codegen(model.rules[0].exp.sequence[0])) self.assertEqual( - codegen(model.rules[0].exp.sequence[0]), + codegen(model.rules[0].exp.sequence[0]).strip(), repr("self._pattern('(?x)\nfoo\nbar\n')").strip('"\''), )