Commit 549c19c0 authored by Niklas Fors's avatar Niklas Fors
Browse files

Add error tests

parent d057855e
......@@ -20,6 +20,7 @@ import beaver.Parser;
public class Compiler {
protected ArrayList<Option<?>> options;
protected FlagOption optionWriteToFile;
protected FlagOption optionPrintAST;
protected CommandLine commandLine;
public Compiler(String args[]) throws CommandLineException {
......@@ -37,7 +38,9 @@ public class Compiler {
Program p = parseProgram(filename);
if (!p.errors().isEmpty()) {
System.out.println(p.dumpTree());
if (optionPrintAST.isSet()) {
System.out.println(p.dumpTree());
}
System.err.println("Errors:");
for (ErrorMessage e: p.errors()) {
System.err.println(e);
......@@ -50,8 +53,9 @@ public class Compiler {
String absPathExclExt = absPath.substring(0, absPath.lastIndexOf('.'));
writeToFile(absPathExclExt + "Gen.ast", p.generateAbstractGrammar());
writeToFile(absPathExclExt + "Gen.jadd", p.generateAspect());
}
else {
} else if (optionPrintAST.isSet()) {
System.out.println(p.dumpTree());
} else {
System.out.println(p.generateAbstractGrammar());
System.out.println(p.generateAspect());
}
......@@ -60,7 +64,7 @@ public class Compiler {
protected void writeToFile(String filename, String str) {
try {
PrintWriter writer = new PrintWriter(filename, "UTF-8");
PrintWriter writer = new PrintWriter(filename);
writer.print(str);
writer.close();
} catch (Exception e) {
......@@ -70,7 +74,8 @@ public class Compiler {
}
protected void addOptions() {
optionWriteToFile = addOption(new FlagOption("file", "write output to file"));
optionWriteToFile = addOption(new FlagOption("file", "write output to files <filename>Gen.ast and <filename>Gen.jadd"));
optionPrintAST = addOption(new FlagOption("ast", "print AST"));
}
protected <OptionType extends Option<?>> OptionType addOption(OptionType option) {
......@@ -101,24 +106,19 @@ public class Compiler {
System.err.println("Parse error in file " + file);
System.err.println(e.getMessage());
System.exit(1);
} /*catch (ScannerError e) {
System.err.println("Scanner error in file " + file);
System.err.println(e.getMessage());
System.exit(1);
}*/
}
return null;
}
protected void error(String message) {
System.err.println("Error: " + message);
System.err.println();
System.err.println("Usage: java -jar relast-compiler.jar <filename> [--option1] [--option2=value] ... ");
System.err.println("Options:");
System.err.print(commandLine.printOptionHelp());
System.exit(1);
}
private void showUsageAndExit() {
//System.out.println("Usage: java -jar bloqqi-compiler.jar [--option1] [--option2=value] ... <filename1> [filename2] [filename3] ...");
//System.exit(1);
}
public static void main(String[] args) {
try {
new Compiler(args);
......
all: compile run check-idempotent
compile:
(cd .. && ant jar)
java -jar ../relast-compiler.jar All.relast --file
java -jar ../tools/jastadd2.jar --package=AST AllGen.ast AllGen.jadd Utils.jadd
run:
javac AST/*.java Test.java
java Test
check-idempotent:
java -jar ../relast-compiler.jar AllGen.ast --file
diff AllGen.ast AllGenGen.ast
all:
cd ../ && ant jar
cd valid && make test
cd errors && make test
\ No newline at end of file
Errors:
Line 5, column 5: Role name missing for type 'A'
Line 6, column 15: Role name missing for type 'B'
Line 7, column 12: The target of a directed relation cannot have a role name
Line 8, column 13: The target of a directed relation may only have multiplicity 1
Program ::= A* B*;
A;
B;
rel A -> B;
rel A.bs* <-> B*;
rel A.b -> B.b;
rel A.b2 -> B*;
all: build-jar test
build-jar:
(cd ../../ && ant jar)
test:
java -jar ../../relast-compiler.jar Errors.relast 2> Errors.out || true
diff Errors.out Errors.expected
\ No newline at end of file
all: build-jar test
test: compile run check-idempotent
build-jar:
(cd ../../ && ant jar)
compile:
java -jar ../../relast-compiler.jar All.relast --file
java -jar ../../tools/jastadd2.jar --package=AST AllGen.ast AllGen.jadd Utils.jadd
run:
javac AST/*.java Test.java
java Test
check-idempotent:
java -jar ../../relast-compiler.jar AllGen.ast --file
diff AllGen.ast AllGenGen.ast
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