Search in sources :

Example 21 with BCompoundException

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

the class SubstitutionTest method testInvalidIdentifierListInAnySubstitution.

@Test
public void testInvalidIdentifierListInAnySubstitution() throws BCompoundException {
    final String testMachine = "#SUBSTITUTION ANY (x|->y) WHERE x = 1 & y = 1 THEN skip END ";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception");
    } catch (final BCompoundException e) {
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 22 with BCompoundException

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

the class SubstitutionTest method testRenamedIdentifierInAnySubstitution.

@Test
public void testRenamedIdentifierInAnySubstitution() {
    final String testMachine = "#SUBSTITUTION ANY x.y WHERE x.y = 1 THEN skip END ";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception");
    } catch (final BCompoundException e) {
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 23 with BCompoundException

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

the class DefinitionsErrorsTest method checkForInvalidDefinition.

@Test
public void checkForInvalidDefinition() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEING x :=1 END \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid substitution was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[3,15]"));
        assertTrue(e.getMessage().contains("expecting end of definition"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 24 with BCompoundException

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

the class DefinitionsErrorsTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    // System.out.println("Parsing: \"" + testMachine + "\":");
    final BParser parser = new BParser("testcase");
    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();
    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 25 with BCompoundException

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

the class DefinitionsErrorsTest method checkForInvalidSubstitution.

@Test
public void checkForInvalidSubstitution() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEGIN\n x=1 END \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid substitution was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[4,3]"));
    }
}
Also used : 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