Search in sources :

Example 71 with BCompoundException

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

the class Helpers method getPrettyPrint.

public static String getPrettyPrint(final String testMachine) {
    final BParser parser = new BParser("testcase");
    Start startNode;
    try {
        startNode = parser.parse(testMachine, false);
    } catch (BCompoundException e) {
        throw new RuntimeException(e);
    }
    PrettyPrinter pp = new PrettyPrinter();
    startNode.apply(pp);
    return pp.getPrettyPrint();
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 72 with BCompoundException

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

the class LetPredicateTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    final Start startNode = parser.parse(testMachine, false);
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    return ast2String.toString();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String)

Example 73 with BCompoundException

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

the class FilePragmaTest method testFilePragma.

@Test
public void testFilePragma() throws IOException, BCompoundException {
    String PATH = "src/test/resources/pragmas/filePragma/";
    String file = PATH + "Main1.mch";
    File f = new File(file);
    BParser bparser = new BParser();
    Start ast = bparser.parseFile(f, false);
    assertNotNull(ast);
    RecursiveMachineLoader rml = new RecursiveMachineLoader(PATH, bparser.getContentProvider(), new ParsingBehaviour());
    rml.loadAllMachines(f, ast, bparser.getDefinitions());
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) Ast2String(util.Ast2String) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) Test(org.junit.Test)

Example 74 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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 75 with BCompoundException

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

Aggregations

BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)73 Test (org.junit.Test)64 Ast2String (util.Ast2String)62 Start (de.be4.classicalb.core.parser.node.Start)52 BParser (de.be4.classicalb.core.parser.BParser)29 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)19 File (java.io.File)15 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)7 BException (de.be4.classicalb.core.parser.exceptions.BException)7 Helpers.getTreeAsString (util.Helpers.getTreeAsString)7 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)5 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)5 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 Node (de.be4.classicalb.core.parser.node.Node)5 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)4 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)4