001/*
002 * Copyright 2020 nilshoffmann.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.isas.lipidomics.palinom;
017
018import org.antlr.v4.runtime.DefaultErrorStrategy;
019import org.antlr.v4.runtime.InputMismatchException;
020import org.antlr.v4.runtime.Parser;
021import org.antlr.v4.runtime.ParserRuleContext;
022import org.antlr.v4.runtime.RecognitionException;
023import org.antlr.v4.runtime.Token;
024import org.antlr.v4.runtime.misc.ParseCancellationException;
025
026/**
027 *
028 * @author nilshoffmann
029 */
030public class GoslinErrorHandler extends DefaultErrorStrategy {
031
032    @Override
033    public Token recoverInline(Parser recognizer) throws RecognitionException {
034        InputMismatchException e = new InputMismatchException(recognizer);
035        for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
036            context.exception = e;
037        }
038
039        throw new ParseCancellationException(e);
040    }
041
042    @Override
043    public void recover(Parser recognizer, RecognitionException e) {
044        for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
045            context.exception = e;
046        }
047
048        throw new ParseCancellationException(e);
049    }
050
051}