Java Code Examples for org.antlr.v4.runtime.Parser#notifyErrorListeners()

The following examples show how to use org.antlr.v4.runtime.Parser#notifyErrorListeners() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
public void reportError(Parser recognizer, RecognitionException e) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
      this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
      this.reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
      this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
      System.err.println("unknown recognition error type: " + e.getClass().getName());
      recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
    }

  }
}
 
Example 2
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
  TokenStream tokens = recognizer.getInputStream();
  String input;
  if (tokens != null) {
    if (e.getStartToken().getType() == -1) {
      input = "<EOF>";
    } else {
      input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    }
  } else {
    input = "<unknown input>";
  }

  String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example 3
Source File: CQLErrorStrategy.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens instanceof TokenStream)
    {
        if (e.getStartToken().getType() == Token.EOF)
            input = "<EOF>";
        else
            input = getText(tokens, e.getStartToken(), e.getOffendingToken());
    }
    else
    {
        input = "<unknown input>";
    }
    String msg = "no viable alternative at input " + escapeWSAndQuote(input);
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example 4
Source File: CapitulatingErrorStrategy.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
	// change error message from default implementation
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens != null) {
		if (e.getStartToken().getType() == Token.EOF) {
			input = "the end";
		} else {
			input = escapeWSAndQuote(tokens.getText(e.getStartToken(), e.getOffendingToken()));
		}
	} else {
		input = escapeWSAndQuote("<unknown input>");
	}
	String msg = "inadmissible input at " + input;
	recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example 5
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
protected void reportUnwantedToken(Parser recognizer) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    String tokenName = this.getTokenErrorDisplay(t);
    IntervalSet expecting = this.getExpectedTokens(recognizer);
    String msg =
        "extraneous input " + tokenName + " expecting "
        + expecting.toString(recognizer.getVocabulary());
    recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
  }
}
 
Example 6
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
protected void reportMissingToken(Parser recognizer) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = this.getExpectedTokens(recognizer);
    String msg =
        "missing " + expecting.toString(recognizer.getVocabulary()) + " at " + this
            .getTokenErrorDisplay(t);
    recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
  }
}
 
Example 7
Source File: GyroErrorStrategy.java    From gyro with Apache License 2.0 5 votes vote down vote up
@Override
protected void reportInputMismatch(Parser recognizer, InputMismatchException error) {
    recognizer.notifyErrorListeners(
        error.getOffendingToken(),
        "Expected " + error.getExpectedTokens().toString(recognizer.getVocabulary()),
        error);
}
 
Example 8
Source File: GyroErrorStrategy.java    From gyro with Apache License 2.0 5 votes vote down vote up
@Override
protected void reportMissingToken(Parser recognizer) {
    if (inErrorRecoveryMode(recognizer)) {
        return;
    }

    beginErrorCondition(recognizer);

    recognizer.notifyErrorListeners(
        recognizer.getCurrentToken(),
        "Missing " + getExpectedTokens(recognizer).toString(recognizer.getVocabulary()),
        null);
}
 
Example 9
Source File: GyroErrorStrategy.java    From gyro with Apache License 2.0 5 votes vote down vote up
@Override
protected void reportUnwantedToken(Parser recognizer) {
    if (inErrorRecoveryMode(recognizer)) {
        return;
    }

    beginErrorCondition(recognizer);
    recognizer.notifyErrorListeners(recognizer.getCurrentToken(), "Extra input", null);
}
 
Example 10
Source File: CapitulatingErrorStrategy.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void reportUnwantedToken(Parser recognizer) {
	// change error message from default implementation
	if (inErrorRecoveryMode(recognizer)) {
		return;
	}

	beginErrorCondition(recognizer);

	Token t = recognizer.getCurrentToken();
	String tokenName = getTokenErrorDisplay(t);
	String msg = "extraneous input " + tokenName + " expecting operator";
	recognizer.notifyErrorListeners(t, msg, null);
}
 
Example 11
Source File: KsqlParserErrorStrategy.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 4 votes vote down vote up
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
  String msg =
      "Syntax error. There is a mismatch between the expected term and te term in the query. "
      + "Please check the line and column in the query.";
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example 12
Source File: GyroErrorStrategy.java    From gyro with Apache License 2.0 4 votes vote down vote up
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException error) {
    recognizer.notifyErrorListeners(error.getOffendingToken(), "Invalid input", error);
}
 
Example 13
Source File: CapitulatingErrorStrategy.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
	// change error message from default implementation
	String msg = "mismatched input " + getTokenErrorDisplay(e.getOffendingToken()) + " expecting operator";
	recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
Example 14
Source File: BatfishANTLRErrorStrategy.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
public void reportError(Parser recognizer, RecognitionException e) {
  if (!(e instanceof BatfishRecognitionException)) {
    recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
  }
}