Skip to content

Commit

Permalink
[codegen] pass whitespace setting to parser
Browse files Browse the repository at this point in the history
[codegen] restore default Buffer class
  • Loading branch information
apalala committed Oct 26, 2023
1 parent 14849fa commit b0b868c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tatsu/codegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def render_fields(self, fields):
elif isinstance(whitespace, RETYPE):
whitespace = repr(whitespace)
else:
whitespace = 're.compile({0})'.format(repr(whitespace))
whitespace = f're.compile(r"{whitespace}")'

if self.node.config.nameguard is not None:
nameguard = repr(self.node.config.nameguard)
Expand Down Expand Up @@ -519,6 +519,7 @@ def {name}(self, ast): # noqa
import sys
from tatsu.buffering import Buffer
from tatsu.parsing import Parser
from tatsu.parsing import tatsumasu
from tatsu.parsing import leftrec, nomemo, isname # noqa
Expand All @@ -529,11 +530,30 @@ def {name}(self, ast): # noqa
KEYWORDS = {{{keywords}}} # type: ignore
class {name}Buffer(Buffer):
def __init__(self, text, /, config: ParserConfig = None, **settings):
config = ParserConfig.new(
config,
owner=self,
whitespace={whitespace},
nameguard={nameguard},
ignorecase={ignorecase},
namechars={namechars},
parseinfo={parseinfo},
comments_re={comments_re},
eol_comments_re={eol_comments_re},
keywords=KEYWORDS,
start={start!r},
)
config = config.replace(**settings)
super().__init__(text, config=config)
class {name}Parser(Parser):
def __init__(self, /, config: ParserConfig | None = None, **settings):
config = ParserConfig.new(
config,
owner=self,
whitespace={whitespace},
nameguard={nameguard},
ignorecase={ignorecase},
namechars={namechars},
Expand Down

0 comments on commit b0b868c

Please sign in to comment.