Skip to content

Commit

Permalink
[codegen] remder REs for comments into the tokenizer/buffer and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
apalala committed Oct 13, 2023
1 parent 0a34786 commit c777dfe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tatsu/codegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ def render_fields(self, fields):
left_recursion = self.node.config.left_recursion
parseinfo = self.node.config.parseinfo
namechars = repr(self.node.config.namechars or '')
comments_re = repr(self.node.config.comments_re)
eol_comments_re = repr(self.node.config.eol_comments_re)

rules = '\n'.join([
self.get_renderer(rule).render() for rule in self.node.rules
Expand All @@ -494,6 +496,8 @@ def render_fields(self, fields):
parseinfo=parseinfo,
keywords=keywords,
namechars=namechars,
comments_re=comments_re,
eol_comments_re=eol_comments_re,
)

abstract_rule_template = '''
Expand All @@ -513,8 +517,6 @@ def {name}(self, ast): # noqa
# Any changes you make to it will be overwritten the next time
# the file is generated.
from __future__ import annotations
import sys
from tatsu.buffering import Buffer
Expand All @@ -528,7 +530,7 @@ def {name}(self, ast): # noqa
KEYWORDS = {{{keywords}}} # type: ignore
class {name}Buffer(Buffer):
class {name}Tokenizer(Buffer):
def __init__(self, text, /, config: ParserConfig | None = None, **settings):
config = ParserConfig.new(
config,
Expand All @@ -537,6 +539,8 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings):
ignorecase={ignorecase},
namechars={namechars},
parseinfo={parseinfo},
comments_re={comments_re},
eol_comments_re={eol_comments_re},
)
config = config.replace(**settings)
super().__init__(text, config=config)
Expand All @@ -551,6 +555,8 @@ def __init__(self, /, config: ParserConfig | None = None, **settings):
ignorecase={ignorecase},
namechars={namechars},
parseinfo={parseinfo},
comments_re={comments_re},
eol_comments_re={eol_comments_re},
keywords=KEYWORDS,
start={start!r},
)
Expand Down

0 comments on commit c777dfe

Please sign in to comment.