Search in sources :

Example 6 with RecursiveMachineLoader

use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project probparsers by bendisposto.

the class BParser method getASTasFastProlog.

private static String getASTasFastProlog(final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
    final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
    rml.loadAllMachines(bfile, tree, parser.getDefinitions());
    StructuredPrologOutput structuredPrologOutput = new StructuredPrologOutput();
    rml.printAsProlog(structuredPrologOutput);
    Collection<PrologTerm> sentences = structuredPrologOutput.getSentences();
    StructuredPrologOutput output = new StructuredPrologOutput();
    output.openList();
    for (PrologTerm term : sentences) {
        output.printTerm(term);
    }
    output.closeList();
    output.fullstop();
    FastReadTransformer transformer = new FastReadTransformer(output);
    return transformer.write();
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 7 with RecursiveMachineLoader

use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.

the class ClassicalBFactory method create.

public ExtractedModel<ClassicalBModel> create(final Start model) {
    ClassicalBModel classicalBModel = modelCreator.get();
    BParser bparser = new BParser();
    final RecursiveMachineLoader rml = parseAllMachines(model, ".", new File(""), new CachingDefinitionFileProvider(), bparser);
    classicalBModel = classicalBModel.create(model, rml, new File("from_string"), bparser);
    return new ExtractedModel<>(classicalBModel, classicalBModel.getMainMachine());
}
Also used : CachingDefinitionFileProvider(de.be4.classicalb.core.parser.CachingDefinitionFileProvider) ClassicalBModel(de.prob.model.classicalb.ClassicalBModel) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) File(java.io.File)

Example 8 with RecursiveMachineLoader

use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.

the class ClassicalBFactory method create.

public ExtractedModel<ClassicalBModel> create(final String model) {
    ClassicalBModel classicalBModel = modelCreator.get();
    BParser bparser = new BParser();
    Start ast = parseString(model, bparser);
    final RecursiveMachineLoader rml = parseAllMachines(ast, ".", new File(""), bparser.getContentProvider(), bparser);
    classicalBModel = classicalBModel.create(ast, rml, new File("from_string"), bparser);
    return new ExtractedModel<>(classicalBModel, classicalBModel.getMainMachine());
}
Also used : ClassicalBModel(de.prob.model.classicalb.ClassicalBModel) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) File(java.io.File)

Example 9 with RecursiveMachineLoader

use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.

the class ClassicalBFactory method extract.

@Override
public ExtractedModel<ClassicalBModel> extract(final String modelPath) throws IOException, ModelTranslationError {
    ClassicalBModel classicalBModel = modelCreator.get();
    File f = new File(modelPath);
    BParser bparser = new BParser();
    Start ast = parseFile(f, bparser);
    RecursiveMachineLoader rml = parseAllMachines(ast, f.getParent(), f, bparser.getContentProvider(), bparser);
    classicalBModel = classicalBModel.create(ast, rml, f, bparser);
    return new ExtractedModel<>(classicalBModel, classicalBModel.getMainMachine());
}
Also used : ClassicalBModel(de.prob.model.classicalb.ClassicalBModel) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) File(java.io.File)

Example 10 with RecursiveMachineLoader

use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.

the class ClassicalBFactory method parseAllMachines.

/**
 * Given an {@link Start} ast, {@link File} f, and {@link BParser} bparser, all
 * machines are loaded.
 *
 * @param ast
 *            {@link Start} representing the abstract syntax tree for the
 *            machine
 * @param directory
 *            the directory relative to which machines should be loaded
 * @param f
 *            {@link File} containing machine
 * @param contentProvider
 *            the content provider to use
 * @param bparser
 *            {@link BParser} for parsing
 * @return {@link RecursiveMachineLoader} rml with all loaded machines
 * @throws ProBError
 *             if the model could not be loaded
 */
public RecursiveMachineLoader parseAllMachines(final Start ast, final String directory, final File f, final IDefinitionFileProvider contentProvider, final BParser bparser) {
    try {
        ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
        parsingBehaviour.setAddLineNumbers(true);
        final RecursiveMachineLoader rml = new RecursiveMachineLoader(directory, contentProvider, parsingBehaviour);
        rml.loadAllMachines(f, ast, bparser.getDefinitions());
        logger.trace("Done parsing '{}'", f.getAbsolutePath());
        return rml;
    } catch (BCompoundException e) {
        throw new ProBError(e);
    }
}
Also used : RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) ProBError(de.prob.exception.ProBError) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Aggregations

RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 BParser (de.be4.classicalb.core.parser.BParser)8 File (java.io.File)8 Start (de.be4.classicalb.core.parser.node.Start)7 ClassicalBModel (de.prob.model.classicalb.ClassicalBModel)4 Test (org.junit.Test)4 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)2 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 Ast2String (util.Ast2String)2 CachingDefinitionFileProvider (de.be4.classicalb.core.parser.CachingDefinitionFileProvider)1 ProBError (de.prob.exception.ProBError)1 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)1 ClassicalBFactory (de.prob.scripting.ClassicalBFactory)1 TLA2BException (de.tla2b.exceptions.TLA2BException)1 Translator (de.tla2bAst.Translator)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1