use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class DefinitionsTest method testDoubleSemicolon.
@Test
public void testDoubleSemicolon() {
final String testMachine = "MACHINE Test\nDEFINITIONS\npt == (PP=TRUE);;\nqt == (QQ=TRUE)\nEND";
try {
getTreeAsString(testMachine);
fail("Expected exception was not thrown");
} catch (final BCompoundException e) {
// IGNORE, is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class DefinitionsTest method testExprOrSubst4.
@Test
public void testExprOrSubst4() {
final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr==g(x)\nOPERATIONS\nop=BEGIN defExpr; a:=defExpr END\nEND";
try {
getTreeAsString(testMachine);
fail("Expected exception was not thrown");
} catch (final BCompoundException e) {
final CheckException cause = (CheckException) e.getCause();
assertEquals("Expecting expression here but found definition with type 'Substitution'", cause.getLocalizedMessage());
// IGNORE, is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class DefinitionsTest method testExprOrSubstWParams4.
@Test
public void testExprOrSubstWParams4() {
final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=BEGIN defExpr(x); a:=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 expression here but found definition with type 'Substitution'", cause.getLocalizedMessage());
// IGNORE, is expected
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class Helpers method getTreeAsString.
public static String getTreeAsString(final String testMachine) throws BCompoundException {
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, false);
// startNode.apply(new ASTPrinter());
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
final String string = ast2String.toString();
// System.out.println(string);
return string;
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class Helpers method parseFile.
public static void parseFile(final String filename) throws IOException, BCompoundException {
final int dot = filename.lastIndexOf('.');
if (dot >= 0) {
final File machineFile = new File(filename);
final String probfilename = filename.substring(0, dot) + ".prob";
BParser parser = new BParser(filename);
Start tree = parser.parseFile(machineFile, false);
final ParsingBehaviour behaviour = new ParsingBehaviour();
behaviour.setVerbose(true);
PrintStream output = new PrintStream(probfilename);
BParser.printASTasProlog(output, parser, machineFile, tree, behaviour, parser.getContentProvider());
output.close();
} else
throw new IllegalArgumentException("Filename '" + filename + "' has no extension");
}
Aggregations