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