@@ -1300,7 +1300,7 @@ def evaluate_apply_expression(self, expr: Optional[parser.Parser.Symbol], input:
13001300 return result
13011301
13021302 def is_function_like (self , o : Optional [Any ]) -> bool :
1303- return utils .Utils .is_function (o ) or functions .Functions .is_lambda (o ) or ( isinstance ( o , re . Pattern ) )
1303+ return utils .Utils .is_function (o ) or functions .Functions .is_lambda (o ) or functions . Functions . is_regex ( o )
13041304
13051305 CURRENT = threading .local ()
13061306 MUTEX = threading .Lock ()
@@ -1477,7 +1477,7 @@ def apply_inner(self, proc: Optional[Any], args: Optional[Any], input: Optional[
14771477 # }
14781478 elif isinstance (proc , Jsonata .JLambda ):
14791479 result = proc .call (input , validated_args )
1480- elif isinstance (proc , re . Pattern ):
1480+ elif functions . Functions . is_regex (proc ):
14811481 _res = []
14821482 for s in validated_args :
14831483 if isinstance (s , str ):
@@ -1886,12 +1886,15 @@ def _static_initializer() -> None:
18861886 #
18871887 # JSONata
18881888 # @param {Object} expr - JSONata expression
1889+ # @param {Object} regex_engine - module/object providing a `compile(pattern, flags)`
1890+ # function compatible with the stdlib `re` module (e.g. `re2`), used to compile
1891+ # JSONata regex literals. Defaults to the stdlib `re` module.
18891892 # @returns Evaluated expression
18901893 # @throws jexception.JException An exception if an error occured.
1891- #
1894+ #
18921895 @staticmethod
1893- def jsonata (expression : Optional [str ]) -> 'Jsonata' :
1894- return Jsonata (expression )
1896+ def jsonata (expression : Optional [str ], regex_engine : Any = re ) -> 'Jsonata' :
1897+ return Jsonata (expression , regex_engine )
18951898
18961899 #
18971900 # Internal constructor
@@ -1904,11 +1907,13 @@ def jsonata(expression: Optional[str]) -> 'Jsonata':
19041907 ast : Optional [parser .Parser .Symbol ]
19051908 timestamp : int
19061909 input : Optional [Any ]
1910+ regex_engine : Any
19071911
1908- def __init__ (self , expr : Optional [str ]) -> None :
1912+ def __init__ (self , expr : Optional [str ], regex_engine : Any = re ) -> None :
1913+ self .regex_engine = regex_engine
19091914 try :
19101915 self .parser = Jsonata .get_parser ()
1911- self .ast = self .parser .parse (expr ) # , optionsRecover);
1916+ self .ast = self .parser .parse (expr , regex_engine ) # , optionsRecover);
19121917 self .errors = self .ast .errors
19131918 self .ast .errors = None # delete ast.errors;
19141919 except jexception .JException as err :
@@ -1931,13 +1936,6 @@ def __init__(self, expr: Optional[str]) -> None:
19311936 # return timestamp.getTime()
19321937 # }, "<:n>"))
19331938
1934- # FIXED: options.RegexEngine not implemented in Java
1935- # if(options && options.RegexEngine) {
1936- # jsonata.RegexEngine = options.RegexEngine
1937- # } else {
1938- # jsonata.RegexEngine = RegExp
1939- # }
1940-
19411939 # Set instance for this thread
19421940 Jsonata .CURRENT .jsonata = self
19431941
0 commit comments