Go target, unable to check when custom error strategy is in recovery mode
See original GitHub issueHello, community!
I am trying to move existing parser error strategy from c++ to golang target:
class MyErrorStrategy: public antlr4::DefaultErrorStrategy {
void reportUnwantedToken(antlr4::Parser* recognizer) override {
if (inErrorRecoveryMode(recognizer)) {
return;
}
antlr4::Token* t = recognizer->getCurrentToken();
std::string tokenName = getTokenErrorDisplay(t);
antlr4::misc::IntervalSet expecting = getExpectedTokens(recognizer);
throw CustomException({
{"extraneous input " + tokenName, Position {int(t->getLine()), int(t->getCharPositionInLine()) + 1}},
{" expecting " + expecting.toString(recognizer->getVocabulary()), Position()}
});
}
};
But I have a “small problem”. Unlike c++, golang does not provide the ability to call private / unexported methods. This small difference makes it impossible to check when the strategy is inErrorRecoveryMode
.
I saw that the strategy method GetTokenErrorDisplay
was made public, as well as the parser
method GetCurrentToken
in contrast to the c++ runtime, where it has private access. Perhaps it’s time to also make the inErrorRecoveryMode
method public? I find an explanation why the methods of controlling the state flag are private, but I don’t understand why method for reading it has private access.
I also assume that there is another way to do this check. If I’m right, please tell me how I can do it.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Weird. that it did not auto close to spite me saying “Fixes #3259”. hmm…
Yeah, it looks like it should be compared to other runtimes. SGTM