Search in sources :

Example 6 with AExpressionParseUnit

use of de.be4.classicalb.core.parser.node.AExpressionParseUnit 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 7 with AExpressionParseUnit

use of de.be4.classicalb.core.parser.node.AExpressionParseUnit 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

AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)7 Start (de.be4.classicalb.core.parser.node.Start)6 Test (org.junit.Test)5 AAddExpression (de.be4.classicalb.core.parser.node.AAddExpression)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 BParser (de.be4.classicalb.core.parser.BParser)2 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 SourcePosition (de.hhu.stups.sablecc.patch.SourcePosition)2 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)1 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)1 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)1 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)1 APredicateParseUnit (de.be4.classicalb.core.parser.node.APredicateParseUnit)1 PParseUnit (de.be4.classicalb.core.parser.node.PParseUnit)1 TIntegerLiteral (de.be4.classicalb.core.parser.node.TIntegerLiteral)1 LexerException (de.be4.classicalb.core.preparser.lexer.LexerException)1 ParserException (de.be4.classicalb.core.preparser.parser.ParserException)1 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)1 IOException (java.io.IOException)1