Search in sources :

Example 51 with BParser

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

the class DefinitionFilesTest method testOneDefinitionFile.

@Test
public void testOneDefinitionFile() throws BCompoundException {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile\"; def1 == xx\nINVARIANT def2 = def3\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, true, this);
    final IDefinitions definitions = parser.getDefinitions();
    final AExpressionDefinitionDefinition def1 = (AExpressionDefinitionDefinition) definitions.getDefinition("def1");
    assertEquals("def1", def1.getName().getText());
    assertEquals(0, def1.getParameters().size());
    assertTrue(def1.getRhs() instanceof AIdentifierExpression);
    final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
    assertEquals("def2", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof AIdentifierExpression);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 52 with BParser

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

the class DefinitionsOrderTest method testLinearOrder.

@Test
public void testLinearOrder() throws IOException, BCompoundException {
    machine = new File(PATH + "DefinitionsOccurInLinearOrder.mch");
    final BParser parser = new BParser(machine.getName());
    Start start = parser.parseFile(machine, false);
    assertNotNull(start);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) Test(org.junit.Test)

Example 53 with BParser

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

the class StructuralTest method testClause1.

@Test
public void testClause1() 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);
    assertNotNull(startNode);
// TODO more tests
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Test(org.junit.Test)

Example 54 with BParser

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

the class StructuralTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    // System.out.println("Parsing: \"" + testMachine + "\":");
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, false);
    // startNode.apply(new ASTPrinter());
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    final String string = ast2String.toString();
    // System.out.println();
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 55 with BParser

use of de.be4.classicalb.core.parser.BParser 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)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)63 BParser (de.be4.classicalb.core.parser.BParser)53 Test (org.junit.Test)39 File (java.io.File)23 Ast2String (util.Ast2String)21 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)18 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 PrintStream (java.io.PrintStream)7 AbstractParseMachineTest (util.AbstractParseMachineTest)7 IOException (java.io.IOException)6 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)5 ClassicalBModel (de.prob.model.classicalb.ClassicalBModel)4 OutputStream (java.io.OutputStream)4 BLexer (de.be4.classicalb.core.parser.BLexer)3 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 EOF (de.be4.classicalb.core.parser.node.EOF)3 Token (de.be4.classicalb.core.parser.node.Token)3 ProBError (de.prob.exception.ProBError)3