use of de.be4.classicalb.core.parser.rules.RulesProject in project probparsers by bendisposto.
the class RulesUtil method getRulesMachineAsBMachine.
public static String getRulesMachineAsBMachine(File file) {
RulesProject rulesProject = new RulesProject();
rulesProject.parseProject(file);
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 CTagsGenerator method createCTagsFromMachines.
private static Collection<? extends CTagsEntry> createCTagsFromMachines(RulesProject project) {
List<CTagsEntry> list = new ArrayList<>();
for (IModel model : project.bModels) {
if (model instanceof RulesParseUnit) {
RulesParseUnit parseUnit = (RulesParseUnit) model;
if (null != parseUnit.getRulesMachineChecker()) {
TIdentifierLiteral literal = parseUnit.getRulesMachineChecker().getNameLiteral();
list.add(new CTagsEntry(literal.getText(), parseUnit.getPath(), literal.getStartPos(), TYPE_MACHINE));
}
}
}
return list;
}
use of de.be4.classicalb.core.parser.rules.RulesProject in project prob2 by bendisposto.
the class Api method brules_load.
/**
* Load a B rules machine from the given file.
*
* @param file the path of the file to load
* @param prefs the preferences to use
* @return the {@link StateSpace} for the loaded machine
*/
public StateSpace brules_load(final String file, final Map<String, String> prefs) throws IOException {
final RulesModelFactory bRulesFactory = modelFactoryProvider.getBRulesFactory();
final RulesProject rulesProject = new RulesProject();
final ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
parsingBehaviour.setAddLineNumbers(true);
rulesProject.setParsingBehaviour(parsingBehaviour);
rulesProject.parseProject(new File(file));
rulesProject.checkAndTranslateProject();
if (rulesProject.hasErrors()) {
throw new ProBError(new BCompoundException(rulesProject.getBExceptionList()));
}
return bRulesFactory.extract(new File(file), rulesProject).load(prefs);
}
Aggregations