use of de.be4.classicalb.core.parser.node.Node in project prob2 by bendisposto.
the class DomBuilder method createExpressionAST.
private Start createExpressionAST(final PExpression expression) {
Start start = new Start();
AExpressionParseUnit node = new AExpressionParseUnit();
start.setPParseUnit(node);
start.setEOF(EOF);
node.setExpression((PExpression) expression.clone());
node.getExpression().apply(new RenameIdentifiers());
return start;
}
use of de.be4.classicalb.core.parser.node.Node in project prob2 by bendisposto.
the class IdentifierExtractor method union.
public static Set<String> union(final Node... assignments) {
Set<String> union = new HashSet<>();
for (Node assignment : assignments) {
IdentifierExtractor v = new IdentifierExtractor();
assignment.apply(v);
union.addAll(v.getIdentifiers());
}
return union;
}
use of de.be4.classicalb.core.parser.node.Node in project prob2 by bendisposto.
the class EventBParserBase method toPrologTerm.
private static void toPrologTerm(final IPrologTermOutput pto, final Node ast, final boolean wrap, final String wrapper) {
if (wrap) {
pto.openTerm(wrapper);
}
final ASTProlog prolog = new ASTProlog(pto, null);
ast.apply(prolog);
if (wrap) {
pto.closeTerm();
}
}
use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class PositionAspectTest method testComposedNode.
@Test
public void testComposedNode() throws Exception {
final String testMachine = "#EXPRESSION x+1";
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
// test top node
final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
SourcePosition startPos = expression.getStartPos();
SourcePosition endPos = expression.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
// test left child: 13-14
final PExpression leftExpr = ((AAddExpression) expression).getLeft();
startPos = leftExpr.getStartPos();
endPos = leftExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(14, endPos.getPos());
// test right child: 15-16
final PExpression rightExpr = ((AAddExpression) expression).getRight();
startPos = rightExpr.getStartPos();
endPos = rightExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(15, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
}
use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class StructuralTest method checkForInvalidSemicolonBeforeEnd2.
@Test
public void checkForInvalidSemicolonBeforeEnd2() throws Exception {
String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip;skip\n; END\nEND";
try {
getTreeAsString(s);
fail("Invalid Semicolon was not detected");
} catch (BCompoundException e) {
final CheckException cause = (CheckException) e.getCause();
Node node = cause.getNodes()[0];
assertEquals(4, node.getStartPos().getLine());
assertEquals(1, node.getStartPos().getPos());
assertTrue(e.getMessage().contains("Invalid semicolon after last substitution"));
}
}
Aggregations