Search in sources :

Example 6 with ParsingBehaviour

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

the class RulesUtil method getRulesMachineAsPrologTerm.

public static String getRulesMachineAsPrologTerm(final String content) {
    RulesParseUnit unit = new RulesParseUnit();
    unit.setMachineAsString(content);
    ParsingBehaviour pb = new ParsingBehaviour();
    pb.setAddLineNumbers(false);
    unit.setParsingBehaviour(pb);
    unit.parse();
    unit.translate();
    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();
        }
    };
    unit.printPrologOutput(new PrintStream(output), new PrintStream(output));
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

Example 7 with ParsingBehaviour

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

the class RulesMachineFilesTest method testRulesMachineConfiguration.

@Test
public void testRulesMachineConfiguration() throws Exception {
    File file = new File("src/test/resources/rules/project/RulesMachineConfigurationTest.rmch");
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    parsingBehaviour.setPrologOutput(true);
    RulesProject project = new RulesProject();
    project.parseProject(file);
    project.checkAndTranslateProject();
    RulesMachineRunConfiguration rulesMachineRunConfiguration = project.getRulesMachineRunConfiguration();
    Set<RuleGoalAssumption> rulesGoalAssumptions = rulesMachineRunConfiguration.getRulesGoalAssumptions();
    assertEquals(2, rulesGoalAssumptions.size());
    for (Iterator<RuleGoalAssumption> iterator = rulesGoalAssumptions.iterator(); iterator.hasNext(); ) {
        RuleGoalAssumption next = iterator.next();
        if ("rule1".equals(next.getRuleName())) {
            assertEquals(new HashSet<Integer>(Arrays.asList(1)), next.getErrorTypesAssumedToSucceed());
            assertEquals(true, next.isCheckedForCounterexamples());
            assertEquals("rule1", next.getRuleOperation().getName());
        } else {
            assertEquals("rule2", next.getRuleName());
            assertEquals(new HashSet<Integer>(Arrays.asList(1)), next.getErrorTypesAssumedToFail());
            assertEquals(false, next.isCheckedForCounterexamples());
        }
    }
}
Also used : RuleGoalAssumption(de.be4.classicalb.core.parser.rules.RulesMachineRunConfiguration.RuleGoalAssumption) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) Test(org.junit.Test)

Example 8 with ParsingBehaviour

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

the class RulesMachineFilesTest method testForAll.

@Test
public void testForAll() throws Exception {
    String f = "src/test/resources/rules/ForAllPredicate.rmch";
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    RulesProject.parseProject(new File(f), parsingBehaviour, System.out, System.err);
}
Also used : ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) File(java.io.File) Test(org.junit.Test)

Example 9 with ParsingBehaviour

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

the class RulesMachineFilesTest method getRulesMachineAsPrologTerm.

private String getRulesMachineAsPrologTerm(String fileName) {
    File file = new File(fileName);
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    parsingBehaviour.setPrologOutput(true);
    OutputStream out = new OutputStream() {

        private StringBuilder string = new StringBuilder();

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

        @Override
        public String toString() {
            return this.string.toString();
        }
    };
    RulesProject.parseProject(file, parsingBehaviour, new PrintStream(out), new PrintStream(out));
    return out.toString();
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

Example 10 with ParsingBehaviour

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

the class BParser method fullParsing.

public int fullParsing(final File bfile, final ParsingBehaviour parsingBehaviour, final PrintStream out, final PrintStream err) {
    try {
        // Properties hashes = new Properties();
        // if (parsingBehaviour.getOutputFile() != null) {
        // if (hashesStillValid(parsingBehaviour.getOutputFile())){
        // return 0;
        // }
        // }
        final long start = System.currentTimeMillis();
        final Start tree = parseFile(bfile, parsingBehaviour.isVerbose());
        final long end = System.currentTimeMillis();
        if (parsingBehaviour.isPrintTime()) {
            out.println("Time for parsing: " + (end - start) + "ms");
        }
        if (parsingBehaviour.isPrintAST()) {
            ASTPrinter sw = new ASTPrinter(out);
            tree.apply(sw);
        }
        if (parsingBehaviour.isDisplayGraphically()) {
            tree.apply(new ASTDisplay());
        }
        final long start2 = System.currentTimeMillis();
        if (parsingBehaviour.isPrologOutput()) {
            printASTasProlog(out, this, bfile, tree, parsingBehaviour, contentProvider);
        }
        final long end2 = System.currentTimeMillis();
        if (parsingBehaviour.isPrintTime()) {
            out.println("Time for Prolog output: " + (end2 - start2) + "ms");
        }
        if (parsingBehaviour.isFastPrologOutput()) {
            try {
                String fp = getASTasFastProlog(this, bfile, tree, parsingBehaviour, contentProvider);
                out.println(fp);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } catch (final IOException e) {
        if (parsingBehaviour.isPrologOutput()) {
            PrologExceptionPrinter.printException(err, e, bfile.getAbsolutePath());
        } else {
            err.println();
            err.println("Error reading input file: " + e.getLocalizedMessage());
        }
        return -2;
    } catch (final BCompoundException e) {
        if (parsingBehaviour.isPrologOutput()) {
            PrologExceptionPrinter.printException(err, e, parsingBehaviour.isUseIndention(), false);
        // PrologExceptionPrinter.printException(err, e);
        } else {
            err.println();
            err.println("Error parsing input file: " + e.getLocalizedMessage());
        }
        return -3;
    }
    return 0;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) ASTDisplay(de.be4.classicalb.core.parser.visualisation.ASTDisplay) IOException(java.io.IOException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) ParserException(de.be4.classicalb.core.parser.parser.ParserException)

Aggregations

ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)19 File (java.io.File)16 PrintStream (java.io.PrintStream)12 BParser (de.be4.classicalb.core.parser.BParser)9 OutputStream (java.io.OutputStream)7 Start (de.be4.classicalb.core.parser.node.Start)6 Test (org.junit.Test)6 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)5 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)4 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 ProBError (de.prob.exception.ProBError)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 BException (de.be4.classicalb.core.parser.exceptions.BException)2 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)2 LtlParseException (de.be4.ltl.core.parser.LtlParseException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Ast2String (util.Ast2String)2 MockedDefinitions (de.be4.classicalb.core.parser.MockedDefinitions)1 ParserException (de.be4.classicalb.core.parser.parser.ParserException)1