Skip to content

Commit

Permalink
positive join … (neogeny#343)
Browse files Browse the repository at this point in the history
codegen emit / parser equivalence

fix neogeny#342
  • Loading branch information
commonism authored Dec 17, 2024
1 parent 3f78137 commit 1b632e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tatsu/ngcodegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,24 @@ def walk_PositiveClosure(self, closure: grammars.PositiveClosure):
self.print(f'self._positive_closure(block{n})')

def walk_Join(self, join: grammars.Join):
n = self._gen_block(join.sep, name='sep')
m = self._gen_block(join.sep, name='sep')
n = self._gen_block(join.exp)
self.print(f'self._join(block{n}, sep{n})')
self.print(f'self._join(block{n}, sep{m})')

def walk_PositiveJoin(self, join: grammars.PositiveJoin):
n = self._gen_block(join.sep, name='sep')
m = self._gen_block(join.sep, name='sep')
n = self._gen_block(join.exp)
self.print(f'self._positive_join(block{n}, sep{n})')
self.print(f'self._positive_join(block{n}, sep{m})')

def walk_LeftJoin(self, join: grammars.LeftJoin):
n = self._gen_block(join.sep, name='sep')
m = self._gen_block(join.sep, name='sep')
n = self._gen_block(join.exp)
self.print(f'self._left_join(block{n}, sep{n})')
self.print(f'self._left_join(block{n}, sep{m})')

def walk_RightJoin(self, join: grammars.RightJoin):
n = self._gen_block(join.sep, name='sep')
m = self._gen_block(join.sep, name='sep')
n = self._gen_block(join.exp)
self.print(f'self._right_join(block{n}, sep{n})')
self.print(f'self._right_join(block{n}, sep{m})')

def walk_Gather(self, gather: grammars.Gather):
m = self._gen_block(gather.sep, name='sep')
Expand Down
19 changes: 19 additions & 0 deletions test/parser_equivalence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,22 @@ def test_none_whitespace():
parser = generate_and_load_parser('W', grammar)
output = parser.parse(input, parseinfo=False)
assert output == ('This is a', ' test')

def test_sep_join():
grammar = """
@@grammar::numbers
start
= expression $
;
expression
= ~ ( "," )%{ digit }+
;
digit = /\d+/ ;
"""
parser = generate_and_load_parser('W', grammar)
ast = parser.parse('1,2,3,4', nameguard=False)


0 comments on commit 1b632e8

Please sign in to comment.