Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-compile regexps #338

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tatsu/infos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
import copy
import dataclasses
from collections.abc import Callable, Mapping
Expand Down Expand Up @@ -29,8 +30,8 @@ class ParserConfig:
start_rule: str | None = None # FIXME
rule_name: str | None = None # Backward compatibility

comments_re: str | None = None
eol_comments_re: str | None = None
comments_re: re.Pattern | None = None
eol_comments_re: re.Pattern | None = None

tokenizercls: type[Tokenizer] | None = None # FIXME
semantics: type | None = None
Expand Down Expand Up @@ -63,9 +64,9 @@ def __post_init__(self): # pylint: disable=W0235
if self.ignorecase:
self.keywords = [k.upper() for k in self.keywords]
if self.comments:
self.comments_re = self.comments
self.comments_re = re.compile(self.comments)
if self.eol_comments:
self.eol_comments_re = self.eol_comments
self.eol_comments_re = re.compile(self.eol_comments)

@classmethod
def new(
Expand Down
Loading