Skip to content

Commit

Permalink
replace {eol_}comments_re references
Browse files Browse the repository at this point in the history
  • Loading branch information
vfazio committed Dec 27, 2024
1 parent ae00ecf commit 157937b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tatsu/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings):
ignorecase=False,
namechars='',
parseinfo=True,
comments_re=re.compile('(?sm)[(][*](?:.|\\n)*?[*][)]', re.MULTILINE|re.DOTALL),
eol_comments_re=re.compile('#[^\\n]*'),
comments='(?sm)[(][*](?:.|\\n)*?[*][)]',
eol_comments='#[^\\n]*',
keywords=KEYWORDS,
start='start',
)
Expand All @@ -55,8 +55,8 @@ def __init__(self, /, config: ParserConfig | None = None, **settings):
ignorecase=False,
namechars='',
parseinfo=True,
comments_re=re.compile('(?sm)[(][*](?:.|\\n)*?[*][)]', re.MULTILINE|re.DOTALL),
eol_comments_re=re.compile('#[^\\n]*'),
comments='(?sm)[(][*](?:.|\\n)*?[*][)]',
eol_comments='#[^\\n]*',
keywords=KEYWORDS,
start='start',
)
Expand Down
6 changes: 4 additions & 2 deletions tatsu/buffering.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(
self.text = self.original_text = text

self.whitespace_re = self.build_whitespace_re(config.whitespace)
self.comments_re = None if config.comments in (None, '') else re.compile(config.comments)
self.eol_comments_re = None if config.comments in (None, '') else re.compile(config.eol_comments)
self.nameguard = (
config.nameguard
if config.nameguard is not None
Expand Down Expand Up @@ -269,11 +271,11 @@ def eat_whitespace(self):
return self._eat_regex(self.whitespace_re)

def eat_comments(self):
comments = self._eat_regex_list(self.config.comments_re)
comments = self._eat_regex_list(self.comments_re)
self._index_comments(comments, lambda x: x.inline)

def eat_eol_comments(self):
comments = self._eat_regex_list(self.config.eol_comments_re)
comments = self._eat_regex_list(self.eol_comments_re)
self._index_comments(comments, lambda x: x.eol)

def next_token(self):
Expand Down
16 changes: 8 additions & 8 deletions tatsu/codegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,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)
comments = repr(self.node.config.comments)
eol_comments = repr(self.node.config.eol_comments)

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

abstract_rule_template = """
Expand Down Expand Up @@ -535,8 +535,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},
comments={comments},
eol_comments={eol_comments},
keywords=KEYWORDS,
start={start!r},
)
Expand All @@ -554,8 +554,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},
comments={comments},
eol_comments={eol_comments},
left_recursion={left_recursion},
keywords=KEYWORDS,
start={start!r},
Expand Down
4 changes: 2 additions & 2 deletions tatsu/ngcodegen/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def _gen_init(self, grammar: grammars.Grammar):
ignorecase={grammar.config.ignorecase},
namechars={grammar.config.namechars!r},
parseinfo={grammar.config.parseinfo},
comments_re={grammar.config.comments_re!r},
eol_comments_re={grammar.config.eol_comments_re!r},
comments={grammar.config.comments!r},
eol_comments={grammar.config.eol_comments!r},
keywords=KEYWORDS,
start={start!r},
)
Expand Down
2 changes: 1 addition & 1 deletion test/grammar/syntax_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_parse_hash():
start = '#' ;
"""

parser = compile(grammar, eol_comments_re='')
parser = compile(grammar, eol_comments='')
parser.parse('#', trace=True)


Expand Down

0 comments on commit 157937b

Please sign in to comment.