Skip to content

Commit 56623e5

Browse files
msimacektomasstupka
authored andcommitted
Add ErrorCallback to CompilerTests
1 parent f101513 commit 56623e5

File tree

2 files changed

+8
-8
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler
    • com.oracle.graal.python/src/com/oracle/graal/python/compiler

2 files changed

+8
-8
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.nio.file.Paths;
4747
import java.util.EnumSet;
4848

49-
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
5049
import org.junit.Assert;
5150
import org.junit.Rule;
5251
import org.junit.Test;
@@ -55,6 +54,7 @@
5554
import com.oracle.graal.python.compiler.CodeUnit;
5655
import com.oracle.graal.python.compiler.CompilationUnit;
5756
import com.oracle.graal.python.compiler.Compiler;
57+
import com.oracle.graal.python.pegparser.ErrorCallback;
5858
import com.oracle.graal.python.pegparser.FExprParser;
5959
import com.oracle.graal.python.pegparser.InputType;
6060
import com.oracle.graal.python.pegparser.NodeFactory;
@@ -63,6 +63,7 @@
6363
import com.oracle.graal.python.pegparser.ParserTokenizer;
6464
import com.oracle.graal.python.pegparser.sst.ExprTy;
6565
import com.oracle.graal.python.pegparser.sst.ModTy;
66+
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
6667
import com.oracle.graal.python.test.PythonTests;
6768

6869
public class CompilerTests extends PythonTests {
@@ -727,18 +728,21 @@ private void doTest(String src) {
727728
}
728729

729730
private void doTest(String src, InputType type) {
731+
ErrorCallback errorCallback = (errorType, sourceRange, message) -> {
732+
throw new AssertionError("Unexpected syntax error: " + message);
733+
};
730734
ParserTokenizer tokenizer = new ParserTokenizer(src);
731735
NodeFactory factory = new NodeFactoryImp();
732736
FExprParser fexpParser = new FExprParser() {
733737
@Override
734738
public ExprTy parse(String code, SourceRange sourceRange) {
735739
ParserTokenizer tok = new ParserTokenizer(code);
736-
return new Parser(tok, factory, this).fstring_rule();
740+
return new Parser(tok, factory, this, errorCallback).fstring_rule();
737741
}
738742
};
739-
Parser parser = new Parser(tokenizer, factory, fexpParser);
743+
Parser parser = new Parser(tokenizer, factory, fexpParser, errorCallback);
740744
ModTy result = (ModTy) parser.parse(type);
741-
Compiler compiler = new Compiler();
745+
Compiler compiler = new Compiler(errorCallback);
742746
CompilationUnit cu = compiler.compile(result, EnumSet.noneOf(Compiler.Flags.class), 2);
743747
CodeUnit co = cu.assemble(0);
744748
checkCodeUnit(co);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ public class Compiler implements SSTreeVisitor<Void> {
168168
public enum Flags {
169169
}
170170

171-
public Compiler() {
172-
this(null);
173-
}
174-
175171
public Compiler(ErrorCallback errorCallback) {
176172
this.errorCallback = errorCallback;
177173
}

0 commit comments

Comments
 (0)