Commit e53b54f4 authored by René Schöne's avatar René Schöne
Browse files

working on concise grammar

- update YAML generation (again)
parent a14db74f
Pipeline #12019 passed with stages
in 9 minutes and 9 seconds
// aspect MustacheNodesToYAML {
// syn Document MRagConnect.toYAML() {
// Document doc = new Document();
// MappingElement root = new MappingElement();
// root.put("rootNodeName", rootNodeName());
// root.put("closeMethod", closeMethod());
// root.put("usesMqtt", usesMqtt);
// root.put("usesRest", usesRest);
// // mqtt
// root.put("mqttHandlerField", mqttHandlerField());
// root.put("mqttHandlerAttribute", mqttHandlerAttribute());
// root.put("mqttSetupWaitUntilReadyMethod", mqttSetupWaitUntilReadyMethod());
//
// // rootTypeComponents
// ListElement rootTypeComponents = new ListElement();
// for (MTypeComponent comp : getRootTypeComponentList()) {
// MappingElement inner = new MappingElement();
// inner.put("first", comp.isFirst());
// inner.put("name", comp.name());
// rootTypeComponents.addElement(inner);
// }
// root.put("RootTypeComponents", rootTypeComponents);
//
// // rest
// root.put("restHandlerField", restHandlerField());
// root.put("restHandlerAttribute", restHandlerAttribute());
//
// // TokenReceiveDefinitions
// ListElement receiveDefinitions = new ListElement();
// for (MTokenReceiveDefinition def : getTokenReceiveDefinitionList()) {
// receiveDefinitions.addElement(def.toYAML());
// }
// root.put("TokenReceiveDefinitions", receiveDefinitions);
//
// // TokenSendDefinitions
// ListElement sendDefinitions = new ListElement();
// for (MTokenSendDefinition def : getTokenSendDefinitionList()) {
// sendDefinitions.addElement(def.toYAML());
// }
// root.put("TokenSendDefinitions", sendDefinitions);
//
// // TypeReceiveDefinitions
// ListElement typeReceiveDefinitions = new ListElement();
// for (MTypeReceiveDefinition def : getTypeReceiveDefinitionList()) {
// typeReceiveDefinitions.addElement(def.toYAML());
// }
// root.put("TypeReceiveDefinitions", typeReceiveDefinitions);
//
// // TypeSendDefinitions
// ListElement typeSendDefinitions = new ListElement();
// for (MTypeSendDefinition def : getTypeSendDefinitionList()) {
// typeSendDefinitions.addElement(def.toYAML());
// }
// root.put("TypeSendDefinitions", typeSendDefinitions);
//
// // MappingDefinitions
// ListElement mappingDefinitions = new ListElement();
// for (MMappingDefinition def : getMappingDefinitionList()) {
// mappingDefinitions.addElement(def.toYAML());
// }
// root.put("MappingDefinitions", mappingDefinitions);
//
// // DependencyDefinitions
// ListElement dependencyDefinitions = new ListElement();
// for (MDependencyDefinition def : getDependencyDefinitionList()) {
// dependencyDefinitions.addElement(def.toYAML());
// }
// root.put("DependencyDefinitions", dependencyDefinitions);
//
// // TokenComponents
// ListElement tokenComponents = new ListElement();
// for (MTokenComponent comp : getTokenComponentList()) {
// tokenComponents.addElement(comp.toYAML());
// }
// root.put("TokenComponents", tokenComponents);
//
// // Handlers
// ListElement handlers = new ListElement();
// for (MHandler handler : getHandlerList()) {
// handlers.add(handler.toYAML()
// .put("rootTokenComponents", rootTypeComponents.treeCopy()) );
// }
// root.put("Handlers", handlers);
//
// doc.setRootElement(root);
// return doc;
// }
//
// syn MappingElement MEndpointDefinition.toYAML() {
// MappingElement result = new MappingElement();
// result.put("parentTypeName", parentTypeName());
// result.put("connectMethod", connectMethod());
// result.put("connectParameterName", connectParameterName());
// result.put("lastDefinitionToType", lastDefinitionToType());
// result.put("preemptiveReturn", preemptiveReturn());
// result.put("alwaysApply", alwaysApply());
// result.put("condition",
// condition().replace("\"", "\\\"").replace("\n", "\\n"));
// result.put("lastResult", lastResult());
// result.put("tokenName", tokenName());
// result.put("InnerMappingDefinitions", innerMappingDefinitionsAsListElement());
// return result;
// }
//
// syn MappingElement MTokenReceiveDefinition.toYAML() {
// MappingElement result = super.toYAML();
// result.put("loggingEnabledForReads", loggingEnabledForReads);
// return result;
// }
//
// syn MappingElement MTokenSendDefinition.toYAML() {
// MappingElement result = super.toYAML();
// result.put("sender", sender());
// result.put("lastValue", lastValue());
// result.put("loggingEnabledForWrites", loggingEnabledForWrites);
// result.put("updateMethod", updateMethod());
// result.put("writeMethod", writeMethod());
// result.put("tokenResetMethod", tokenResetMethod());
// return result;
// }
//
// syn MappingElement MTypeReceiveDefinition.toYAML() {
// MappingElement result = super.toYAML();
// result.put("typeIsList", typeIsList());
// result.put("loggingEnabledForReads", loggingEnabledForReads);
// return result;
// }
//
// syn MappingElement MTypeSendDefinition.toYAML() {
// MappingElement result = super.toYAML();
// result.put("typeIsList", typeIsList());
// result.put("sender", sender());
// result.put("lastValue", lastValue());
// result.put("loggingEnabledForWrites", loggingEnabledForWrites);
// result.put("updateMethod", updateMethod());
// result.put("writeMethod", writeMethod());
// result.put("tokenResetMethod", tokenResetMethod());
// return result;
// }
//
// syn Element MMappingDefinition.toYAML() {
// MappingElement result = new MappingElement();
// result.put("toType", toType());
// result.put("methodName", methodName());
// result.put("fromType", fromType());
// result.put("fromVariableName", fromVariableName());
// result.put("content",
// content().replace("\"", "\\\"").replace("\n", "\\n"));
// return result;
// }
//
// syn Element MDependencyDefinition.toYAML() {
// MappingElement result = new MappingElement();
// result.put("targetParentTypeName", targetParentTypeName());
// result.put("dependencyMethod", dependencyMethod());
// result.put("sourceParentTypeName", sourceParentTypeName());
// result.put("internalRelationPrefix", internalRelationPrefix());
// return result;
// }
//
// syn Element MTokenComponent.toYAML() {
// MappingElement result = new MappingElement();
// result.put("parentTypeName", parentTypeName());
// result.put("name", name());
// result.put("javaType", javaType());
// result.put("internalName", internalName());
// ListElement dependencyDefinitions = new ListElement();
// for (MDependencyDefinition def : getDependencyDefinitionList()) {
// MappingElement inner = new MappingElement();
// inner.put("targetParentTypeName", def.targetParentTypeName());
// inner.put("internalRelationPrefix", def.internalRelationPrefix());
// MappingElement targetEndpointDefinition = new MappingElement();
// targetEndpointDefinition.put("updateMethod", def.targetEndpointDefinition().updateMethod());
// targetEndpointDefinition.put("writeMethod", def.targetEndpointDefinition().writeMethod());
// inner.put("targetEndpointDefinition", targetEndpointDefinition);
// dependencyDefinitions.addElement(inner);
// }
// result.put("DependencyDefinitions", dependencyDefinitions);
// return result;
// }
//
// ListElement MEndpointDefinition.innerMappingDefinitionsAsListElement() {
// ListElement innerMappingDefinitions = new ListElement();
// for (MInnerMappingDefinition def : getInnerMappingDefinitionList()) {
// MappingElement inner = new MappingElement();
// inner.put("toType", def.toType());
// inner.put("methodName", def.methodName());
// inner.put("inputVarName", def.inputVarName());
// inner.put("outputVarName", def.outputVarName());
// inner.put("last", def.isLast());
// innerMappingDefinitions.addElement(inner);
// }
// return innerMappingDefinitions;
// }
//
// syn MappingElement MHandler.toYAML() {
// MappingElement result = new MappingElement();
// result.put("ClassName", getClassName());
// result.put("Construction", getConstruction());
// result.put("AttributeName", getAttributeName());
// result.put("FieldName", getFieldName());
// result.put("InUse", getInUse());
// return result;
// }
// }
//
// aspect Navigation {
// eq Document.getChild().program() = null;
// eq Document.getChild().ragconnect() = null;
// eq Document.getChild().containedFile() = null;
// eq Document.containedFileName() = getFileName();
// }
aspect MustacheNodesToYAML {
syn Document RagConnect.toYAML() {
Document doc = new Document();
MappingElement root = new MappingElement();
root.put("rootNodeName", rootNodeName());
root.put("closeMethodName", closeMethodName());
root.put("loggingEnabledForReads", loggingEnabledForReads());
root.put("loggingEnabledForWrites", loggingEnabledForWrites());
// rootTypeComponents
ListElement rootTypeComponents = new ListElement();
for (TypeComponent comp : rootTypeComponents()) {
MappingElement inner = new MappingElement();
rootTypeComponents.addElement(inner);
}
root.put("RootTypeComponents", rootTypeComponents);
// allEndpointDefinitionList
ListElement endpointDefinitions = new ListElement();
for (EndpointDefinition def : allEndpointDefinitionList()) {
endpointDefinitions.addElement(def.toYAML());
}
root.put("allEndpointDefinitionList", endpointDefinitions);
// allMappingDefinitions
ListElement mappingDefinitions = new ListElement();
for (MappingDefinition def : allMappingDefinitions()) {
mappingDefinitions.addElement(def.toYAML());
}
root.put("allMappingDefinitions", mappingDefinitions);
// allDependencyDefinitionList
ListElement dependencyDefinitions = new ListElement();
for (DependencyDefinition def : allDependencyDefinitionList()) {
dependencyDefinitions.addElement(def.toYAML());
}
root.put("allDependencyDefinitionList", dependencyDefinitions);
// tokenComponentsThatNeedProxy
ListElement tokenComponents = new ListElement();
for (TokenComponent comp : tokenComponentsThatNeedProxy()) {
tokenComponents.addElement(comp.toYAML());
}
root.put("tokenComponentsThatNeedProxy", tokenComponents);
// Handlers
ListElement handlers = new ListElement();
for (Handler handler : getHandlerList()) {
handlers.add(handler.toYAML()
// .put("rootTypeComponents", rootTypeComponents.treeCopy())
// .put("hasRootTypeComponents", hasRootTypeComponents())
);
}
root.put("Handlers", handlers);
root.put("mqttHandler", mqttHandler().toYAML());
root.put("restHandler", restHandler().toYAML());
doc.setRootElement(root);
return doc;
}
syn MappingElement EndpointDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("AlwaysApply", getAlwaysApply());
result.put("IndexBasedListAccess", getIndexBasedListAccess());
result.put("WithAdd", getWithAdd());
result.put("Send", getSend());
result.put("preemptiveExpectedValue", preemptiveExpectedValue());
result.put("preemptiveReturn", preemptiveReturn());
result.put("firstInputVarName", firstInputVarName());
result.put("updateMethodName", updateMethodName());
result.put("writeMethodName", writeMethodName());
result.put("parentTypeName", parentTypeName());
result.put("entityName", entityName());
result.put("getterMethodName", getterMethodName());
result.put("uniqueSuffix", uniqueSuffix());
result.put("connectParameterName", connectParameterName());
result.put("connectMethodName", connectMethodName());
result.put("internalConnectMethodName", internalConnectMethodName());
result.put("disconnectMethodName", disconnectMethodName());
result.put("typeDeclName", typeDeclName());
result.put("lastDefinition", lastDefinition().getMappingDefinition().toYAML().treeCopy());
result.put("lastDefinitionToType", lastDefinitionToType());
result.put("lastResult", lastResult());
result.put("condition", sanitizeValueForYAML(condition()));
result.put("senderName", senderName());
result.put("lastValue", lastValue());
result.put("tokenResetMethodName", tokenResetMethodName());
result.put("resolveInListMethodName", resolveInListMethodName());
result.put("idTokenName", idTokenName());
result.put("InnerMappingDefinitions", innerMappingDefinitionsAsListElement());
getEndpointTarget().addToYAML(result);
return result;
}
abstract void EndpointTarget.addToYAML(MappingElement result);
void TokenEndpointTarget.addToYAML(MappingElement result) {
result.put("tokenName", containingEndpointDefinition().tokenName());
}
void TypeEndpointTarget.addToYAML(MappingElement result) {
result.put("typeName", containingEndpointDefinition().typeName());
result.put("typeIsList", typeIsList());
}
void UntypedEndpointTarget.addToYAML(MappingElement result) {
}
syn Element MappingDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("toType", toType());
result.put("methodName", methodName());
result.put("fromType", fromType());
result.put("fromVariableName", getFromVariableName());
result.put("content", sanitizeValueForYAML(getContent()));
return result;
}
syn Element DependencyDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("targetParentTypeName", targetParentTypeName());
result.put("dependencyMethodName", dependencyMethodName());
result.put("sourceParentTypeName", sourceParentTypeName());
result.put("internalRelationPrefix", internalRelationPrefix());
return result;
}
syn Element TokenComponent.toYAML() {
MappingElement result = new MappingElement();
result.put("parentTypeName", parentTypeName());
result.put("name", getName());
result.put("javaType", javaType());
result.put("internalName", internalName());
ListElement dependencyDefinitions = new ListElement();
for (DependencyDefinition def : getDependencySourceDefinitionList()) {
MappingElement inner = new MappingElement();
inner.put("targetParentTypeName", def.targetParentTypeName());
inner.put("internalRelationPrefix", def.internalRelationPrefix());
MappingElement targetEndpointDefinition = new MappingElement();
targetEndpointDefinition.put("updateMethodName", def.targetEndpointDefinition().updateMethodName());
targetEndpointDefinition.put("writeMethodName", def.targetEndpointDefinition().writeMethodName());
inner.put("targetEndpointDefinition", targetEndpointDefinition);
dependencyDefinitions.addElement(inner);
}
result.put("DependencyDefinitions", dependencyDefinitions);
return result;
}
ListElement EndpointDefinition.innerMappingDefinitionsAsListElement() {
ListElement innerMappingDefinitions = new ListElement();
for (MInnerMappingDefinition def : innerMappingDefinitions()) {
MappingElement inner = new MappingElement();
inner.put("toType", def.toType());
inner.put("methodName", def.methodName());
inner.put("inputVarName", def.inputVarName());
inner.put("outputVarName", def.outputVarName());
inner.put("last", def.isLast());
innerMappingDefinitions.addElement(inner);
}
return innerMappingDefinitions;
}
syn MappingElement Handler.toYAML() {
MappingElement result = new MappingElement();
result.put("ClassName", getClassName());
result.put("ConstructionSnippet", ConstructionSnippet());
result.put("AttributeName", AttributeName());
result.put("FieldName", FieldName());
result.put("InUse", getInUse());
return result;
}
protected String ASTNode.sanitizeValueForYAML(String value) {
return value.replace("\"", "\\\"").replace("\n", "\\n");
}
}
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.containedFileName() = getFileName();
}
......@@ -80,8 +80,10 @@ public class Compiler extends AbstractCompiler {
}
if (optionPrintYaml.value()) {
System.err.println("'--printYaml' currently unsupported option!");
return 1;
String yamlContent = ragConnect.toYAML().prettyPrint();
System.out.println(yamlContent);
writeToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.yml"), yamlContent);
return 0;
}
LOGGER.fine("Writing output files");
......@@ -163,7 +165,7 @@ public class Compiler extends AbstractCompiler {
.addAcceptedValue(OPTION_PROTOCOL_REST, "Enable REST")
);
optionPrintYaml = addOption(
new BooleanOption("printYaml", "Print out YAML instead of generating files (currently unsupported)")
new BooleanOption("printYaml", "Print out YAML instead of generating files and exit.")
.defaultValue(false));
optionVerbose = addOption(
new BooleanOption("verbose", "Print more messages while compiling.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment