Search in sources :

Example 41 with BCompoundException

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

the class ParseTestUtil method parse.

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

Example 42 with BCompoundException

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

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

the class DefinitionsOrderTest method testReordered.

@Test
public void testReordered() throws IOException, BCompoundException {
    machine = new File(PATH + "DefinitionsOccurReordered.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 44 with BCompoundException

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

the class ErrorMessagesTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    // System.out.println("Parsing \"" + testMachine + "\"");
    final BParser parser = new BParser("testcase");
    parser.getOptions().setGrammar(RulesGrammar.getInstance());
    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(string);
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 45 with BCompoundException

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

the class ErrorMessagesTest method testKeywordAsIdentifierInConstantsClause.

@Test
public void testKeywordAsIdentifierInConstantsClause() throws Exception {
    final String testMachine = "MACHINE Test CONSTANTS right PROPERTIES right = 1 END";
    try {
        getTreeAsString(testMachine);
        fail("Invalid identifier not detected");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        BParseException e1 = (BParseException) e.getFirstException().getCause();
        assertTrue(e1.getToken().getText().equals("right"));
    }
}
Also used : BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) 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