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();
}
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());
}
}
}
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);
}
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();
}
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;
}
Aggregations