From 62e2597c248b3f3ff51d9edbd75ce495ccd991f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Thu, 2 May 2024 17:43:50 +0200 Subject: [PATCH] Pre-compile regexps (#338) --- tatsu/infos.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tatsu/infos.py b/tatsu/infos.py index efcf6ca..3044a43 100644 --- a/tatsu/infos.py +++ b/tatsu/infos.py @@ -1,5 +1,6 @@ from __future__ import annotations +import re import copy import dataclasses from collections.abc import Callable, Mapping @@ -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 @@ -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(