mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
JS: introduce RegExpSequence::nextElement and previousElement
This commit is contained in:
@@ -76,40 +76,22 @@ class RegExpTerm extends Locatable, @regexpterm {
|
||||
/** Gets the regular expression term that is matched (textually) before this one, if any. */
|
||||
RegExpTerm getPredecessor() {
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
if parent instanceof RegExpSequence
|
||||
then
|
||||
exists(RegExpSequence seq, int i |
|
||||
seq = parent and
|
||||
seq.getChild(i) = this
|
||||
|
|
||||
seq.getChild(i - 1) = result
|
||||
or
|
||||
i = 0 and result = seq.getPredecessor()
|
||||
)
|
||||
else (
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getPredecessor()
|
||||
)
|
||||
result = parent.(RegExpSequence).previousElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).previousElement(this)) and
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getPredecessor()
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the regular expression term that is matched (textually) after this one, if any. */
|
||||
RegExpTerm getSuccessor() {
|
||||
exists(RegExpTerm parent | parent = getParent() |
|
||||
if parent instanceof RegExpSequence
|
||||
then
|
||||
exists(RegExpSequence seq, int i |
|
||||
seq = parent and
|
||||
seq.getChild(i) = this
|
||||
|
|
||||
seq.getChild(i + 1) = result
|
||||
or
|
||||
i = seq.getNumChild() - 1 and result = seq.getSuccessor()
|
||||
)
|
||||
else (
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getSuccessor()
|
||||
)
|
||||
result = parent.(RegExpSequence).nextElement(this)
|
||||
or
|
||||
not exists(parent.(RegExpSequence).nextElement(this)) and
|
||||
not parent instanceof RegExpSubPattern and
|
||||
result = parent.getSuccessor()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -328,6 +310,19 @@ class RegExpSequence extends RegExpTerm, @regexp_seq {
|
||||
or
|
||||
result = getChild(i).getConstantValue() + getConstantValue(i+1)
|
||||
}
|
||||
|
||||
/** Gets the element preceding `element` in this sequence. */
|
||||
RegExpTerm previousElement(RegExpTerm element) {
|
||||
element = nextElement(result)
|
||||
}
|
||||
|
||||
/** Gets the element following `element` in this sequence. */
|
||||
RegExpTerm nextElement(RegExpTerm element) {
|
||||
exists(int i |
|
||||
element = this.getChild(i) and
|
||||
result = this.getChild(i + 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user