Search in sources :

Example 66 with BCompoundException

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

the class DefinitionsTest method testDoubleSemicolon.

@Test
public void testDoubleSemicolon() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\npt == (PP=TRUE);;\nqt == (QQ=TRUE)\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
    // IGNORE, is expected
    }
}
Also used : Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 67 with BCompoundException

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

the class DefinitionsTest method testExprOrSubst4.

@Test
public void testExprOrSubst4() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr==g(x)\nOPERATIONS\nop=BEGIN defExpr; a:=defExpr END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting expression here but found definition with type 'Substitution'", 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 68 with BCompoundException

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

the class DefinitionsTest method testExprOrSubstWParams4.

@Test
public void testExprOrSubstWParams4() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=BEGIN defExpr(x); a:=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 expression here but found definition with type 'Substitution'", 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 69 with BCompoundException

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

the class Helpers method getTreeAsString.

public static String getTreeAsString(final String testMachine) throws BCompoundException {
    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(string);
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser)

Example 70 with BCompoundException

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

the class Helpers method parseFile.

public static void parseFile(final String filename) throws IOException, BCompoundException {
    final int dot = filename.lastIndexOf('.');
    if (dot >= 0) {
        final File machineFile = new File(filename);
        final String probfilename = filename.substring(0, dot) + ".prob";
        BParser parser = new BParser(filename);
        Start tree = parser.parseFile(machineFile, false);
        final ParsingBehaviour behaviour = new ParsingBehaviour();
        behaviour.setVerbose(true);
        PrintStream output = new PrintStream(probfilename);
        BParser.printASTasProlog(output, parser, machineFile, tree, behaviour, parser.getContentProvider());
        output.close();
    } else
        throw new IllegalArgumentException("Filename '" + filename + "' has no extension");
}
Also used : PrintStream(java.io.PrintStream) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

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