mbtarranger.languages.mcrlOuter.ErrorReporter.java Source code

Java tutorial

Introduction

Here is the source code for mbtarranger.languages.mcrlOuter.ErrorReporter.java

Source

/*******************************************************************************
 * Copyright (c) 2013, 2014 ETAS GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation
 *******************************************************************************/
package mbtarranger.languages.mcrlOuter;

import java.io.File;

import mbtarranger.BadBank;

import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;

public class ErrorReporter extends DefaultErrorStrategy {
    File arrFile;

    public ErrorReporter(File arrFile) {
        super();
        this.arrFile = arrFile;
    }

    private void toBadbank(Parser arg0, RecognitionException arg1) {
        // if (arg1 instanceof NoViableAltException){
        // NoViableAltException novex = (NoViableAltException) arg1;
        StringBuilder sb = new StringBuilder();
        for (int tk : arg1.getExpectedTokens().toArray()) {
            sb.append(arg0.getTokenNames()[tk]);
            sb.append(" ");
        }
        String positionInfo = "";
        try {
            positionInfo = "startline " +
            /* [@8,50:50='.',<94>,3:5] */
                    arg1.getOffendingToken().toString().split(">,")[1].split("]")[0];
        } catch (Exception ex) {
        }
        String msg = String.format("%s, mal input: '%s', expected '%s' ", positionInfo,
                getTokenErrorDisplay(arg1.getOffendingToken()), sb.toString());
        BadBank.reportProblem(arg1.getOffendingToken().getLine(), arrFile, msg);
    }

    @Override
    public void recover(Parser arg0, RecognitionException arg1) {
        super.recover(arg0, arg1);
        toBadbank(arg0, arg1);

    }

    @Override
    public void reportError(Parser arg0, RecognitionException arg1) {
        super.reportError(arg0, arg1);
        toBadbank(arg0, arg1);
        // }

    }

}