use of de.be4.classicalb.core.parser.node.AAddExpression in project probparsers by bendisposto.
the class SourcePositionsTest method testAddExpression.
@Test
public void testAddExpression() throws Exception {
final String testMachine = "#EXPRESSION xx + 5";
final Start result = getAst(testMachine);
final AExpressionParseUnit exprParseUnit = (AExpressionParseUnit) result.getPParseUnit();
assertEquals(1, exprParseUnit.getStartPos().getLine());
assertEquals(1, exprParseUnit.getStartPos().getPos());
assertEquals(1, exprParseUnit.getEndPos().getLine());
assertEquals(19, exprParseUnit.getEndPos().getPos());
final AAddExpression addExpression = (AAddExpression) exprParseUnit.getExpression();
assertEquals(1, addExpression.getStartPos().getLine());
assertEquals(13, addExpression.getStartPos().getPos());
assertEquals(1, addExpression.getEndPos().getLine());
assertEquals(19, addExpression.getEndPos().getPos());
final AIdentifierExpression varExpression = (AIdentifierExpression) addExpression.getLeft();
assertEquals(1, varExpression.getStartPos().getLine());
assertEquals(13, varExpression.getStartPos().getPos());
assertEquals(1, varExpression.getEndPos().getLine());
assertEquals(15, varExpression.getEndPos().getPos());
final AIntegerExpression intExpression = (AIntegerExpression) addExpression.getRight();
assertEquals(1, intExpression.getStartPos().getLine());
assertEquals(18, intExpression.getStartPos().getPos());
assertEquals(1, intExpression.getEndPos().getLine());
assertEquals(19, intExpression.getEndPos().getPos());
}
use of de.be4.classicalb.core.parser.node.AAddExpression 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.AAddExpression in project probparsers by bendisposto.
the class SourcePositionsTest method testTokenAsPositionedNode.
@Test
public void testTokenAsPositionedNode() throws Exception {
final String testMachine = "#EXPRESSION xx + 5";
final Start result = getAst(testMachine);
final AExpressionParseUnit exprParseUnit = (AExpressionParseUnit) result.getPParseUnit();
final AAddExpression addExpression = (AAddExpression) exprParseUnit.getExpression();
final AIntegerExpression intExpression = (AIntegerExpression) addExpression.getRight();
assertTrue(intExpression instanceof PositionedNode);
final PositionedNode intNode = (PositionedNode) intExpression;
assertNotNull(intNode.getStartPos());
assertNotNull(intNode.getEndPos());
final TIntegerLiteral intLiteral = intExpression.getLiteral();
assertTrue(intLiteral instanceof PositionedNode);
final PositionedNode posNode = (PositionedNode) intLiteral;
assertNotNull(posNode.getStartPos());
assertNotNull(posNode.getEndPos());
}
use of de.be4.classicalb.core.parser.node.AAddExpression in project probparsers by bendisposto.
the class SourcePositionsTest method testComment1.
@Test
public void testComment1() throws Exception {
final String testMachine = "#EXPRESSION xx /* comment */ + 5";
final Start result = getAst(testMachine);
final AExpressionParseUnit exprParseUnit = (AExpressionParseUnit) result.getPParseUnit();
final AAddExpression addExpression = (AAddExpression) exprParseUnit.getExpression();
final AIntegerExpression intExpression = (AIntegerExpression) addExpression.getRight();
assertEquals(1, intExpression.getStartPos().getLine());
assertEquals(32, intExpression.getStartPos().getPos());
assertEquals(1, intExpression.getEndPos().getLine());
assertEquals(testMachine.length() + 1, intExpression.getEndPos().getPos());
}
Aggregations