JavaScript: Fix RegExpTerm.getPredecessor and getSuccessor.

These were originally meant to give you the term that is textually matched right before/right after the receiver. When I introduced support for lookbehinds, I changed the behaviour to give you the term that is _operationally_ matched before/after the receiver (remember that lookbehinds are implemented by reverse-matching).

However, I think that's rarely ever what you want, and is wrong for the only two uses of these predicates, where it's the textual matching order that we are after, not the operational order.

Consequently, I've changed the semantics back and updated the comments to hopefully clarify the intention.
This commit is contained in:
Max Schaefer
2019-11-28 12:49:39 +00:00
parent ec8ced7963
commit a788bf87a0
5 changed files with 14 additions and 12 deletions

View File

@@ -73,21 +73,21 @@ class RegExpTerm extends Locatable, @regexpterm {
/** Holds if this regular expression term can match the empty string. */
predicate isNullable() { none() } // Overridden in subclasses.
/** Gets the regular expression term that is matched before this one, if any. */
/** Gets the regular expression term that is matched (textually) before this one, if any. */
RegExpTerm getPredecessor() {
exists(RegExpSequence seq, int i |
seq.getChild(i) = this and
seq.getChild(i - getDirection()) = result
seq.getChild(i - 1) = result
)
or
result = getParent().(RegExpTerm).getPredecessor()
}
/** Gets the regular expression term that is matched after this one, if any. */
/** Gets the regular expression term that is matched (textually) after this one, if any. */
RegExpTerm getSuccessor() {
exists(RegExpSequence seq, int i |
seq.getChild(i) = this and
seq.getChild(i + getDirection()) = result
seq.getChild(i + 1) = result
)
or
exists(RegExpTerm parent |
@@ -98,12 +98,6 @@ class RegExpTerm extends Locatable, @regexpterm {
)
}
/**
* Gets the matching direction of this term: `1` if it is in a forward-matching
* context, `-1` if it is in a backward-matching context.
*/
private int getDirection() { if isInBackwardMatchingContext() then result = -1 else result = 1 }
/**
* Holds if this regular term is in a forward-matching context, that is,
* it has no enclosing lookbehind assertions.