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

prompto.problem.ParserNoViableAltProblem Maven / Gradle / Ivy

The newest version!
package prompto.problem;

import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;

public class ParserNoViableAltProblem extends ParserProblemBase {

	NoViableAltException e;
	
	public ParserNoViableAltProblem(String path, int line, int column, NoViableAltException e) {
		super(path, line, column);
		this.e = e;
	}
	
	@Override
	public int getStartIndex() {
		return e.getOffendingToken().getStartIndex();
	}
	
	@Override
	public int getEndIndex() {
		return getStartIndex() + getOffendingText().length();
	}
	
	String getOffendingText() {
		return e.getOffendingToken().getText();
	}
	
	@Override
	public String getMessage() {
		TokenStream tokens = (TokenStream)e.getInputStream();
		Token start = e.getStartToken();
		return "Invalid syntax at: " +
				( start.getType()==Token.EOF ? "" : tokens.getText(start, e.getOffendingToken()));
	}
	
	@Override
	public Type getType() {
		return Type.ERROR;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy