Merge pull request #2548 from Thomasb81/fix2547
Fix overlaping condition
This commit is contained in:
commit
edae2a1c9b
|
@ -612,7 +612,6 @@ namespace Antlr4.Runtime
|
|||
}
|
||||
// throw exception unless disjoint or identical
|
||||
bool disjoint = prevRop.lastIndex < rop.index || prevRop.index > rop.lastIndex;
|
||||
bool same = prevRop.index == rop.index && prevRop.lastIndex == rop.lastIndex;
|
||||
// Delete special case of replace (text==null):
|
||||
// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
|
||||
if (prevRop.text == null && rop.text == null && !disjoint)
|
||||
|
@ -628,7 +627,7 @@ namespace Antlr4.Runtime
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!disjoint && !same)
|
||||
if (!disjoint)
|
||||
{
|
||||
throw new ArgumentException("replace op boundaries of " + rop + " overlap with previous " + prevRop);
|
||||
}
|
||||
|
|
|
@ -348,7 +348,6 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
|
|||
}
|
||||
// throw exception unless disjoint or identical
|
||||
bool disjoint = prevRop->lastIndex < rop->index || prevRop->index > rop->lastIndex;
|
||||
bool same = prevRop->index == rop->index && prevRop->lastIndex == rop->lastIndex;
|
||||
// Delete special case of replace (text==null):
|
||||
// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
|
||||
if (prevRop->text.empty() && rop->text.empty() && !disjoint) {
|
||||
|
@ -358,7 +357,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
|
|||
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
|
||||
std::cout << "new rop " << rop << std::endl;
|
||||
}
|
||||
else if (!disjoint && !same) {
|
||||
else if (!disjoint) {
|
||||
throw IllegalArgumentException("replace op boundaries of " + rop->toString() +
|
||||
" overlap with previous " + prevRop->toString());
|
||||
}
|
||||
|
|
|
@ -157,13 +157,12 @@ class TokenStreamRewriter(object):
|
|||
rewrites[prevRop.instructionIndex] = None
|
||||
continue
|
||||
isDisjoint = any((prevRop.last_index < rop.index, prevRop.index > rop.last_index))
|
||||
isSame = all((prevRop.index == rop.index, prevRop.last_index == rop.last_index))
|
||||
if all((prevRop.text is None, rop.text is None, not isDisjoint)):
|
||||
rewrites[prevRop.instructionIndex] = None
|
||||
rop.index = min(prevRop.index, rop.index)
|
||||
rop.last_index = min(prevRop.last_index, rop.last_index)
|
||||
print('New rop {}'.format(rop))
|
||||
elif not all((isDisjoint, isSame)):
|
||||
elif (not(isDisjoint)):
|
||||
raise ValueError("replace op boundaries of {} overlap with previous {}".format(rop, prevRop))
|
||||
|
||||
# Walk inserts before
|
||||
|
|
|
@ -156,13 +156,12 @@ class TokenStreamRewriter(object):
|
|||
rewrites[prevRop.instructionIndex] = None
|
||||
continue
|
||||
isDisjoint = any((prevRop.last_index<rop.index, prevRop.index>rop.last_index))
|
||||
isSame = all((prevRop.index == rop.index, prevRop.last_index == rop.last_index))
|
||||
if all((prevRop.text is None, rop.text is None, not isDisjoint)):
|
||||
rewrites[prevRop.instructionIndex] = None
|
||||
rop.index = min(prevRop.index, rop.index)
|
||||
rop.last_index = min(prevRop.last_index, rop.last_index)
|
||||
print('New rop {}'.format(rop))
|
||||
elif not all((isDisjoint, isSame)):
|
||||
elif (not(isDisjoint)):
|
||||
raise ValueError("replace op boundaries of {} overlap with previous {}".format(rop, prevRop))
|
||||
|
||||
# Walk inserts
|
||||
|
@ -249,4 +248,4 @@ class TokenStreamRewriter(object):
|
|||
def __str__(self):
|
||||
if self.text:
|
||||
return '<ReplaceOp@{}..{}:"{}">'.format(self.tokens.get(self.index), self.tokens.get(self.last_index),
|
||||
self.text)
|
||||
self.text)
|
||||
|
|
Loading…
Reference in New Issue