use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class DefinitionFilesTest method testNonCircleReference.
/*
* test circles references between def files
*/
@Test
public void testNonCircleReference() throws Exception {
final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile5\";\n\"DefFile6\"\nEND";
final BParser parser = new BParser("testcase");
parser.parse(testMachine, false, this);
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class DefinitionFilesTest method testRecursiveReference.
// TODO test two files
/*
* test recursive references from def file to def file
*/
@Test
public void testRecursiveReference() throws Exception {
final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile1\"; def1 == xx; def02 == aa\nEND";
final BParser parser = new BParser("testcase");
parser.parse(testMachine, false, this);
final IDefinitions definitions = parser.getDefinitions();
final AExpressionDefinitionDefinition def1 = (AExpressionDefinitionDefinition) definitions.getDefinition("def1");
assertEquals("def1", def1.getName().getText());
assertEquals(0, def1.getParameters().size());
assertTrue(def1.getRhs() instanceof AIdentifierExpression);
String ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def1.getRhs()).getIdentifier());
assertEquals("xx", ident);
final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
assertEquals("def2", def2.getName().getText());
assertEquals(0, def2.getParameters().size());
assertTrue(def2.getRhs() instanceof AIdentifierExpression);
ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def2.getRhs()).getIdentifier());
assertEquals("yy", ident);
final AExpressionDefinitionDefinition def3 = (AExpressionDefinitionDefinition) definitions.getDefinition("def3");
assertEquals("def3", def3.getName().getText());
assertEquals(0, def3.getParameters().size());
assertTrue(def3.getRhs() instanceof AIdentifierExpression);
ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def3.getRhs()).getIdentifier());
// definition in outer def file should overwrite the one in referenced
// def file
assertEquals("bb", ident);
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class DefinitionsOrderTest method testReordered.
@Test
public void testReordered() throws IOException, BCompoundException {
machine = new File(PATH + "DefinitionsOccurReordered.mch");
final BParser parser = new BParser(machine.getName());
Start start = parser.parseFile(machine, false);
assertNotNull(start);
}
use of de.be4.eventbalg.core.parser.parser.Parser 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;
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class ErrorMessagesTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
// System.out.println("Parsing \"" + testMachine + "\"");
final BParser parser = new BParser("testcase");
parser.getOptions().setGrammar(RulesGrammar.getInstance());
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;
}
Aggregations