use of de.be4.classicalb.core.parser.exceptions.BException 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.classicalb.core.parser.exceptions.BException in project prob2 by bendisposto.
the class RulesMachineErrorsTest method testRulesMachineWithParseError.
@Test
public void testRulesMachineWithParseError() {
RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations("RULE foo BODY ;; END");
System.out.println(rulesMachineRun.getFirstError().getMessage());
assertEquals(ERROR_TYPES.PARSE_ERROR, rulesMachineRun.getFirstError().getType());
assertTrue(rulesMachineRun.getFirstError().getException() instanceof BException);
}
use of de.be4.classicalb.core.parser.exceptions.BException in project prob2 by bendisposto.
the class ProBError method convertParserExceptionToErrorItems.
private static List<ErrorItem> convertParserExceptionToErrorItems(BCompoundException e) {
List<ErrorItem> errorItems = new ArrayList<>();
for (BException bException : e.getBExceptions()) {
List<ErrorItem.Location> errorItemlocations = new ArrayList<>();
if (bException.getFilename() != null && bException.getCause() != null) {
List<BException.Location> parserlocations = bException.getLocations();
for (BException.Location location : parserlocations) {
ErrorItem.Location loc = new ErrorItem.Location(bException.getFilename(), location.getStartLine(), location.getStartColumn(), location.getEndLine(), location.getEndColumn());
errorItemlocations.add(loc);
}
}
ErrorItem item = new ErrorItem(bException.getMessage(), ErrorItem.Type.ERROR, errorItemlocations);
errorItems.add(item);
}
return errorItems;
}
use of de.be4.classicalb.core.parser.exceptions.BException in project probparsers by bendisposto.
the class RulesUtil method getRulesProjectAsPrologTerm.
public static String getRulesProjectAsPrologTerm(final String content) {
RulesProject rulesProject = new RulesProject();
ParsingBehaviour pb = new ParsingBehaviour();
pb.setAddLineNumbers(false);
rulesProject.setParsingBehaviour(pb);
rulesProject.parseRulesMachines(content, new String[] {});
rulesProject.checkAndTranslateProject();
List<IModel> bModels = rulesProject.getBModels();
List<BException> bExceptionList = rulesProject.getBExceptionList();
if (bExceptionList.isEmpty()) {
IModel model = bModels.get(bModels.size() - 2);
PrettyPrinter pp = new PrettyPrinter();
model.getStart().apply(pp);
System.out.println(pp.getPrettyPrint());
}
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();
}
};
rulesProject.printPrologOutput(new PrintStream(output), new PrintStream(output));
return output.toString();
}
use of de.be4.classicalb.core.parser.exceptions.BException 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();
}
Aggregations