Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a12545e8f |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
public class Bug421 {
|
||||
public m() { return 1 } // Missing semicolon
|
||||
}
|
||||
@@ -2,9 +2,8 @@ package de.dhbwstuttgart.exceptions;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public class ParserError extends TypeinferenceException{
|
||||
|
||||
public ParserError(Token offset){
|
||||
super("Fehler beim Parsen", offset);
|
||||
public class ParserError extends RuntimeException{
|
||||
public ParserError(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.exceptions.ParserError;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Lexer;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||
@@ -8,9 +9,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -21,13 +20,25 @@ public class JavaTXParser {
|
||||
|
||||
public static Logger logger = new Logger("Parser");
|
||||
|
||||
public static class ThrowingErrorListener extends BaseErrorListener {
|
||||
|
||||
@Override
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
|
||||
int line, int charPositionInLine, String msg, RecognitionException e) {
|
||||
throw new ParserError("Syntax error at line " + line + ":" + charPositionInLine + " - " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static Java17Parser.SourceFileContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
||||
InputStream stream = new FileInputStream(source);
|
||||
// DEPRECATED: ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||
var errorListener = new ThrowingErrorListener();
|
||||
CharStream input = CharStreams.fromStream(stream);
|
||||
Java17Lexer lexer = new Java17Lexer(input);
|
||||
lexer.addErrorListener(errorListener);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
Java17Parser parser = new Java17Parser(tokens);
|
||||
parser.addErrorListener(errorListener);
|
||||
return parser.sourceFile();
|
||||
/*
|
||||
* SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source)); return generator.convert(tree);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import de.dhbwstuttgart.bytecode.CodeGenException;
|
||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||
import de.dhbwstuttgart.exceptions.ParserError;
|
||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||
import de.dhbwstuttgart.util.Logger;
|
||||
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||
@@ -1704,4 +1705,14 @@ public class TestComplete {
|
||||
var clazz = classFiles.get("Bug406");
|
||||
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug421() throws Exception {
|
||||
try {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug421.jav");
|
||||
fail("Shouldn't compile!");
|
||||
} catch (ParserError e) {
|
||||
assertEquals("Syntax error at line 2:26 - no viable alternative at input 'm() { return 1 }'", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user