Search in sources :

Example 21 with BParser

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

the class PositionAspectTest method testSimpleNode.

@Test
public void testSimpleNode() throws Exception {
    final String testMachine = "#EXPRESSION x";
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, true);
    final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
    final SourcePosition startPos = expression.getStartPos();
    final SourcePosition endPos = expression.getEndPos();
    assertNotNull(startNode);
    assertNotNull(endPos);
    assertEquals(1, startPos.getLine());
    assertEquals(13, startPos.getPos());
    assertEquals(1, endPos.getLine());
    assertEquals(14, endPos.getPos());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) Start(de.be4.classicalb.core.parser.node.Start) SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) BParser(de.be4.classicalb.core.parser.BParser) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 22 with BParser

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

the class DefinitionFilesTest method testCircleReference.

/*
	 * test circles references between def files
	 */
@Test
public void testCircleReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile3\"\nEND";
    final BParser parser = new BParser("testcase");
    try {
        parser.parse(testMachine, false, this);
        fail("Expected PreParseException missing");
    } catch (final BCompoundException e) {
        assertTrue(e.getCause() instanceof PreParseException);
    }
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 23 with BParser

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

the class DefinitionFilesTest method testDefCaching.

@Test
public void testDefCaching() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile1\"; \"DefFile2\"\nEND";
    final BParser parser = new BParser("testcase");
    final CountingDefinitionFileProvider provider = new CountingDefinitionFileProvider();
    parser.parse(testMachine, false, provider);
    assertEquals(4, provider.getStoredCounter);
    assertEquals(2, provider.storeCounter);
    assertEquals(2, provider.getContentCounter);
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 24 with BParser

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

the class DefinitionFilesTest method testNonCircleReference.

/*
	 * test circles references between def files
	 */
@Test
public void testNonCircleReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile5\";\n\"DefFile6\"\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, false, this);
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 25 with BParser

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

the class DefinitionFilesTest method testRecursiveReference.

// TODO test two files
/*
	 * test recursive references from def file to def file
	 */
@Test
public void testRecursiveReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile1\"; def1 == xx; def02 == aa\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, false, 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);
    String ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def1.getRhs()).getIdentifier());
    assertEquals("xx", ident);
    final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
    assertEquals("def2", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def2.getRhs()).getIdentifier());
    assertEquals("yy", ident);
    final AExpressionDefinitionDefinition def3 = (AExpressionDefinitionDefinition) definitions.getDefinition("def3");
    assertEquals("def3", def3.getName().getText());
    assertEquals(0, def3.getParameters().size());
    assertTrue(def3.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def3.getRhs()).getIdentifier());
    // definition in outer def file should overwrite the one in referenced
    // def file
    assertEquals("bb", ident);
}
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)

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