org.antlr.runtime.Parser Java Examples

The following examples show how to use org.antlr.runtime.Parser. 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: ErrorCollector.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void syntaxError(BaseRecognizer recognizer, String[] tokenNames, RecognitionException e)
{
    String hdr = recognizer.getErrorHeader(e);
    String msg = recognizer.getErrorMessage(e, tokenNames);

    StringBuilder builder = new StringBuilder().append(hdr)
            .append(' ')
            .append(msg);

    if (recognizer instanceof Parser)
        appendQuerySnippet((Parser) recognizer, builder);

    errorMsgs.add(builder.toString());
}
 
Example #2
Source File: ToolANTLRParser.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getParserErrorMessage(Parser parser, RecognitionException e) {
	String msg;
	if ( e instanceof NoViableAltException) {
		String name = parser.getTokenErrorDisplay(e.token);
		msg = name+" came as a complete surprise to me";
	}
	else if ( e instanceof v4ParserException) {
		msg = ((v4ParserException)e).msg;
	}
	else {
		msg = parser.getErrorMessage(e, parser.getTokenNames());
	}
	return msg;
}
 
Example #3
Source File: ErrorCollector.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a query snippet to the message to help the user to understand the problem.
 *
 * @param parser the parser used to parse the query
 * @param builder the <code>StringBuilder</code> used to build the error message
 */
private void appendQuerySnippet(Parser parser, StringBuilder builder)
{
    TokenStream tokenStream = parser.getTokenStream();
    int index = tokenStream.index();
    int size = tokenStream.size();

    Token from = tokenStream.get(getSnippetFirstTokenIndex(index));
    Token to = tokenStream.get(getSnippetLastTokenIndex(index, size));
    Token offending = tokenStream.get(getOffendingTokenIndex(index, size));

    appendSnippet(builder, from, to, offending);
}
 
Example #4
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From hop with Apache License 2.0 4 votes vote down vote up
public Parser[] getDelegates() {
  return new Parser[] {};
}
 
Example #5
Source File: DSLMapParser.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public Parser[] getDelegates() {
	return new Parser[] {};
}
 
Example #6
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Parser[] getDelegates() {
  return new Parser[] {};
}