Search in sources :

Example 36 with PExpression

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

the class RulesLanguageExceptionTest method testUnkownExpressionOperatorException.

@Test(expected = AssertionError.class)
public void testUnkownExpressionOperatorException() throws Exception {
    AOperatorExpression operator = new AOperatorExpression(new TKwExpressionOperator("foo"), new ArrayList<PExpression>());
    RulesMachineChecker rulesMachineVisitor = new RulesMachineChecker(null, null, null, null);
    operator.apply(rulesMachineVisitor);
}
Also used : AOperatorExpression(de.be4.classicalb.core.parser.node.AOperatorExpression) TKwExpressionOperator(de.be4.classicalb.core.parser.node.TKwExpressionOperator) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 37 with PExpression

use of de.be4.classicalb.core.parser.node.PExpression in project prob2 by bendisposto.

the class ContextTranslator method processConstants.

private List<PContextClause> processConstants() {
    List<PContextClause> constants = new ArrayList<>();
    List<PExpression> concrete = new ArrayList<>();
    List<PExpression> abstractC = new ArrayList<>();
    for (EventBConstant eventBConstant : context.getConstants()) {
        if (eventBConstant.isAbstract()) {
            abstractC.add((PExpression) ((EventB) eventBConstant.getExpression()).getAst());
        } else {
            concrete.add((PExpression) ((EventB) eventBConstant.getExpression()).getAst());
        }
    }
    constants.add(new AConstantsContextClause(concrete));
    constants.add(new AAbstractConstantsContextClause(abstractC));
    return constants;
}
Also used : AConstantsContextClause(de.be4.classicalb.core.parser.node.AConstantsContextClause) EventB(de.prob.animator.domainobjects.EventB) ArrayList(java.util.ArrayList) EventBConstant(de.prob.model.eventb.EventBConstant) PExpression(de.be4.classicalb.core.parser.node.PExpression) PContextClause(de.be4.classicalb.core.parser.node.PContextClause) AAbstractConstantsContextClause(de.be4.classicalb.core.parser.node.AAbstractConstantsContextClause)

Example 38 with PExpression

use of de.be4.classicalb.core.parser.node.PExpression 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;
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) Start(de.be4.classicalb.core.parser.node.Start)

Example 39 with PExpression

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

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

the class RulesLanguageExceptionTest method testUnkownPredicateOperatorException.

@Test(expected = AssertionError.class)
public void testUnkownPredicateOperatorException() throws Exception {
    AOperatorPredicate operator = new AOperatorPredicate(new TKwPredicateOperator("foo"), new ArrayList<PExpression>());
    RulesMachineChecker rulesMachineVisitor = new RulesMachineChecker(null, null, null, null);
    operator.apply(rulesMachineVisitor);
}
Also used : AOperatorPredicate(de.be4.classicalb.core.parser.node.AOperatorPredicate) TKwPredicateOperator(de.be4.classicalb.core.parser.node.TKwPredicateOperator) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Aggregations

PExpression (de.be4.classicalb.core.parser.node.PExpression)50 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)28 ArrayList (java.util.ArrayList)27 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)21 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 Test (org.junit.Test)6 Node (de.be4.classicalb.core.parser.node.Node)5 LinkedList (java.util.LinkedList)5 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)4 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)4 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)3 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 BParser (de.be4.classicalb.core.parser.BParser)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)2 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)2