Search in sources :

Example 46 with BParser

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

the class PositionAspectTest method testComposedNode.

@Test
public void testComposedNode() throws Exception {
    final String testMachine = "#EXPRESSION x+1";
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, true);
    // test top node
    final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
    SourcePosition startPos = expression.getStartPos();
    SourcePosition endPos = expression.getEndPos();
    assertNotNull(startNode);
    assertNotNull(endPos);
    assertEquals(1, startPos.getLine());
    assertEquals(13, startPos.getPos());
    assertEquals(1, endPos.getLine());
    assertEquals(16, endPos.getPos());
    // test left child: 13-14
    final PExpression leftExpr = ((AAddExpression) expression).getLeft();
    startPos = leftExpr.getStartPos();
    endPos = leftExpr.getEndPos();
    assertNotNull(startNode);
    assertNotNull(endPos);
    assertEquals(1, startPos.getLine());
    assertEquals(13, startPos.getPos());
    assertEquals(1, endPos.getLine());
    assertEquals(14, endPos.getPos());
    // test right child: 15-16
    final PExpression rightExpr = ((AAddExpression) expression).getRight();
    startPos = rightExpr.getStartPos();
    endPos = rightExpr.getEndPos();
    assertNotNull(startNode);
    assertNotNull(endPos);
    assertEquals(1, startPos.getLine());
    assertEquals(15, startPos.getPos());
    assertEquals(1, endPos.getLine());
    assertEquals(16, endPos.getPos());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) 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 47 with BParser

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

the class PositionAspectTest method testNodeSubclassOfPositionedNode.

@Test
public void testNodeSubclassOfPositionedNode() throws Exception {
    final String testMachine = "#EXPRESSION 1+2";
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, true);
    assertTrue(startNode instanceof PositionedNode);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) Test(org.junit.Test)

Example 48 with BParser

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

the class ByteOrderMarkTests method testParsable.

@Test
public void testParsable() throws Exception {
    final BParser parser = new BParser(machine.getName());
    Start start = parser.parseFile(machine, false);
    start.apply(new PositionTester());
    assertNotNull(start);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) AbstractParseMachineTest(util.AbstractParseMachineTest) Test(org.junit.Test)

Example 49 with BParser

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

the class DefinitionFilesTest method testNotExistingFile.

@Test
public void testNotExistingFile() {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile\"; def1 == xx\nEND";
    try {
        new BParser("testcase").parse(testMachine, false, new PlainFileContentProvider());
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
    // EXPECTED
    }
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) PlainFileContentProvider(de.be4.classicalb.core.parser.PlainFileContentProvider) Test(org.junit.Test)

Example 50 with BParser

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

the class DefinitionFilesTest method testRealFiles.

/*
	 * test with real files
	 */
@Test
public void testRealFiles() throws Exception {
    final BParser parser = new BParser("testcase");
    File machine = new File("src/test/resources/parsable/DefinitionFileTest.mch");
    parser.parseFile(machine, false);
    final IDefinitions definitions = parser.getDefinitions();
    final APredicateDefinitionDefinition def1 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD2");
    assertEquals("GRD2", def1.getName().getText());
    assertEquals(0, def1.getParameters().size());
    assertTrue(def1.getRhs() instanceof PPredicate);
    final APredicateDefinitionDefinition def2 = (APredicateDefinitionDefinition) definitions.getDefinition("GRD1");
    assertEquals("GRD1", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof PPredicate);
}
Also used : APredicateDefinitionDefinition(de.be4.classicalb.core.parser.node.APredicateDefinitionDefinition) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) BParser(de.be4.classicalb.core.parser.BParser) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) File(java.io.File) 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