Search in sources :

Example 1 with PMachineClause

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

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);
}
Also used : AMachineHeader(de.be4.classicalb.core.parser.node.AMachineHeader) Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) AAbstractMachineParseUnit(de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit) PMachineClause(de.be4.classicalb.core.parser.node.PMachineClause) Test(org.junit.Test)

Example 3 with PMachineClause

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);
    }
}
Also used : Node(de.be4.classicalb.core.parser.node.Node) PMachineClause(de.be4.classicalb.core.parser.node.PMachineClause)

Example 4 with PMachineClause

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);
    }
}
Also used : PMachineClause(de.be4.classicalb.core.parser.node.PMachineClause)

Aggregations

PMachineClause (de.be4.classicalb.core.parser.node.PMachineClause)4 AAbstractMachineParseUnit (de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit)2 Start (de.be4.classicalb.core.parser.node.Start)2 Test (org.junit.Test)2 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 AMachineHeader (de.be4.classicalb.core.parser.node.AMachineHeader)1 AVariablesMachineClause (de.be4.classicalb.core.parser.node.AVariablesMachineClause)1 Node (de.be4.classicalb.core.parser.node.Node)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 Ast2String (util.Ast2String)1