Search in sources :

Example 1 with AVariablesMachineClause

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

the class SourcePositionsTest method testVariablesSourcePositions.

@Test
public void testVariablesSourcePositions() throws Exception {
    final String testMachine = "MACHINE test\n" + "VARIABLES\n" + "  xx,\n" + "    yy\n" + "INVARIANT xx:INT & yy:INT\n" + "INITIALISATION xx,yy:=0,0\n" + "END\n";
    final Start result = getAst(testMachine);
    final AAbstractMachineParseUnit machine = (AAbstractMachineParseUnit) result.getPParseUnit();
    AVariablesMachineClause variables = null;
    for (final PMachineClause clause : machine.getMachineClauses()) {
        if (clause instanceof AVariablesMachineClause) {
            variables = (AVariablesMachineClause) clause;
            break;
        }
    }
    if (variables == null) {
        fail("variables clause not found");
    }
    final LinkedList<PExpression> ids = variables.getIdentifiers();
    assertEquals(2, ids.size());
    final AIdentifierExpression x = (AIdentifierExpression) ids.get(0);
    final AIdentifierExpression y = (AIdentifierExpression) ids.get(1);
    // VARIABLES block
    assertEquals(2, variables.getStartPos().getLine());
    assertEquals(1, variables.getStartPos().getPos());
    assertEquals(4, variables.getEndPos().getLine());
    assertEquals(7, variables.getEndPos().getPos());
    // variable x declaration
    assertEquals(3, x.getStartPos().getLine());
    assertEquals(3, x.getStartPos().getPos());
    assertEquals(3, x.getEndPos().getLine());
    assertEquals(5, x.getEndPos().getPos());
    // variable y declaration
    assertEquals(4, y.getStartPos().getLine());
    assertEquals(5, y.getStartPos().getPos());
    assertEquals(4, y.getEndPos().getLine());
    assertEquals(7, y.getEndPos().getPos());
}
Also used : AVariablesMachineClause(de.be4.classicalb.core.parser.node.AVariablesMachineClause) Start(de.be4.classicalb.core.parser.node.Start) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) AAbstractMachineParseUnit(de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit) PMachineClause(de.be4.classicalb.core.parser.node.PMachineClause) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 2 with AVariablesMachineClause

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

the class MachineContext method caseAVariablesMachineClause.

@Override
public void caseAVariablesMachineClause(AVariablesMachineClause node) {
    List<PExpression> copy = new ArrayList<PExpression>(node.getIdentifiers());
    for (PExpression e : copy) {
        AIdentifierExpression v = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(v.getIdentifier());
        exist(v.getIdentifier());
        variables.put(name, v);
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 AAbstractMachineParseUnit (de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit)1 AVariablesMachineClause (de.be4.classicalb.core.parser.node.AVariablesMachineClause)1 PMachineClause (de.be4.classicalb.core.parser.node.PMachineClause)1 Start (de.be4.classicalb.core.parser.node.Start)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1