@@ -75,26 +75,41 @@ class RegExpTerm extends Locatable, @regexpterm {
7575
7676 /** Gets the regular expression term that is matched (textually) before this one, if any. */
7777 RegExpTerm getPredecessor ( ) {
78- exists ( RegExpSequence seq , int i |
79- seq .getChild ( i ) = this and
80- seq .getChild ( i - 1 ) = result
78+ exists ( RegExpTerm parent | parent = getParent ( ) |
79+ if parent instanceof RegExpSequence
80+ then
81+ exists ( RegExpSequence seq , int i |
82+ seq = parent and
83+ seq .getChild ( i ) = this
84+ |
85+ seq .getChild ( i - 1 ) = result
86+ or
87+ i = 0 and result = seq .getPredecessor ( )
88+ )
89+ else (
90+ not parent instanceof RegExpSubPattern and
91+ result = parent .getPredecessor ( )
92+ )
8193 )
82- or
83- result = getParent ( ) .( RegExpTerm ) .getPredecessor ( )
8494 }
8595
8696 /** Gets the regular expression term that is matched (textually) after this one, if any. */
8797 RegExpTerm getSuccessor ( ) {
88- exists ( RegExpSequence seq , int i |
89- seq .getChild ( i ) = this and
90- seq .getChild ( i + 1 ) = result
91- )
92- or
93- exists ( RegExpTerm parent |
94- parent = getParent ( ) and
95- not parent instanceof RegExpSubPattern
96- |
97- result = parent .getSuccessor ( )
98+ exists ( RegExpTerm parent | parent = getParent ( ) |
99+ if parent instanceof RegExpSequence
100+ then
101+ exists ( RegExpSequence seq , int i |
102+ seq = parent and
103+ seq .getChild ( i ) = this
104+ |
105+ seq .getChild ( i + 1 ) = result
106+ or
107+ i = seq .getNumChild ( ) - 1 and result = seq .getSuccessor ( )
108+ )
109+ else (
110+ not parent instanceof RegExpSubPattern and
111+ result = parent .getSuccessor ( )
112+ )
98113 )
99114 }
100115
0 commit comments