use of de.be4.classicalb.core.parser.rules.RulesProject in project probparsers by bendisposto.
the class RulesUtil method getRulesMachineAsBMachine.
public static String getRulesMachineAsBMachine(final String content) {
RulesProject rulesProject = new RulesProject();
rulesProject.parseRulesMachines(content, new String[] {});
rulesProject.checkAndTranslateProject();
List<IModel> bModels = rulesProject.getBModels();
List<BException> bExceptionList = rulesProject.getBExceptionList();
if (!bExceptionList.isEmpty()) {
throw new RuntimeException(bExceptionList.get(0));
}
IModel model = bModels.get(bModels.size() - 2);
PrettyPrinter pp = new PrettyPrinter();
model.getStart().apply(pp);
return pp.getPrettyPrint();
}
use of de.be4.classicalb.core.parser.rules.RulesProject 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.rules.RulesProject in project prob2 by bendisposto.
the class RulesMachineRun method parseAndTranslateRulesProject.
private boolean parseAndTranslateRulesProject() {
this.rulesProject = new RulesProject();
ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
parsingBehaviour.setAddLineNumbers(true);
rulesProject.setParsingBehaviour(parsingBehaviour);
rulesProject.parseProject(runnerFile);
for (Entry<String, String> pair : constantValuesToBeInjected.entrySet()) {
rulesProject.addConstantValue(pair.getKey(), pair.getValue());
}
/*
* parse errors and errors from semantic checks are stored in the
* rulesProject
*/
rulesProject.checkAndTranslateProject();
if (rulesProject.hasErrors()) {
BException bException = rulesProject.getBExceptionList().get(0);
String message = bException.getMessage();
logger.error("Parse error: {}", message);
this.errors.add(new Error(ERROR_TYPES.PARSE_ERROR, message, bException));
}
return rulesProject.hasErrors();
}
use of de.be4.classicalb.core.parser.rules.RulesProject in project prob2 by bendisposto.
the class RulesTestUtil method checkRulesMachineRunForConsistency.
public static void checkRulesMachineRunForConsistency(RulesMachineRun rulesMachineRun) {
RulesProject rulesProject = rulesMachineRun.getRulesProject();
RuleResults ruleResults = rulesMachineRun.getRuleResults();
Map<String, RuleResult> ruleResultMap = ruleResults.getRuleResultMap();
for (AbstractOperation abstractOperation : rulesProject.getOperationsMap().values()) {
if (abstractOperation instanceof RuleOperation) {
String ruleName = abstractOperation.getName();
assertTrue(String.format("Rule operation '%s' is not contained in the result map.", ruleName), ruleResultMap.containsKey(ruleName));
RuleResult ruleResult = ruleResultMap.get(ruleName);
if (ruleResult.getRuleState() == RuleStatus.FAIL) {
assertTrue(String.format("No violation found but rule failed: '%s'", ruleName), ruleResult.getNumberOfViolations() > 0);
}
if (ruleResult.getRuleState() == RuleStatus.NOT_CHECKED) {
List<String> notCheckedCauses = ruleResult.getFailedDependencies();
assertTrue(String.format("There is no cause why rule '%s' is not checked.", ruleName), !notCheckedCauses.isEmpty());
}
}
}
}
use of de.be4.classicalb.core.parser.rules.RulesProject in project probparsers by bendisposto.
the class RulesUtil method getRulesProjectAsPrologTerm.
public static String getRulesProjectAsPrologTerm(final String content) {
RulesProject rulesProject = new RulesProject();
ParsingBehaviour pb = new ParsingBehaviour();
pb.setAddLineNumbers(false);
rulesProject.setParsingBehaviour(pb);
rulesProject.parseRulesMachines(content, new String[] {});
rulesProject.checkAndTranslateProject();
List<IModel> bModels = rulesProject.getBModels();
List<BException> bExceptionList = rulesProject.getBExceptionList();
if (bExceptionList.isEmpty()) {
IModel model = bModels.get(bModels.size() - 2);
PrettyPrinter pp = new PrettyPrinter();
model.getStart().apply(pp);
System.out.println(pp.getPrettyPrint());
}
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();
}
};
rulesProject.printPrologOutput(new PrintStream(output), new PrintStream(output));
return output.toString();
}
Aggregations