Search in sources :

Example 46 with BCompoundException

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

the class ExploreSourcePositionTest method test.

@Test
public void test() throws BCompoundException, IOException {
    final BParser parser = new BParser("m");
    Start parse = parser.parseFile(new File("src/test/resources/LabelTest.mch"), false);
    parse.apply(new ASTPrinter());
    assertTrue(true);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) File(java.io.File) Test(org.junit.Test)

Example 47 with BCompoundException

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

the class PrimedIdentifierTest method testPrimedIdentifiersInQuantifiers.

@Test
public void testPrimedIdentifiersInQuantifiers() throws BCompoundException {
    final String testMachine = "#PREDICATE !a$0.(a$0=5 => b=6)";
    try {
        getTreeAsString(testMachine);
        fail("exception expected");
    } catch (BCompoundException e) {
        assertTrue(e.getCause() instanceof BParseException);
    // ok
    }
}
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)

Example 48 with BCompoundException

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

the class PrimedIdentifierTest method testRestrictedUsage.

@Test
public void testRestrictedUsage() {
    final String testMachine = "#SUBSTITUTION x : (x = x$5)";
    try {
        getTreeAsString(testMachine);
        fail("exception expected");
    } catch (BCompoundException e) {
        assertTrue(e.getFirstException().getCause() instanceof CheckException);
    // ok
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 49 with BCompoundException

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

the class StringLiteralNotClosedTest method testStringLiteralNotClosedLongString.

@Test
public void testStringLiteralNotClosedLongString() {
    final String testMachine = "MACHINE Test CONSTANTS the_string PROPERTIES the_string = \"not closed" + randomString(100) + "END";
    try {
        getTreeAsString(testMachine);
        fail("Exception did not occur");
    } catch (BCompoundException e) {
        System.out.println(e.getCause());
        assertTrue(e.getCause() instanceof PreParseException);
        assertTrue(e.getLocalizedMessage().contains("Unknown token:"));
    }
}
Also used : Ast2String(util.Ast2String) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 50 with BCompoundException

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

the class SatProblem method getTreeAsStringOrg.

private String getTreeAsStringOrg(final String testMachine) throws BCompoundException {
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, false);
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    final String string = ast2String.toString();
    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)

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