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());
}
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);
}
}
Aggregations