use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class DefinitionsTest method testExprOrSubstWParams3.
@Test
public void testExprOrSubstWParams3() {
final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=PRE defExpr(x)=42 THEN defExpr(x) END\nEND";
try {
getTreeAsString(testMachine);
fail("Expected exception was not thrown");
} catch (final BCompoundException e) {
final CheckException cause = (CheckException) e.getCause();
assertEquals("Expecting substitution here but found definition with type 'Expression'", cause.getLocalizedMessage());
// IGNORE, is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class DefinitionsTest method testUnparsableRhs.
@Test
public void testUnparsableRhs() {
final String testMachine = "MACHINE Test\nDEFINITIONS def_expr1 == 42 < \n OPERATIONS op = PRE def_expr1 THEN skip END END";
try {
getTreeAsString(testMachine);
fail("Was expecting BParseException");
} catch (final BCompoundException e) {
System.out.println(e.getLocalizedMessage());
// IGNORE is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class IfThenElseExpressionTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
final Start startNode = parser.parse(testMachine, false);
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
return ast2String.toString();
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class Helpers method parseFile2.
public static String parseFile2(String filename) throws IOException {
final File machineFile = new File(filename);
final BParser parser = new BParser(machineFile.getAbsolutePath());
Start tree;
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
try {
tree = parser.parseFile(machineFile, false);
PrintStream printStream = new PrintStream(output);
BParser.printASTasProlog(printStream, parser, machineFile, tree, new ParsingBehaviour(), parser.getContentProvider());
output.close();
return output.toString();
} catch (BCompoundException e) {
e.printStackTrace();
PrologExceptionPrinter.printException(output, e);
return output.toString();
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class Helpers method getMachineAsPrologTerm.
public static String getMachineAsPrologTerm(String input) {
final BParser parser = new BParser("Test");
Start start;
try {
start = parser.parse(input, true);
} catch (BCompoundException e) {
throw new RuntimeException(e);
}
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
final IPrologTermOutput pout = new PrologTermOutput(output, false);
printAsProlog(start, pout);
return output.toString();
}
Aggregations