Search in sources :

Example 11 with BCompoundException

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

the class OpPatternTest method checkParser.

private void checkParser(final String description, final String oppattern, final String expected) throws BCompoundException {
    final Start ast = parser.parse(BParser.OPERATION_PATTERN_PREFIX + oppattern, false);
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    final String parsed = ast2String.toString();
    assertEquals(description, "Start(AOppatternParseUnit(" + expected + "))", parsed);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 12 with BCompoundException

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

the class PredicatesTest method testBFalse.

@Test
public void testBFalse() throws BCompoundException {
    parser.getOptions().setRestrictProverExpressions(true);
    try {
        getPredicateAsString("bfalse");
        fail("exception expected");
    } catch (BCompoundException e) {
        assertTrue(e.getFirstException().getCause() instanceof CheckException);
    }
    parser.getOptions().setRestrictProverExpressions(false);
    final String actual = getPredicateAsString("bfalse");
    final String expected = "AFalsityPredicate()";
    assertEquals(expected, actual);
}
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 13 with BCompoundException

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

the class PredicatesTest 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 14 with BCompoundException

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

the class PredicatesTest method testNonIdentifiersInQuantification.

@Test
public void testNonIdentifiersInQuantification() {
    final String testMachine = "#PREDICATE ! a,5. (a=5 => a/=5 )";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception");
    } catch (final BCompoundException e) {
        assertTrue(e.getFirstException().getCause() instanceof BParseException);
    }
}
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 15 with BCompoundException

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

the class PreParser method parse.

public void parse() throws PreParseException, IOException, BException, BCompoundException {
    final PreLexer preLexer = new PreLexer(pushbackReader);
    final Parser preParser = new Parser(preLexer);
    Start rootNode = null;
    try {
        rootNode = preParser.parse();
    } catch (final ParserException e) {
        if (e.getToken() instanceof de.be4.classicalb.core.preparser.node.TDefinitions) {
            final Token errorToken = e.getToken();
            final String message = "[" + errorToken.getLine() + "," + errorToken.getPos() + "] " + "Clause 'DEFINITIONS' is used more than once";
            throw new PreParseException(e.getToken(), message);
        } else {
            throw new PreParseException(e.getToken(), e.getLocalizedMessage());
        }
    } catch (final LexerException e) {
        throw new PreParseException(e.getLocalizedMessage());
    }
    final DefinitionPreCollector collector = new DefinitionPreCollector();
    rootNode.apply(collector);
    evaluateDefinitionFiles(collector.getFileDefinitions());
    List<Token> sortedDefinitionList = sortDefinitionsByTopologicalOrderAndCheckForCycles(collector.getDefinitions());
    evaluateTypes(sortedDefinitionList, collector.getDefinitions());
}
Also used : ParserException(de.be4.classicalb.core.preparser.parser.ParserException) Start(de.be4.classicalb.core.preparser.node.Start) Token(de.be4.classicalb.core.preparser.node.Token) DefinitionPreCollector(de.be4.classicalb.core.parser.analysis.checking.DefinitionPreCollector) Parser(de.be4.classicalb.core.preparser.parser.Parser) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) LexerException(de.be4.classicalb.core.preparser.lexer.LexerException)

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