forked from jasder/antlr
C++ runtime version of previousTokenOnChannel doesn't handle edge case correctly #2343
<!-- Before submitting an issue to ANTLR, please check off these boxes: - [x] I am not submitting a question on how to use ANTLR; instead, go to [antlr4-discussion google group](https://groups.google.com/forum/#!forum/antlr-discussion) or ask at [stackoverflow](http://stackoverflow.com/questions/tagged/antlr4) - [ x] I have done a search of the existing issues to make sure I'm not sending in a duplicate Please include information about the expected behavior, actual behavior, and the smallest grammar or code that reproduces the behavior. If appropriate, please indicate the code generation targets such as Java, C#, ... Pointers into offending code regions are also very welcome. --> As documented previousTokenOnChannel, should "return -1 if there are no tokens on channel between i and 0." but the C++ version of the runtime returns 0 not -1 as can be seen below: ``` while (true) { Token *token = _tokens[i].get(); if (token->getType() == Token::EOF || token->getChannel() == channel) { return i; } if (i == 0) break; i--; } ``` Looking at the Java implementation, it would seem the C++ code should instead be: ``` while (true) { Token *token = _tokens[i].get(); if (token->getType() == Token::EOF || token->getChannel() == channel) { return i; } if (i == 0) return -1; i--; } ``` This bug causes getHiddenTokensToLeft() to miss hidden tokens that come before the first non-hidden token. There would also be a potential bug in CommonTokenStream::LB as the "< 0" case would never happen.
This commit is contained in:
parent
27c8eb5c6a
commit
936db23a40
|
@ -272,7 +272,7 @@ ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, size_t channel) {
|
|||
}
|
||||
|
||||
if (i == 0)
|
||||
break;
|
||||
return -1;
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
|
|
Loading…
Reference in New Issue