Search in sources :

Example 6 with AIntegerExpression

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

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

Example 8 with AIntegerExpression

use of de.be4.classicalb.core.parser.node.AIntegerExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkSucceededRuleErrorTypeOperator.

private void checkSucceededRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
    if (arguments.size() != 2) {
        this.errorList.add(new CheckException("The SUCCEEDED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
        return;
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of SUCCEEDED_RULE_ERROR_TYPE must be an identifier.", node));
        return;
    }
    PExpression secondArg = node.getIdentifiers().get(1);
    if (!(secondArg instanceof AIntegerExpression)) {
        this.errorList.add(new CheckException("The second argument of SUCCEEDED_RULE_ERROR_TYPE must be an integer value.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
    return;
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)7 Test (org.junit.Test)5 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)4 AAddExpression (de.be4.classicalb.core.parser.node.AAddExpression)3 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)3 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 TIntegerLiteral (de.be4.classicalb.core.parser.node.TIntegerLiteral)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 APartitionPredicate (de.be4.classicalb.core.parser.node.APartitionPredicate)1 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)1 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)1 Ast2String (util.Ast2String)1