
org.vesalainen.parser.util.Recoverable Maven / Gradle / Ivy
Show all versions of lpg Show documentation
/*
* Copyright (C) 2014 Timo Vesalainen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.vesalainen.parser.util;
import java.io.IOException;
/**
* Recoverable is an interface used by the parser. In case of syntax error or
* other problem while parsing, the parser check the existence of method
* annotated with @RecoverMethod. If the method exist it is called.
*
* If @RecoverMethod
* doesn't exist, InputReader searches for InputStream or Reader class implementing
* Recoverable interface. If found it calls it's recover method. If the method return's
* true the parser continues at the start of the grammar. If it return's false it throws
* exception.
*
*
Note that parser often encloses input which practically hides the Recoverable input. If
* that happens, a warning is printed to stderr during compilation.
*
*
In most cases using @RecoverMethod is easier.
*
* @author Timo Vesalainen
*/
public interface Recoverable
{
/**
* If returns true, the parser is able to continue parsing in grammar start.
* @param msg Error message
* @param source Error source
* @param line Line number in source
* @param column Column number
* @return
* @throws java.io.IOException
*/
boolean recover(String msg, String source, int line, int column) throws IOException;
}