Search in sources :

Example 1 with AMachineHeader

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

the class MachineContext method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    this.header = node;
    if (machineName == null) {
        List<TIdentifierLiteral> nameList = new ArrayList<TIdentifierLiteral>(node.getName());
        this.machineName = Utils.getTIdentifierListAsString(nameList);
    }
    List<PExpression> copy = new ArrayList<PExpression>(node.getParameters());
    for (PExpression e : copy) {
        AIdentifierExpression p = (AIdentifierExpression) e;
        String name = Utils.getTIdentifierListAsString(p.getIdentifier());
        exist(p.getIdentifier());
        if (Character.isUpperCase(name.charAt(0))) {
            this.machineSetParameter.put(name, p);
        } else {
            this.machineScalarParameter.put(name, p);
        }
    }
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 2 with AMachineHeader

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

the class CreateFreetypeTest method createMachine.

private Start createMachine(String name) {
    final AFreetypesMachineClause freetypes = createFreetype();
    final AConstantsMachineClause variables = new AConstantsMachineClause(createIdentifiers(VAR_NAME));
    final AMemberPredicate member = new AMemberPredicate(createIdentifier(VAR_NAME), new APowSubsetExpression(createIdentifier(FREETYPE_NAME)));
    final AInvariantMachineClause inv = new AInvariantMachineClause(member);
    final AInitialisationMachineClause init = new AInitialisationMachineClause(createAssignment(VAR_NAME, new AEmptySetExpression()));
    final AOperationsMachineClause operations = createOperations();
    final AMachineHeader header = new AMachineHeader(createIdLits(name), EMPTY_EXPRS);
    final AAbstractMachineParseUnit machine = new AAbstractMachineParseUnit(new AMachineMachineVariant(), header, Arrays.asList(freetypes, variables, inv, init, operations));
    return new Start(machine, new EOF());
}
Also used : AMachineMachineVariant(de.be4.classicalb.core.parser.node.AMachineMachineVariant) AInitialisationMachineClause(de.be4.classicalb.core.parser.node.AInitialisationMachineClause) AMachineHeader(de.be4.classicalb.core.parser.node.AMachineHeader) AConstantsMachineClause(de.be4.classicalb.core.parser.node.AConstantsMachineClause) Start(de.be4.classicalb.core.parser.node.Start) AMemberPredicate(de.be4.classicalb.core.parser.node.AMemberPredicate) AAbstractMachineParseUnit(de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit) AOperationsMachineClause(de.be4.classicalb.core.parser.node.AOperationsMachineClause) AInvariantMachineClause(de.be4.classicalb.core.parser.node.AInvariantMachineClause) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AEmptySetExpression(de.be4.classicalb.core.parser.node.AEmptySetExpression) EOF(de.be4.classicalb.core.parser.node.EOF)

Example 3 with AMachineHeader

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

the class RulesMachineChecker method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    if (!node.getParameters().isEmpty()) {
        errorList.add(new CheckException("A RULES_MACHINE must not have any machine parameters", node));
    }
    LinkedList<TIdentifierLiteral> nameList = node.getName();
    if (nameList.size() > 1) {
        errorList.add(new CheckException("Renaming of a RULES_MACHINE name is not allowed.", node));
    }
    this.nameLiteral = nameList.get(0);
    this.machineName = nameLiteral.getText();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 4 with AMachineHeader

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

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

the class ReferencedMachines method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    machineName = Utils.getTIdentifierListAsString(node.getName());
    final String fileNameWithoutExtension = Utils.getFileWithoutExtension(mainFile.getName());
    if (isMachineNameMustMatchFileName && !machineName.equals(fileNameWithoutExtension)) {
        CheckException ch = new CheckException(String.format("Machine name does not match the file name: '%s' vs '%s'", machineName, fileNameWithoutExtension), node);
        throw new VisitorException(ch);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)3 AAbstractMachineParseUnit (de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit)2 AMachineHeader (de.be4.classicalb.core.parser.node.AMachineHeader)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 Start (de.be4.classicalb.core.parser.node.Start)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)2 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 AConstantsMachineClause (de.be4.classicalb.core.parser.node.AConstantsMachineClause)1 AEmptySetExpression (de.be4.classicalb.core.parser.node.AEmptySetExpression)1 AFreetypesMachineClause (de.be4.classicalb.core.parser.node.AFreetypesMachineClause)1 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 AInitialisationMachineClause (de.be4.classicalb.core.parser.node.AInitialisationMachineClause)1 AInvariantMachineClause (de.be4.classicalb.core.parser.node.AInvariantMachineClause)1 AMachineMachineVariant (de.be4.classicalb.core.parser.node.AMachineMachineVariant)1 AMemberPredicate (de.be4.classicalb.core.parser.node.AMemberPredicate)1 AOperationsMachineClause (de.be4.classicalb.core.parser.node.AOperationsMachineClause)1 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)1 EOF (de.be4.classicalb.core.parser.node.EOF)1 PMachineClause (de.be4.classicalb.core.parser.node.PMachineClause)1