All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hpccsystems.ws.client.antlr.ErrorStrategy Maven / Gradle / Ivy

Go to download

This project allows a user to interact with ESP services in a controlled manner. The API calls available under org.hpccsystems.ws.client.platform allow for a user to target ESP's across multiple environments running a range of hpccsystems-platform versions. There is no guarantee that if a user utilizes org.hpccsystems.ws.client.gen generated stub code from wsdl, that the calls will be backwards compatible with older hpccsystems-platform versions.

There is a newer version: 9.8.20-1
Show newest version
package org.hpccsystems.ws.client.antlr;

import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;

public class ErrorStrategy extends DefaultErrorStrategy
{

    @Override
    protected void reportMissingToken(Parser recognizer)
    {

        beginErrorCondition(recognizer);

        Token t = recognizer.getCurrentToken();
        String loc = t.getLine() + "," + t.getCharPositionInLine();
        String tokenName = getTokenErrorDisplay(t);
        IntervalSet expecting = getExpectedTokens(recognizer);
        String expectingStr = expecting.toString(recognizer.getVocabulary());

        // TODO - Insert appropriate error code here or change to alternate error handling
        RecognitionException e = new RecognitionException("MISSING_TOKEN " + tokenName + ", expecting "
                + expecting.toString(recognizer.getVocabulary()) + " at " + loc, recognizer, null,
                recognizer.getContext());
        recognizer.notifyErrorListeners(t, "missing token", e);
    }
    
    @Override
    protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {

        beginErrorCondition(recognizer);

        Token t = recognizer.getCurrentToken();
        String tokenName = getTokenErrorDisplay(t);
        IntervalSet expecting = getExpectedTokens(recognizer);
        String expectingStr = expecting.toString(recognizer.getVocabulary());

        RecognitionException re = new RecognitionException("NO_VIABLE_ALTERNATIVE at " + tokenName + ", expecting "
                + expecting.toString(recognizer.getVocabulary()), recognizer, null, recognizer.getContext());
        recognizer.notifyErrorListeners(t, "extra token", e);

    }

    @Override
    protected void reportUnwantedToken(Parser recognizer)
    {
        if (inErrorRecoveryMode(recognizer))
        {
            return;
        }

        beginErrorCondition(recognizer);

        Token t = recognizer.getCurrentToken();
        String tokenName = getTokenErrorDisplay(t);
        IntervalSet expecting = getExpectedTokens(recognizer);
        String expectingStr = expecting.toString(recognizer.getVocabulary());

        RecognitionException e = new RecognitionException("MISSING_TOKEN " + tokenName + ", expecting "
                + expecting.toString(recognizer.getVocabulary()), recognizer, null, recognizer.getContext());
        recognizer.notifyErrorListeners(t, "extra token", e);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy