Пример #1
0
/** Parser error-reporting function can be overridden in subclass */
void Parser::reportError(const RecognitionException& ex)
{
	// DW 060204 Amended to indicate error in DOS window
	ANTLR_USE_NAMESPACE(std)cerr << "cerr " << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
	// DW 060204 Inserted to show position of condition in trace output
	ANTLR_USE_NAMESPACE(std)cout << "cout " << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
}
Пример #2
0
void DefaultErrorStrategy::reportError(Parser *recognizer, const RecognitionException &e) {
  // If we've already reported an error and have not matched a token
  // yet successfully, don't report any errors.
  if (inErrorRecoveryMode(recognizer)) {
    return; // don't report spurious errors
  }

  beginErrorCondition(recognizer);
  if (is<const NoViableAltException *>(&e)) {
    reportNoViableAlternative(recognizer, (const NoViableAltException &)e);
  } else if (is<const InputMismatchException *>(&e)) {
    reportInputMismatch(recognizer, (const InputMismatchException &)e);
  } else if (is<const FailedPredicateException *>(&e)) {
    reportFailedPredicate(recognizer, (const FailedPredicateException &)e);
  } else if (is<const RecognitionException *>(&e)) {
    recognizer->notifyErrorListeners(e.getOffendingToken(), e.what(), std::current_exception());
  }
}
Пример #3
0
void ParserInterpreter::recover(RecognitionException &e) {
  size_t i = _input->index();
  getErrorHandler()->recover(this, std::make_exception_ptr(e));

  if (_input->index() == i) {
    // no input consumed, better add an error node
    if (is<InputMismatchException *>(&e)) {
      InputMismatchException &ime = (InputMismatchException&)e;
      Token *tok = e.getOffendingToken();
      size_t expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
      _errorToken = getTokenFactory()->create({ tok->getTokenSource(), tok->getTokenSource()->getInputStream() },
        expectedTokenType, tok->getText(), Token::DEFAULT_CHANNEL, INVALID_INDEX, INVALID_INDEX, // invalid start/stop
        tok->getLine(), tok->getCharPositionInLine());
      _ctx->addErrorNode(_tracker, _errorToken.get());
    }
    else { // NoViableAlt
      Token *tok = e.getOffendingToken();
      _errorToken = getTokenFactory()->create({ tok->getTokenSource(), tok->getTokenSource()->getInputStream() },
        Token::INVALID_TYPE, tok->getText(), Token::DEFAULT_CHANNEL, INVALID_INDEX, INVALID_INDEX, // invalid start/stop
        tok->getLine(), tok->getCharPositionInLine());
      _ctx->addErrorNode(_tracker, _errorToken.get());
    }
  }
}
Пример #4
0
/** Report exception errors caught in nextToken() */
void CharScanner::reportError(const RecognitionException& ex)
{
	ANTLR_USE_NAMESPACE(std)cerr << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
}