super(scanner);
}
@Override
protected Partition calculateStartOfDamagedRegion(int pos) {
Partition p = getPartitionAt(pos);
if (p != null) {
/*
* This is needed to cover cases like the following:
* The user is about to comment out the Length() call in the script. After the first
* "/" character is typed we have:
*
* <trans>
* /Length($x)
* </trans>
*
* When the second "/" is typed p will represent the Length token. The logic below
* will then break immediately, and we will end up with two /-operator tokens rather
* than with a start-comment token.
*/
p = p.getPrevious();
}
while (p != null) {
Token t = p.token;
/*
* This is needed to cover cases like the following:
*
* <trans>"abc"</trans
*
* At this point he currect partitioning will end with
*
* OPERATOR("<") OPERATOR("/") SOURCE_PATH("trans")
*
* When the final ">" is typed, we need to go back all the way to the string literal
* "abc" in order to correctly detect the new END_TRANS token.
*
* Another example:
*
* <trans>"abc"</tra ns> [note the space in the closing trans]
*
* At this point the current partitioning will end with
*
* OPERATOR("<") OPERATOR("/") SOURCE_PATH("tra") WHITESPACE(" ") SOURCE_PATH("ns") OPERATOR(">")
*
* When the erroneous space is deleted we must again walk back to the string literal "abc"
* as a starting point.
*/
if (!t.isWhitespace() && t != SOURCE_PATH && t != OPERATOR && t != WORD_TOKEN) {
break;
}
p = p.getPrevious();
}
return p;
}