use of de.be4.classicalb.core.parser.node.PMachineClause 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.PMachineClause in project probparsers by bendisposto.
the class StructuralTest method testEmptyMachine.
@Test
public void testEmptyMachine() throws Exception {
final String testMachine = "MACHINE SimplyStructure END";
// System.out.println("Parsing: \"" + testMachine + "\":");
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
final AAbstractMachineParseUnit machine = (AAbstractMachineParseUnit) startNode.getPParseUnit();
final AMachineHeader header = (AMachineHeader) machine.getHeader();
assertEquals("Machine name not as expected", "SimplyStructure", header.getName().get(0).getText());
assertNotNull("Machine header parameter list is null", header.getParameters());
assertTrue("More machine header parameters than expected", header.getParameters().size() == 0);
final LinkedList<PMachineClause> machineClauses = machine.getMachineClauses();
assertNotNull("Machine clause list is null", machineClauses);
assertTrue("More machine clauses than expected", machineClauses.size() == 0);
}
use of de.be4.classicalb.core.parser.node.PMachineClause in project probparsers by bendisposto.
the class ClausesCollector method inAAbstractMachineParseUnit.
@Override
public void inAAbstractMachineParseUnit(final AAbstractMachineParseUnit node) {
super.inAAbstractMachineParseUnit(node);
final LinkedList<PMachineClause> machineClauses = node.getMachineClauses();
for (final Iterator<PMachineClause> iterator = machineClauses.iterator(); iterator.hasNext(); ) {
final PMachineClause clause = iterator.next();
final String className = clause.getClass().getSimpleName();
Set<Node> nodesForclause = availableClauses.get(className);
if (nodesForclause == null) {
nodesForclause = new HashSet<Node>();
}
nodesForclause.add(clause);
availableClauses.put(className, nodesForclause);
}
}
use of de.be4.classicalb.core.parser.node.PMachineClause in project probparsers by bendisposto.
the class MachineContext method caseAAbstractMachineParseUnit.
@Override
public void caseAAbstractMachineParseUnit(AAbstractMachineParseUnit node) {
this.abstractMachineParseUnit = node;
if (node.getVariant() != null) {
node.getVariant().apply(this);
}
if (node.getHeader() != null) {
node.getHeader().apply(this);
}
List<PMachineClause> machineClauses = node.getMachineClauses();
// Sort the machine clauses: declarations clauses first, then
// properties clauses
MachineClauseSorter.sortMachineClauses(start);
for (PMachineClause e : machineClauses) {
e.apply(this);
}
}
Aggregations