Skip to content

Commit

Permalink
[lint] solve warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
apalala committed Nov 29, 2023
1 parent 7074718 commit fda5915
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tatsu/ngcodegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from collections.abc import Iterator
from typing import Any

from ..collections import OrderedSet as oset
from .. import grammars
from ..collections import OrderedSet as oset
from ..mixins.indent import IndentPrintMixin
from ..util import trim, compress_seq, safe_name
from ..util import compress_seq, safe_name, trim
from ..walkers import NodeWalker

HEADER = """\
Expand Down Expand Up @@ -110,24 +110,25 @@ def param_repr(p):
if rule.kwparams:
kwparams = ', '.join(
f'{k}={param_repr(self.walk(v))}'
for k, v in self.kwparams.items()
for k, v in rule.kwparams.items()
)

if params and kwparams:
params = params + ', ' + kwparams
elif kwparams:
params = kwparams

sdefines = ''
if not isinstance(rule.exp, grammars.Choice):
sdefines = self._make_defines_declaration(rule)
# sdefines = ''
# if not isinstance(rule.exp, grammars.Choice):
# sdefines = self._make_defines_declaration(rule)

leftrec = '\n@leftrec' if rule.is_leftrec else ''
nomemo = (
'\n@nomemo'
if not rule.is_memoizable and not leftrec
else ''
)
isname='\n@isname' if rule.is_name else ''
isname = '\n@isname' if rule.is_name else ''

self.print(
f"""
Expand All @@ -136,7 +137,7 @@ def param_repr(p):
{nomemo}\
{isname}
def _{rule.name}_(self):
"""
""",
)
with self.indent():
self.print(self.walk(rule.exp))
Expand Down Expand Up @@ -208,12 +209,12 @@ def _make_defines_declaration(self, node: grammars.Model):
if not (sdefs or ldefs):
return ''
else:
sdefs = '[%s]' % ', '.join(sorted(repr(d) for d in sdefs))
ldefs = '[%s]' % ', '.join(sorted(repr(d) for d in ldefs))
sdefs_str = '[%s]' % ', '.join(sorted(repr(d) for d in sdefs))
ldefs_str = '[%s]' % ', '.join(sorted(repr(d) for d in ldefs))
if not ldefs:
return f'\n\n self._define({sdefs}, {ldefs})'
return f'\n\n self._define({sdefs_str}, {ldefs_str})'
else:
return '\n' + trim(self.define_template % (sdefs, ldefs))
return '\n' + trim(self.define_template % (sdefs_str, ldefs_str))

define_template = """\
self._define(
Expand Down

0 comments on commit fda5915

Please sign in to comment.