Add RegExpQuotedString class to support quoted string escapes in regex

This commit is contained in:
Napalys
2025-03-07 10:42:10 +01:00
parent e0f20b2bd1
commit 8cbc0aea05
3 changed files with 52 additions and 30 deletions

View File

@@ -1170,6 +1170,28 @@ private class StringConcatRegExpPatternSource extends RegExpPatternSource {
override RegExpTerm getRegExpTerm() { result = this.asExpr().(AddExpr).asRegExp() }
}
/**
* A quoted string escape in a regular expression, using the `\q` syntax.
* The only operation supported inside a quoted string is alternation, using `|`.
*
* Example:
*
* ```
* \q{foo}
* \q{a|b|c}
* ```
*/
class RegExpQuotedString extends RegExpTerm, @regexp_quoted_string {
/** Gets the term representing the contents of this quoted string. */
RegExpTerm getQuotedString() { result = this.getAChild() }
override predicate isNullable() { none() }
override string getAMatchedString() { result = this.getQuotedString().getAMatchedString() }
override string getAPrimaryQlClass() { result = "RegExpQuotedString" }
}
module RegExp {
/** Gets the string `"?"` used to represent a regular expression whose flags are unknown. */
string unknownFlag() { result = "?" }