Search in sources :

Example 31 with BCompoundException

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

the class DefinitionsTest method testExprOrSubstWParams3.

@Test
public void testExprOrSubstWParams3() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=PRE defExpr(x)=42 THEN defExpr(x) END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting substitution here but found definition with type 'Expression'", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 32 with BCompoundException

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

the class DefinitionsTest method testUnparsableRhs.

@Test
public void testUnparsableRhs() {
    final String testMachine = "MACHINE Test\nDEFINITIONS def_expr1 == 42 < \n OPERATIONS op = PRE def_expr1 THEN skip END END";
    try {
        getTreeAsString(testMachine);
        fail("Was expecting BParseException");
    } catch (final BCompoundException e) {
        System.out.println(e.getLocalizedMessage());
    // IGNORE is expected
    }
}
Also used : Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 33 with BCompoundException

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

the class IfThenElseExpressionTest 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 34 with BCompoundException

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

the class Helpers method parseFile2.

public static String parseFile2(String filename) throws IOException {
    final File machineFile = new File(filename);
    final BParser parser = new BParser(machineFile.getAbsolutePath());
    Start tree;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    try {
        tree = parser.parseFile(machineFile, false);
        PrintStream printStream = new PrintStream(output);
        BParser.printASTasProlog(printStream, parser, machineFile, tree, new ParsingBehaviour(), parser.getContentProvider());
        output.close();
        return output.toString();
    } catch (BCompoundException e) {
        e.printStackTrace();
        PrologExceptionPrinter.printException(output, e);
        return output.toString();
    }
}
Also used : PrintStream(java.io.PrintStream) Start(de.be4.classicalb.core.parser.node.Start) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 35 with BCompoundException

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

the class Helpers method getMachineAsPrologTerm.

public static String getMachineAsPrologTerm(String input) {
    final BParser parser = new BParser("Test");
    Start start;
    try {
        start = parser.parse(input, true);
    } catch (BCompoundException e) {
        throw new RuntimeException(e);
    }
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    final IPrologTermOutput pout = new PrologTermOutput(output, false);
    printAsProlog(start, pout);
    return output.toString();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput)

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