use of de.be4.classicalb.core.parser.node.Token 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.node.Token in project probparsers by bendisposto.
the class StringLiteralNotClosedTest method testStringLiteralNotClosedShortString.
@Test
public void testStringLiteralNotClosedShortString() {
final String testMachine = "MACHINE Test CONSTANTS the_string PROPERTIES the_string = \"not closed END";
try {
getTreeAsString(testMachine);
fail("Exception did not occur");
} catch (BCompoundException e) {
assertEquals("[1,59] Unknown token: \"not closed END", e.getMessage());
}
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class UnitPragmaTest method testLexer.
@Test
public void testLexer() throws Exception {
String input = "MACHINE UnitPragmaExpressions1 VARIABLES lala, /*@ unit \"10**1 * m**1\" */ xx, /*@ unit \"10**1 * m**1\" */ yy, /*@ unit \"10**2 * m**2\" */ zz, test INVARIANT /*@ label \"lol\" */ lala = \"trololo\" &xx:NAT & yy:NAT & zz:NAT & test:NAT INITIALISATION xx,yy,zz,test:=1,2,3,4 OPERATIONS multiply = zz := xx*yy; add = xx := yy+1; sub = xx := yy-1; type = test := yy 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();
Start ast = p.parse(input, false);
ASTPrinter pr = new ASTPrinter();
ast.apply(pr);
System.out.println(printAST(ast));
}
use of de.be4.classicalb.core.parser.node.Token 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));
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class EventBLexer method endStringToken.
private void endStringToken() throws LexerException {
try {
/*
* Push back current token. We are going to insert our own string
* token into the token stream just before the current token. Reset
* state so that unread token can be recognized again in next lexer
* step.
*/
unread(token);
state = State.NORMAL;
// create text for string token
string.setText(createString());
} catch (final IOException e) {
throw new LexerException("IOException occured: " + e.getLocalizedMessage());
}
token = string;
string = null;
stringBuffer = null;
}
Aggregations