Search in sources :

Example 1 with BCompoundException

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

the class LTLFormulaVisitor method parseBPredicate.

private de.be4.classicalb.core.parser.node.Start parseBPredicate(String text) {
    String bPredicate = "#PREDICATE " + text;
    BParser parser = new BParser("Testing");
    de.be4.classicalb.core.parser.node.Start start = null;
    try {
        start = parser.parse(bPredicate, false);
    } catch (BCompoundException e) {
        throw new LTLParseException(e.getMessage());
    }
    return start;
}
Also used : LTLParseException(de.prob.typechecker.exceptions.LTLParseException) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 2 with BCompoundException

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

the class ASTPrologTest method checkProlog.

private void checkProlog(final int counter, final String bspec, final String expected) throws BCompoundException {
    final BParser parser = new BParser("testcase");
    if (remove_restrictions) {
        parser.getOptions().setRestrictProverExpressions(false);
    }
    final Start startNode = parser.parse(bspec, false, new NoContentProvider());
    checkAST(counter, expected, startNode);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start)

Example 3 with BCompoundException

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

the class ASTPrologTest method testTrueFalse.

@Test
public void testTrueFalse() throws BCompoundException {
    checkPredicate("TRUE : BOOL", "member($,boolean_true($),bool_set($))");
    checkPredicate("FALSE : BOOL", "member($,boolean_false($),bool_set($))");
    final ADisjunctPredicate disjunction = new ADisjunctPredicate();
    disjunction.setLeft(new ATruthPredicate());
    disjunction.setRight(new AFalsityPredicate());
    checkAST(0, "disjunct($,truth($),falsity($))", disjunction);
}
Also used : ATruthPredicate(de.be4.classicalb.core.parser.node.ATruthPredicate) ADisjunctPredicate(de.be4.classicalb.core.parser.node.ADisjunctPredicate) AFalsityPredicate(de.be4.classicalb.core.parser.node.AFalsityPredicate) Test(org.junit.Test)

Example 4 with BCompoundException

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

the class ASTPrologTest method testFreeType.

@Test
public void testFreeType() throws BCompoundException {
    final AConstructorFreetypeConstructor multi = new AConstructorFreetypeConstructor(new TIdentifierLiteral("multi"), new APowSubsetExpression(new AIntegerSetExpression()));
    final AConstructorFreetypeConstructor single = new AConstructorFreetypeConstructor(new TIdentifierLiteral("single"), new AIntegerSetExpression());
    final AFreetype freetype = new AFreetype(new TIdentifierLiteral("T"), Arrays.<PFreetypeConstructor>asList(multi, single));
    AFreetypesMachineClause clause = new AFreetypesMachineClause(Arrays.<PFreetype>asList(freetype));
    final StringWriter swriter = new StringWriter();
    NodeIdAssignment nodeids = new NodeIdAssignment();
    clause.apply(nodeids);
    IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
    PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
    ASTProlog prolog = new ASTProlog(pout, pprinter);
    clause.apply(prolog);
    String code = swriter.toString();
    assertFalse(code.isEmpty());
    assertEquals("freetypes(0,[freetype(1,'T',[constructor(2,multi,pow_subset(3,integer_set(4))),constructor(5,single,integer_set(6))])])", code);
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter) ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) AIntegerSetExpression(de.be4.classicalb.core.parser.node.AIntegerSetExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) StringWriter(java.io.StringWriter) AConstructorFreetypeConstructor(de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) AFreetype(de.be4.classicalb.core.parser.node.AFreetype) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with BCompoundException

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

the class ExpressionTest method testQuantifiedUnionExpression.

@Test
public void testQuantifiedUnionExpression() throws Exception {
    final String testMachine = "#EXPRESSION UNION x.y.(x=0 | x )";
    try {
        getTreeAsString(testMachine);
        fail("Invalid renaming of identifier not detected");
    } catch (BCompoundException e) {
    }
}
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