use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkForInvalidFormula.
@Test
public void checkForInvalidFormula() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n 1+; \nEND";
try {
getTreeAsString(s);
fail("Invalid formula 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("[4,4]"));
}
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkForInvalidFormula3.
@Test
public void checkForInvalidFormula3() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo(xx) == (xx : OBJECTS -->(1..card(OBJECTS))\n; \nEND";
try {
getTreeAsString(s);
fail("Invalid formula 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("[4,1]"));
assertTrue(e.getMessage().contains("expecting: ')'"));
}
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkForInvalidFormula2.
@Test
public void checkForInvalidFormula2() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n 1=; \nEND";
try {
getTreeAsString(s);
fail("Invalid formula 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("[4,4]"));
}
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class EventBLexer method collectMultiLineComment.
private void collectMultiLineComment() throws EventBLexerException {
if (state.equals(State.MULTI_COMMENT)) {
if (token instanceof EOF) {
// tokenList.add(token);
throw new EventBLexerException(token, "Comment not closed");
}
/*
* Starting a new multiline comment, so first token is
* TMultiCommentStart
*/
if (commentStart == null) {
commentStart = (TMultiCommentStart) token;
commentBuffer = new StringBuilder();
token = null;
} else {
// end of comment reached?
if (token instanceof TMultiCommentEnd) {
token = new TComment(commentBuffer.toString(), commentStart.getLine(), commentStart.getPos());
commentStart = null;
commentBuffer = null;
state = State.NORMAL;
} else {
commentBuffer.append(token.getText());
token = null;
}
}
}
}
use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.
the class CtlParser method parseFormula.
protected Start parseFormula(final String formula) throws LtlParseException, IOException {
StringReader reader = new StringReader(formula);
PushbackReader r = new PushbackReader(reader);
Lexer l = new CtlLexer(r);
Parser p = new Parser(l);
Start ast = null;
try {
ast = p.parse();
} catch (ParserException e) {
final UniversalToken token = UniversalToken.createToken(e.getToken());
throw new LtlParseException(token, e.getLocalizedMessage());
} catch (LexerException e) {
throw new LtlParseException(null, e.getLocalizedMessage());
}
return ast;
}
Aggregations