Search in sources :

Example 1 with AAddExpression

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Test(org.junit.Test)

Example 2 with AAddExpression

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) BParser(de.be4.classicalb.core.parser.BParser) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 3 with AAddExpression

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) TIntegerLiteral(de.be4.classicalb.core.parser.node.TIntegerLiteral) Test(org.junit.Test)

Example 4 with AAddExpression

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) Test(org.junit.Test)

Aggregations

AAddExpression (de.be4.classicalb.core.parser.node.AAddExpression)4 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)4 Start (de.be4.classicalb.core.parser.node.Start)4 Test (org.junit.Test)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3 BParser (de.be4.classicalb.core.parser.BParser)1 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 TIntegerLiteral (de.be4.classicalb.core.parser.node.TIntegerLiteral)1 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)1 SourcePosition (de.hhu.stups.sablecc.patch.SourcePosition)1