C++: Add ECMAScript std::regex parser - #22300
Open
jketema wants to merge 40 commits into
Open
Conversation
Note that we are currently still implementing what Ruby thinks a regex is. This is not correct as C++ by default uses a variant of ECMAScript regexes. We will address this in the follow-up commits.
Strings can have a prefix in C++, which affects the location.
Clean up test source while here
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an ECMAScript-compatible std::regex parser and parse-tree model for future C++ data-flow integration.
Changes:
- Adds parser and regex tree-view libraries.
- Supports raw-string source locations and shared regex utilities.
- Adds comprehensive parsing, value, and location tests.
Show a summary per file
| File | Description |
|---|---|
cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll |
Implements regex parsing. |
cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll |
Exposes parsed regex trees. |
cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll |
Models raw string literals. |
cpp/ql/lib/qlpack.yml |
Adds the regex dependency. |
cpp/ql/lib/change-notes/2026-07-23-std-regex-ecmascript-parser.md |
Documents the feature. |
cpp/ql/test/library-tests/regex/regexp.cpp |
Provides regex test inputs. |
cpp/ql/test/library-tests/regex/regexp.ql |
Tests parsed terms and values. |
cpp/ql/test/library-tests/regex/regexp.expected |
Records expected query results. |
cpp/ql/test/library-tests/regex/parse.ql |
Produces parse-tree graphs. |
cpp/ql/test/library-tests/regex/parse.expected |
Records expected parse trees. |
cpp/ql/test/library-tests/regex/locations.ql |
Tests source locations. |
cpp/ql/test/library-tests/regex/locations.expected |
Records expected locations. |
Review details
Tip
Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (3)
cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll:834
- The single-character claim contradicts this implementation and the new
abctest result, where oneRegExpConstantrepresents the complete three-character constant. Remove that claim to keep the public class documentation accurate.
* A constant regular expression term, that is, a regular expression
* term matching a single string. Currently, this will always be a single character.
cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll:65
- Remove the accidentally duplicated explanation.
// check if the character that comes before the previous closing bracket
// is an opening bracket (taking `^` into account)
// check if the character that comes before the previous closing bracket
// is an opening bracket (taking `^` into account)
cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll:604
- Add the missing possessive apostrophe.
/** Holds if this terms name is given by the part following the escape character. */
- Files reviewed: 12/12 changed files
- Comments generated: 5
- Review effort level: Balanced
| result.getEnd() = part_end | ||
| } | ||
|
|
||
| /** Hodls if this term may match an unlimited number of times. */ |
Comment on lines
+806
to
+807
| * A normal character in a regular expression, that is, a character | ||
| * without special meaning. This includes escaped characters. |
| } | ||
|
|
||
| /** | ||
| * Holds if `root` has the `s` flag for multi-line matching. |
| */ | ||
| abstract class RegExp extends StringLiteral { | ||
| /** | ||
| * Holds if this `RegExp` has the `s` flag for multi-line matching. |
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.
Commit-by-commit review recommended. This is not hooked into anything yet, as this is getting quite big already, so I didn't want to add the flow config here, or other regex alternatives that can be used with
std::regex.Approach: