Search in sources :

Example 11 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class StructureTest method testIdentifierTick.

@Test
public void testIdentifierTick() throws Exception {
    final Start root = parseInput("machine Mac variables x' y end", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
    final LinkedList<PVariable> variables = parseUnit.getVariables();
    assertEquals(2, variables.size());
    assertEquals("x'", ((AVariable) variables.get(0)).getName().getText());
    assertEquals("y", ((AVariable) variables.get(1)).getName().getText());
}
Also used : AVariable(de.be4.eventb.core.parser.node.AVariable) Start(de.be4.eventb.core.parser.node.Start) PVariable(de.be4.eventb.core.parser.node.PVariable) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 12 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class StructureTest method testWitnessTick.

@Test
public void testWitnessTick() throws Exception {
    final Start root = parseInput("machine WitnessTick\nevents\nevent Eve\nwith\n@x' x' :: NAT\nend\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
    final LinkedList<PEvent> events = parseUnit.getEvents();
    assertEquals(1, events.size());
    final AEvent event = (AEvent) events.get(0);
    final LinkedList<PWitness> witnesses = event.getWitnesses();
    assertEquals(1, witnesses.size());
    assertEquals("x'", ((AWitness) witnesses.get(0)).getName().getText());
}
Also used : Start(de.be4.eventb.core.parser.node.Start) AWitness(de.be4.eventb.core.parser.node.AWitness) PWitness(de.be4.eventb.core.parser.node.PWitness) AEvent(de.be4.eventb.core.parser.node.AEvent) PEvent(de.be4.eventb.core.parser.node.PEvent) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 13 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class LexerTest method testStringVariant.

@Test
public void testStringVariant() throws BException {
    final Start rootNode = parseInput("machine Test\nvariant y-x\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final AVariant variantClause = (AVariant) parseUnit.getVariant();
    assertEquals("y-x", variantClause.getExpression().getText());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) AVariant(de.be4.eventbalg.core.parser.node.AVariant) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 14 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project probparsers by bendisposto.

the class SourcePositionsTest method testGetEndLine.

@Test
public void testGetEndLine() throws Exception {
    final Start root = parser.parse("machine\nTestMachine\n\nvariables\nx\n\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
    assertEquals(7, ((PositionedNode) parseUnit).getEndPos().getLine());
    final LinkedList<PVariable> variables = parseUnit.getVariables();
    assertEquals(5, ((PositionedNode) variables.get(0)).getEndPos().getLine());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) PVariable(de.be4.eventbalg.core.parser.node.PVariable) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 15 with AMachineParseUnit

use of de.be4.eventb.core.parser.node.AMachineParseUnit in project prob2 by bendisposto.

the class ComponentExtractor method caseAMachineParseUnit.

@Override
public void caseAMachineParseUnit(final AMachineParseUnit node) {
    String name = node.getName().getText();
    MachineModifier machineM = new MachineModifier(new EventBMachine(name), typeEnv);
    ModelElementList<Context> seen = new ModelElementList<>();
    for (TIdentifierLiteral contextName : node.getSeenNames()) {
        String cName = contextName.getText();
        AbstractElement context = getContext(cName);
        seen = seen.addElement((Context) context);
    }
    machineM = machineM.setSees(seen);
    if (node.getRefinesNames().size() == 1) {
        String mname = node.getRefinesNames().getFirst().getText();
        EventBMachine machine = getMachine(mname);
        machineM = machineM.setRefines(machine);
    } else if (node.getRefinesNames().size() > 1) {
        throw new IllegalArgumentException("Machines can only refine one abstract machine. Found " + node.getRefinesNames().size() + " refined machines");
    }
    machineM = machineM.addComment(getComment(node.getComments()));
    MachineExtractor mE = new MachineExtractor(machineM, typeEnv);
    node.apply(mE);
    modelM = modelM.addMachine(mE.getMachine());
}
Also used : Context(de.prob.model.eventb.Context) AbstractElement(de.prob.model.representation.AbstractElement) ModelElementList(de.prob.model.representation.ModelElementList) EventBMachine(de.prob.model.eventb.EventBMachine) MachineModifier(de.prob.model.eventb.MachineModifier) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Aggregations

Test (org.junit.Test)28 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)14 Start (de.be4.eventb.core.parser.node.Start)14 AMachineParseUnit (de.be4.eventbalg.core.parser.node.AMachineParseUnit)14 Start (de.be4.eventbalg.core.parser.node.Start)14 TComment (de.be4.eventb.core.parser.node.TComment)6 TComment (de.be4.eventbalg.core.parser.node.TComment)6 StringTokenizer (java.util.StringTokenizer)6 AInvariant (de.be4.eventb.core.parser.node.AInvariant)5 PInvariant (de.be4.eventb.core.parser.node.PInvariant)5 AInvariant (de.be4.eventbalg.core.parser.node.AInvariant)5 PInvariant (de.be4.eventbalg.core.parser.node.PInvariant)5 PVariable (de.be4.eventb.core.parser.node.PVariable)3 PVariable (de.be4.eventbalg.core.parser.node.PVariable)3 AEvent (de.be4.eventb.core.parser.node.AEvent)2 AVariable (de.be4.eventb.core.parser.node.AVariable)2 AEvent (de.be4.eventbalg.core.parser.node.AEvent)2 AVariable (de.be4.eventbalg.core.parser.node.AVariable)2 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)2 AAction (de.be4.eventb.core.parser.node.AAction)1