use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class StructuralTest method checkForMissingSemicolon.
@Test
public void checkForMissingSemicolon() throws Exception {
String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip END\n BAR= BEGIN r := xx END\nEND";
try {
getTreeAsString(s);
fail("Missing Semicolon was not detected");
} catch (BCompoundException e) {
final CheckException cause = (CheckException) e.getCause();
Node node = cause.getNodes()[0];
assertEquals(4, node.getStartPos().getLine());
assertEquals(3, node.getStartPos().getPos());
assertTrue(e.getMessage().contains("Semicolon missing"));
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class StructuralTest method checkForInvalidSemicolon.
@Test
public void checkForInvalidSemicolon() throws Exception {
String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip END\n;\nEND";
try {
getTreeAsString(s);
fail("Invalid Semicolon was not detected");
} catch (BCompoundException e) {
final CheckException cause = (CheckException) e.getCause();
Node node = cause.getNodes()[0];
System.out.println(cause.getMessage());
assertEquals(4, node.getStartPos().getLine());
assertEquals(1, node.getStartPos().getPos());
assertTrue(e.getMessage().contains("Invalid semicolon after last operation"));
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateAndInDefinitionsClause2.
@Test
public void checkForDublicateAndInDefinitionsClause2() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n \n 1=1 \n& & 2=2 \nEND";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
// there is no token available, hence the position is in the text
assertTrue(e.getMessage().contains("[6,6]"));
assertTrue(e.getMessage().contains("& &"));
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDuplicateAnd.
@Test
public void checkForDuplicateAnd() throws Exception {
String s = "MACHINE Definitions\nPROPERTIES\n 1=1 &\n & 2 = 2 END";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
final BLexerException ex = (BLexerException) e.getCause();
// checking the position of the second &
assertEquals(4, ex.getLastLine());
assertEquals(2, ex.getLastPos());
}
}
use of de.be4.classicalb.core.parser.exceptions.BCompoundException in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
// System.out.println("Parsing: \"" + testMachine + "\":");
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();
return string;
}
Aggregations