use of de.be4.eventbalg.core.parser.parser.Parser in project prob2 by bendisposto.
the class ModelGenerator method addComponent.
private ModelModifier addComponent(ModelModifier modelM, String name, String componentDesc, Map<String, String> components) throws BException {
EventBParser parser = new EventBParser();
Start ast = parser.parse(componentDesc, false);
ReferenceExtractor e = new ReferenceExtractor();
ast.apply(e);
if (e.isContext()) {
for (String s : e.getExtends()) {
String fileN = s + ".ctx";
if (modelM.getModel().getComponent(fileN) == null) {
if (components.get(fileN) == null) {
throw new IllegalArgumentException("no component description for context " + s);
}
modelM = addComponent(modelM, s, components.get(fileN), components);
}
}
modelM = addComponent(modelM, ast);
} else if (e.isMachine()) {
for (String s : e.getSees()) {
String fileN = s + ".ctx";
if (modelM.getModel().getComponent(fileN) == null) {
if (components.get(fileN) == null) {
throw new IllegalArgumentException("no component description for context " + s);
}
modelM = addComponent(modelM, s, components.get(fileN), components);
}
}
for (String s : e.getRefines()) {
String fileN = s + ".emch";
if (modelM.getModel().getComponent(fileN) == null) {
if (components.get(fileN) == null) {
throw new IllegalArgumentException("no component description for machine " + s);
}
modelM = addComponent(modelM, s, components.get(fileN), components);
}
}
modelM = addComponent(modelM, ast);
}
return modelM;
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class SubstitutionTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
// System.out.println("Parsing \"" + testMachine + "\"");
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, false);
// startNode.apply(new ASTPrinter());
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
final String string = ast2String.toString();
// System.out.println(string);
return string;
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class Helpers method fullParsing.
public static String fullParsing(String filename, ParsingBehaviour parsingBehaviour) {
final File machineFile = new File(filename);
final BParser parser = new BParser(machineFile.getAbsolutePath());
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();
}
};
PrintStream printStream = new PrintStream(output);
parser.fullParsing(machineFile, parsingBehaviour, printStream, printStream);
printStream.flush();
printStream.close();
return output.toString();
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class Helpers method getTreeAsString.
public static String getTreeAsString(final String testMachine) throws BCompoundException {
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, false);
// startNode.apply(new ASTPrinter());
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
final String string = ast2String.toString();
// System.out.println(string);
return string;
}
use of de.be4.eventbalg.core.parser.parser.Parser in project probparsers by bendisposto.
the class Helpers method parseFile.
public static void parseFile(final String filename) throws IOException, BCompoundException {
final int dot = filename.lastIndexOf('.');
if (dot >= 0) {
final File machineFile = new File(filename);
final String probfilename = filename.substring(0, dot) + ".prob";
BParser parser = new BParser(filename);
Start tree = parser.parseFile(machineFile, false);
final ParsingBehaviour behaviour = new ParsingBehaviour();
behaviour.setVerbose(true);
PrintStream output = new PrintStream(probfilename);
BParser.printASTasProlog(output, parser, machineFile, tree, behaviour, parser.getContentProvider());
output.close();
} else
throw new IllegalArgumentException("Filename '" + filename + "' has no extension");
}
Aggregations