Add pluggable regex engine support#7
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a pluggable regex layer to jsonata-cpp by replacing direct std::regex usage in JSONata evaluation with an engine-agnostic IRegex interface, allowing alternative engines (e.g., RE2) to be injected while keeping the default behavior equivalent to the existing std::regex implementation.
Changes:
- Add
IRegex/RegexEngineabstractions plus a defaultStdRegeximplementation and wire regex literal compilation through the injected engine. - Update evaluator/runtime regex paths (
$match,$contains,$replace,$split, regex-as-function application) to work withstd::shared_ptr<IRegex>instead ofstd::regex. - Add an optional RE2-backed test target demonstrating a non-
std::regexengine integration.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/RE2EngineTest.cpp | Adds RE2-based integration tests for regex behavior with an injected engine. |
| test/RE2Engine.h | Declares a test-only RE2-backed IRegex implementation and engine factory. |
| test/RE2Engine.cpp | Implements the RE2-backed IRegex adapter and engine factory. |
| src/jsonata/utils/Signature.cpp | Updates signature/type detection to treat regex values as shared_ptr<IRegex>. |
| src/jsonata/Tokenizer.cpp | Compiles regex literals via RegexEngine and parses flags into RegexFlags. |
| src/jsonata/StdRegex.cpp | Adds the default std::regex-backed IRegex implementation and defaultRegexEngine(). |
| src/jsonata/Parser.cpp | Threads RegexEngine into parsing/tokenization. |
| src/jsonata/Jsonata.cpp | Stores and propagates RegexEngine; updates regex application logic to use IRegex. |
| src/jsonata/Functions.cpp | Ports regex-related functions to IRegex and compiles dynamic string patterns via the current engine. |
| include/jsonata/utils/Signature.h | Includes IRegex so regex values can be recognized in signatures. |
| include/jsonata/Tokenizer.h | Updates tokenizer API to accept/store a RegexEngine and return compiled IRegex. |
| include/jsonata/StdRegex.h | Declares the StdRegex IRegex adapter. |
| include/jsonata/Parser.h | Extends parse() signature to accept a RegexEngine. |
| include/jsonata/Jsonata.h | Extends constructors/factory to accept a RegexEngine and exposes getRegexEngine(). |
| include/jsonata/IRegex.h | Introduces IRegex, RegexMatch, RegexFlags, RegexEngine, and defaultRegexEngine(). |
| include/jsonata/Functions.h | Updates regex function signatures to use shared_ptr<IRegex>. |
| CMakeLists.txt | Adds optional JSONATA_BUILD_RE2_TEST target that links RE2 when available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.