use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForCommentBetweenDuplicateAnd.
@Test
public void checkForCommentBetweenDuplicateAnd() throws Exception {
String s = "MACHINE Definitions\nPROPERTIES 1=1 & /* comment */\n & 2 = 2 END";
try {
getTreeAsString(s);
fail("Duplicate & was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("& &"));
final BLexerException ex = (BLexerException) e.getCause();
// checking the position of the second &
assertEquals(3, ex.getLastLine());
assertEquals(2, ex.getLastPos());
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateDefinitionClause.
@Test
public void checkForDublicateDefinitionClause() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo == 1\n CONSTANTS k \n DEFINITIONS\n bar == 1 \nEND";
try {
getTreeAsString(s);
fail("Duplicate 'DEFINITION' clause was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("[5,2] Clause 'DEFINITIONS' is used more than once"));
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateAndInDefinitionsClause.
@Test
public void checkForDublicateAndInDefinitionsClause() throws Exception {
String s = "MACHINE Definitions\nDEFINITIONS\n foo == 1=1 && 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("[3,14]"));
assertTrue(e.getMessage().contains("& &"));
}
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class SatProblem method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
final BParser parser = new BParser("testcase");
Start ast = parser.eparse(testMachine, new Definitions());
final Ast2String ast2String = new Ast2String();
ast.apply(ast2String);
final String string = ast2String.toString();
return string;
}
use of de.be4.classicalb.core.parser.Definitions in project probparsers by bendisposto.
the class PragmaTest method testLexer.
@Test
public void testLexer() throws Exception {
// String input = "/*@ generated */ MACHINE foo(x) \n"
// + "/* look at me. */ \n"
// + "DEFINITIONS \n"
// + " /*@ conversion */ foo(m) == m \n"
// + "PROPERTIES \n"
// + "/*@ label foo */ \n"
// + "/*@ label bar */ \n"
// + "x = /*@ symbolic */ {y|->z| y < z } \n"
// + "/*@ desc prop */ \n"
// + "SETS A;B={a,b} /*@ desc trololo !!! */;C END";
// String input =
// "MACHINE foo PROPERTIES /*@ label foo */ x = /*@ symbolic */ {y|->z|
// y < z } END";
String input = "MACHINE foo CONSTANTS c /*@ desc konstante nummero uno */ PROPERTIES c = 5 VARIABLES x /*@ desc Hallo du variable */ INVARIANT x=1 INITIALISATION x:= 1 END";
BLexer lex = new BLexer(new PushbackReader(new StringReader(input), 500));
Token t;
while (!((t = lex.next()) instanceof EOF)) {
System.out.print(t.getClass().getSimpleName() + "(" + t.getText() + ")");
System.out.print(" ");
}
BParser p = new BParser();
System.out.println("\n" + input);
Start ast = p.parse(input, false);
ASTPrinter pr = new ASTPrinter();
ast.apply(pr);
System.out.println(printAST(ast));
}
Aggregations