Search in sources :

Example 6 with RulesProject

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();
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 7 with RulesProject

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;
}
Also used : ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 8 with RulesProject

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);
}
Also used : RulesModelFactory(de.prob.model.brules.RulesModelFactory) RulesProject(de.be4.classicalb.core.parser.rules.RulesProject) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) File(java.io.File) ProBError(de.prob.exception.ProBError) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Aggregations

ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)4 BException (de.be4.classicalb.core.parser.exceptions.BException)4 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)3 PrettyPrinter (de.be4.classicalb.core.parser.util.PrettyPrinter)3 ProBError (de.prob.exception.ProBError)2 File (java.io.File)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 RuleGoalAssumption (de.be4.classicalb.core.parser.rules.RulesMachineRunConfiguration.RuleGoalAssumption)1 StateError (de.prob.animator.domainobjects.StateError)1 RuleResult (de.prob.model.brules.RuleResult)1 RuleResults (de.prob.model.brules.RuleResults)1 RulesModelFactory (de.prob.model.brules.RulesModelFactory)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1