Skip to content

Commit

Permalink
Pre-compile regexps (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
olejorgenb authored May 2, 2024
1 parent 2fae997 commit 62e2597
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 62e2597

Please sign in to comment.