Skip to content

Commit 157937b

Browse files
committed
replace {eol_}comments_re references
1 parent ae00ecf commit 157937b

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

tatsu/bootstrap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings):
3535
ignorecase=False,
3636
namechars='',
3737
parseinfo=True,
38-
comments_re=re.compile('(?sm)[(][*](?:.|\\n)*?[*][)]', re.MULTILINE|re.DOTALL),
39-
eol_comments_re=re.compile('#[^\\n]*'),
38+
comments='(?sm)[(][*](?:.|\\n)*?[*][)]',
39+
eol_comments='#[^\\n]*',
4040
keywords=KEYWORDS,
4141
start='start',
4242
)
@@ -55,8 +55,8 @@ def __init__(self, /, config: ParserConfig | None = None, **settings):
5555
ignorecase=False,
5656
namechars='',
5757
parseinfo=True,
58-
comments_re=re.compile('(?sm)[(][*](?:.|\\n)*?[*][)]', re.MULTILINE|re.DOTALL),
59-
eol_comments_re=re.compile('#[^\\n]*'),
58+
comments='(?sm)[(][*](?:.|\\n)*?[*][)]',
59+
eol_comments='#[^\\n]*',
6060
keywords=KEYWORDS,
6161
start='start',
6262
)

tatsu/buffering.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(
4949
self.text = self.original_text = text
5050

5151
self.whitespace_re = self.build_whitespace_re(config.whitespace)
52+
self.comments_re = None if config.comments in (None, '') else re.compile(config.comments)
53+
self.eol_comments_re = None if config.comments in (None, '') else re.compile(config.eol_comments)
5254
self.nameguard = (
5355
config.nameguard
5456
if config.nameguard is not None
@@ -269,11 +271,11 @@ def eat_whitespace(self):
269271
return self._eat_regex(self.whitespace_re)
270272

271273
def eat_comments(self):
272-
comments = self._eat_regex_list(self.config.comments_re)
274+
comments = self._eat_regex_list(self.comments_re)
273275
self._index_comments(comments, lambda x: x.inline)
274276

275277
def eat_eol_comments(self):
276-
comments = self._eat_regex_list(self.config.eol_comments_re)
278+
comments = self._eat_regex_list(self.eol_comments_re)
277279
self._index_comments(comments, lambda x: x.eol)
278280

279281
def next_token(self):

tatsu/codegen/python.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ def render_fields(self, fields):
462462
left_recursion = self.node.config.left_recursion
463463
parseinfo = self.node.config.parseinfo
464464
namechars = repr(self.node.config.namechars or '')
465-
comments_re = repr(self.node.config.comments_re)
466-
eol_comments_re = repr(self.node.config.eol_comments_re)
465+
comments = repr(self.node.config.comments)
466+
eol_comments = repr(self.node.config.eol_comments)
467467

468468
rules = '\n'.join(
469469
[self.get_renderer(rule).render() for rule in self.node.rules],
@@ -488,8 +488,8 @@ def render_fields(self, fields):
488488
parseinfo=parseinfo,
489489
keywords=keywords,
490490
namechars=namechars,
491-
comments_re=comments_re,
492-
eol_comments_re=eol_comments_re,
491+
comments=comments,
492+
eol_comments=eol_comments,
493493
)
494494

495495
abstract_rule_template = """
@@ -535,8 +535,8 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings):
535535
ignorecase={ignorecase},
536536
namechars={namechars},
537537
parseinfo={parseinfo},
538-
comments_re={comments_re},
539-
eol_comments_re={eol_comments_re},
538+
comments={comments},
539+
eol_comments={eol_comments},
540540
keywords=KEYWORDS,
541541
start={start!r},
542542
)
@@ -554,8 +554,8 @@ def __init__(self, /, config: ParserConfig | None = None, **settings):
554554
ignorecase={ignorecase},
555555
namechars={namechars},
556556
parseinfo={parseinfo},
557-
comments_re={comments_re},
558-
eol_comments_re={eol_comments_re},
557+
comments={comments},
558+
eol_comments={eol_comments},
559559
left_recursion={left_recursion},
560560
keywords=KEYWORDS,
561561
start={start!r},

tatsu/ngcodegen/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ def _gen_init(self, grammar: grammars.Grammar):
323323
ignorecase={grammar.config.ignorecase},
324324
namechars={grammar.config.namechars!r},
325325
parseinfo={grammar.config.parseinfo},
326-
comments_re={grammar.config.comments_re!r},
327-
eol_comments_re={grammar.config.eol_comments_re!r},
326+
comments={grammar.config.comments!r},
327+
eol_comments={grammar.config.eol_comments!r},
328328
keywords=KEYWORDS,
329329
start={start!r},
330330
)

test/grammar/syntax_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_parse_hash():
352352
start = '#' ;
353353
"""
354354

355-
parser = compile(grammar, eol_comments_re='')
355+
parser = compile(grammar, eol_comments='')
356356
parser.parse('#', trace=True)
357357

358358

0 commit comments

Comments
 (0)