Ruby: Add matchesEmptyString to RegExpTerm

This commit is contained in:
Harry Maclean
2022-02-16 11:19:45 +13:00
parent 9e0c82eabb
commit c9fc43a4ba

View File

@@ -268,6 +268,9 @@ class RegExpTerm extends RegExpParent {
/** Gets the primary QL class for this term. */
override string getAPrimaryQlClass() { result = "RegExpTerm" }
/** Holds if this regular expression term can match the empty string. */
predicate matchesEmptyString() { none() }
}
/**
@@ -326,6 +329,8 @@ class RegExpStar extends InfiniteRepetitionQuantifier {
RegExpStar() { this.getQualifier().charAt(0) = "*" }
override string getAPrimaryQlClass() { result = "RegExpStar" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -341,6 +346,8 @@ class RegExpPlus extends InfiniteRepetitionQuantifier {
RegExpPlus() { this.getQualifier().charAt(0) = "+" }
override string getAPrimaryQlClass() { result = "RegExpPlus" }
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
}
/**
@@ -356,6 +363,8 @@ class RegExpOpt extends RegExpQuantifier {
RegExpOpt() { this.getQualifier().charAt(0) = "?" }
override string getAPrimaryQlClass() { result = "RegExpOpt" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -375,6 +384,8 @@ class RegExpRange extends RegExpQuantifier {
RegExpRange() { re.multiples(part_end, end, lower, upper) }
override string getAPrimaryQlClass() { result = "RegExpRange" }
/** Gets the string defining the upper bound of this range, if any. */
string getUpper() { result = upper }
@@ -393,7 +404,9 @@ class RegExpRange extends RegExpQuantifier {
/** Gets the lower bound of the range. */
int getLowerBound() { result = this.getLower().toInt() }
override string getAPrimaryQlClass() { result = "RegExpRange" }
override predicate matchesEmptyString() {
this.getAChild().matchesEmptyString() or this.getLowerBound() = 0
}
}
/**
@@ -440,6 +453,10 @@ class RegExpSequence extends RegExpTerm, TRegExpSequence {
}
override string getAPrimaryQlClass() { result = "RegExpSequence" }
override predicate matchesEmptyString() {
forall(RegExpTerm child | child = this.getAChild() | child.matchesEmptyString())
}
}
pragma[nomagic]
@@ -505,6 +522,8 @@ class RegExpAlt extends RegExpTerm, TRegExpAlt {
override string getAMatchedString() { result = this.getAlternative().getAMatchedString() }
override string getAPrimaryQlClass() { result = "RegExpAlt" }
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
}
class RegExpCharEscape = RegExpEscape;
@@ -579,6 +598,8 @@ class RegExpEscape extends RegExpNormalChar {
*/
class RegExpWordBoundary extends RegExpSpecialChar {
RegExpWordBoundary() { this.getChar() = "\\b" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -607,6 +628,8 @@ class RegExpCharacterClassEscape extends RegExpEscape {
override RegExpTerm getChild(int i) { none() }
override string getAPrimaryQlClass() { result = "RegExpCharacterClassEscape" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -663,6 +686,8 @@ class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass {
}
override string getAPrimaryQlClass() { result = "RegExpCharacterClass" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -702,6 +727,8 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
}
override string getAPrimaryQlClass() { result = "RegExpCharacterRange" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -773,6 +800,8 @@ class RegExpConstant extends RegExpTerm {
override string getConstantValue() { result = this.getValue() }
override string getAPrimaryQlClass() { result = "RegExpConstant" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -820,6 +849,8 @@ class RegExpGroup extends RegExpTerm, TRegExpGroup {
override string getAMatchedString() { result = this.getAChild().getAMatchedString() }
override string getAPrimaryQlClass() { result = "RegExpGroup" }
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
}
/**
@@ -867,6 +898,8 @@ class RegExpDot extends RegExpSpecialChar {
RegExpDot() { this.getChar() = "." }
override string getAPrimaryQlClass() { result = "RegExpDot" }
override predicate matchesEmptyString() { none() }
}
/**
@@ -897,6 +930,8 @@ class RegExpDollar extends RegExpAnchor {
RegExpDollar() { this.getChar() = ["$", "\\Z", "\\z"] }
override string getAPrimaryQlClass() { result = "RegExpDollar" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -912,6 +947,8 @@ class RegExpCaret extends RegExpAnchor {
RegExpCaret() { this.getChar() = ["^", "\\A"] }
override string getAPrimaryQlClass() { result = "RegExpCaret" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -929,6 +966,8 @@ class RegExpZeroWidthMatch extends RegExpGroup {
override RegExpTerm getChild(int i) { none() }
override string getAPrimaryQlClass() { result = "RegExpZeroWidthMatch" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -954,6 +993,8 @@ class RegExpSubPattern extends RegExpZeroWidthMatch {
result.getEnd() = in_end
)
}
override predicate matchesEmptyString() { any() }
}
/**
@@ -981,6 +1022,8 @@ class RegExpPositiveLookahead extends RegExpLookahead {
RegExpPositiveLookahead() { re.positiveLookaheadAssertionGroup(start, end) }
override string getAPrimaryQlClass() { result = "RegExpPositiveLookahead" }
override predicate matchesEmptyString() { any() }
}
/**
@@ -1076,6 +1119,8 @@ class RegExpBackRef extends RegExpTerm, TRegExpBackRef {
override RegExpTerm getChild(int i) { none() }
override string getAPrimaryQlClass() { result = "RegExpBackRef" }
override predicate matchesEmptyString() { this.getGroup().matchesEmptyString() }
}
/**