Commit 63a9dac1 authored by Alexander Weigl's avatar Alexander Weigl
Browse files

Merge branch 'weigl/parsererrorfix' into 'master'

Fixes issues with displaying syntax errors

See merge request key/key!362
parents fdef10ef 5549b30a
......@@ -252,9 +252,9 @@ IS_ABSTRACT_OR_INTERFACE : '\\isAbstractOrInterface';
CONTAINERTYPE : '\\containerType';
// types that need to be declared as keywords
LOCSET : '\\locset';
SEQ : '\\seq';
BIGINT : '\\bigint';
//LOCSET : '\\locset';
//SEQ : '\\seq';
//BIGINT : '\\bigint';
// Unicode symbols for special functions/predicates
UTF_PRECEDES : '\u227A';
......
......@@ -77,28 +77,6 @@ public abstract class ParsingFacade {
KeYParser p = new KeYParser(new CommonTokenStream(createLexer(stream)));
p.removeErrorListeners();
p.addErrorListener(p.getErrorReporter());
p.addErrorListener(new ANTLRErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
System.out.println(((CommonToken) offendingSymbol).getTokenSource().getInputStream().toString());
throw e;
}
@Override
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) {
}
@Override
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, ATNConfigSet configs) {
}
@Override
public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, ATNConfigSet configs) {
}
});
return p;
}
......@@ -139,6 +117,7 @@ public abstract class ParsingFacade {
public static KeyAst.File parseFile(CharStream stream) {
KeYParser p = createParser(stream);
KeYParser.FileContext ctx = p.file();
p.getErrorReporter().throwException();
return new KeyAst.File(ctx);
}
......@@ -151,7 +130,9 @@ public abstract class ParsingFacade {
public static KeyAst.Seq parseSequent(CharStream stream) {
KeYParser p = createParser(stream);
return new KeyAst.Seq(p.seqEOF().seq());
KeyAst.Seq seq = new KeyAst.Seq(p.seqEOF().seq());
p.getErrorReporter().throwException();
return seq;
}
/**
......
package de.uka.ilkd.key.nparser;
import com.google.common.base.Strings;
import de.uka.ilkd.key.parser.Location;
import de.uka.ilkd.key.util.MiscTools;
import org.antlr.v4.runtime.*;
import org.jetbrains.annotations.Nullable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -147,5 +151,24 @@ public class SyntaxErrorReporter extends BaseErrorListener {
.map(it -> it.getBeatifulErrorMessage(lines))
.collect(Collectors.joining(delimter));
}
@Override
public String getMessage() {
StringBuilder s = new StringBuilder();
for (SyntaxError error : errors) {
s.append("line ").append(error.line).append(":").append(error.charPositionInLine).append(" ").append(error.msg)
.append("\n");
}
return s.toString();
}
public Location getLocation() throws MalformedURLException {
if (!errors.isEmpty()) {
SyntaxError e = errors.get(0);
return new Location(MiscTools.parseURL(e.source), e.line, e.charPositionInLine);
}
return null;
}
}
}
\ No newline at end of file
package de.uka.ilkd.key.util;
import de.uka.ilkd.key.nparser.SyntaxErrorReporter;
import org.antlr.runtime.RecognitionException;
import de.uka.ilkd.key.java.ParseExceptionInFile;
......@@ -98,7 +99,9 @@ public final class ExceptionTools {
}
location = new Location(file, ((PosConvertException) exc).getLine(),
((PosConvertException) exc).getColumn());
}
} else if(exc instanceof SyntaxErrorReporter.ParserException) {
location = ((SyntaxErrorReporter.ParserException) exc).getLocation();
}
if (location == null && exc.getCause() != null) {
location = getLocation(exc.getCause());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment