|
55 | 55 | import operator |
56 | 56 | import os |
57 | 57 | import re |
58 | | -from string import Template |
59 | 58 | import sys |
60 | 59 | from functools import reduce, wraps |
| 60 | +from string import Template |
61 | 61 | from textwrap import dedent |
62 | 62 | from typing import ( |
63 | 63 | Any, |
|
80 | 80 |
|
81 | 81 | import lark |
82 | 82 | import lark.visitors |
| 83 | +import re2 |
83 | 84 |
|
84 | 85 | import celpy.celtypes |
85 | 86 | from celpy.celparser import tree_dump |
86 | 87 |
|
87 | | -try: |
88 | | - import re2 |
89 | | - |
90 | | - def function_matches(text: str, pattern: str) -> "Result": |
91 | | - """Implementation of the ``match()`` function using ``re2``""" |
92 | | - try: |
93 | | - m = re2.search(pattern, text) |
94 | | - except re2.error as ex: |
95 | | - return CELEvalError("match error", ex.__class__, ex.args) |
96 | | - |
97 | | - return celpy.celtypes.BoolType(m is not None) |
98 | | - |
99 | | -except ImportError: # pragma: no cover |
100 | | - # There is a build issue with python_version=='3.13' and sys_platform=='darwin' |
101 | | - # See https://github.com/google/re2/issues/516 |
102 | | - # We fall back to using re, which passes the essential tests |
103 | | - |
104 | | - def function_matches(text: str, pattern: str) -> "Result": |
105 | | - """Alternative implementation of the ``match()`` function for systems where ``re2`` can't be installed.""" |
106 | | - try: |
107 | | - m = re.search(pattern, text) |
108 | | - except re.error as ex: |
109 | | - return CELEvalError("match error", ex.__class__, ex.args) |
110 | | - |
111 | | - return celpy.celtypes.BoolType(m is not None) |
112 | | - |
113 | | - |
114 | 88 | # An Annotation describes a union of types, functions, and function types. |
115 | 89 | Annotation = Union[ |
116 | 90 | celpy.celtypes.TypeType, |
@@ -420,6 +394,16 @@ def function_endsWith( |
420 | 394 | return celpy.celtypes.BoolType(string.endswith(fragment)) |
421 | 395 |
|
422 | 396 |
|
| 397 | +def function_matches(text: str, pattern: str) -> Result: |
| 398 | + """Implementation of the ``match()`` function using ``re2``""" |
| 399 | + try: |
| 400 | + m = re2.search(pattern, text) |
| 401 | + except re2.error as ex: |
| 402 | + return CELEvalError("match error", ex.__class__, ex.args) |
| 403 | + |
| 404 | + return celpy.celtypes.BoolType(m is not None) |
| 405 | + |
| 406 | + |
423 | 407 | def function_getDate( |
424 | 408 | ts: celpy.celtypes.TimestampType, |
425 | 409 | tz_name: Optional[celpy.celtypes.StringType] = None, |
|
0 commit comments