Skip to content
Snippets Groups Projects
Commit 91b20c5f authored by René Schöne's avatar René Schöne
Browse files

WIP: Mustache2YAML

- finished transformation
- remove indentation from mustache templates
- store YAML in file when --printYaml is given
parent 0938223b
Branches
No related tags found
No related merge requests found
Showing
with 192 additions and 188 deletions
aspect Printing {
String ASTNode.PRINT_INDENT = " ";
syn String Document.prettyPrint() {
StringBuilder sb = new StringBuilder("#start\n");
StringBuilder sb = new StringBuilder();
sb.append("# RagConnect created at ").append(java.time.Instant.now()).append("\n");
for (ComplexElement element : getComplexElementList()) {
element.prettyPrint(sb, false, "");
}
if (sb.charAt(sb.length() - 1) != '\n') {
sb.append("\n");
}
sb.append("#end");
return sb.toString();
}
syn StringBuilder Element.prettyPrint(StringBuilder sb, boolean printIndent, String indent);
......
......@@ -3,6 +3,7 @@ aspect MustacheNodesToYAML {
Document doc = new Document();
MappingElement root = new MappingElement();
root.addKeyValuePair("rootNodeName", StringElement.of(rootNodeName()));
root.addKeyValuePair("closeMethod", StringElement.of(closeMethod()));
root.addKeyValuePair("usesMqtt", ValueElement.of(usesMqtt));
root.addKeyValuePair("usesRest", ValueElement.of(usesRest));
// mqtt
......@@ -18,7 +19,7 @@ aspect MustacheNodesToYAML {
inner.addKeyValuePair("name", StringElement.of(comp.name()));
rootTypeComponents.addElement(inner);
}
root.addKeyValuePair("rootTypeComponents", rootTypeComponents);
root.addKeyValuePair("RootTypeComponents", rootTypeComponents);
// rest
root.addKeyValuePair("restHandlerField", StringElement.of(restHandlerField()));
......@@ -63,92 +64,93 @@ aspect MustacheNodesToYAML {
return doc;
}
syn Element MReceiveDefinition.toYAML() {
MappingElement inner = new MappingElement();
inner.addKeyValuePair("parentTypeName", StringElement.of(parentTypeName()));
inner.addKeyValuePair("connectMethod", StringElement.of(connectMethod()));
inner.addKeyValuePair("connectParameterName", StringElement.of(connectParameterName()));
inner.addKeyValuePair("lastDefinitionToType", StringElement.of(lastDefinitionToType()));
inner.addKeyValuePair("resultVarPrefix", StringElement.of(resultVarPrefix()));
inner.addKeyValuePair("lastDefinitionName", StringElement.of(lastDefinitionName()));
inner.addKeyValuePair("preemptiveReturn", StringElement.of(preemptiveReturn()));
inner.addKeyValuePair("alwaysApply", ValueElement.of(alwaysApply()));
inner.addKeyValuePair("condition", StringElement.of(condition()));
inner.addKeyValuePair("loggingEnabledForReads", ValueElement.of(loggingEnabledForReads));
inner.addKeyValuePair("tokenName", StringElement.of(tokenName()));
inner.addKeyValuePair("lastResult", StringElement.of(lastResult()));
// inner.addKeyValuePair("first", ValueElement.of(isFirst()));
// parentTypeName
// connectMethod
// connectParameterName
// lastDefinitionToType
// resultVarPrefix
// lastDefinitionName
// #InnerMappingDefinitions -> MInnerMappingDefinition
// last
// toType
// methodName
// inputVarName
// preemptiveReturn
// alwaysApply
// condition - special chars
// loggingEnabledForReads
// tokenName
// lastResult
return inner;
}
syn Element MSendDefinition.toYAML() {
MappingElement inner = new MappingElement();
// #SendDefinitions -> MSendDefinition
// parentTypeName
// sender
// lastValue
// connectMethod
// connectParameterName
// loggingEnabledForWrites
// updateMethod
// writeMethod
// tokenResetMethod
// lastResult
return inner;
syn MappingElement MEndpointDefinition.toYAML() {
MappingElement result = new MappingElement();
result.addKeyValuePair("parentTypeName", StringElement.of(parentTypeName()));
result.addKeyValuePair("connectMethod", StringElement.of(connectMethod()));
result.addKeyValuePair("connectParameterName", StringElement.of(connectParameterName()));
result.addKeyValuePair("lastDefinitionToType", StringElement.of(lastDefinitionToType()));
result.addKeyValuePair("resultVarPrefix", StringElement.of(resultVarPrefix()));
result.addKeyValuePair("lastDefinitionName", StringElement.of(lastDefinitionName()));
result.addKeyValuePair("preemptiveReturn", StringElement.of(preemptiveReturn()));
result.addKeyValuePair("alwaysApply", ValueElement.of(alwaysApply()));
result.addKeyValuePair("condition", StringElement.of(
condition().replace("\"", "\\\"").replace("\n", "\\n")));
result.addKeyValuePair("lastResult", StringElement.of(lastResult()));
result.addKeyValuePair("InnerMappingDefinitions", innerMappingDefinitionsAsListElement());
result.addKeyValuePair("tokenName", StringElement.of(tokenName()));
return result;
}
syn MappingElement MReceiveDefinition.toYAML() {
MappingElement result = super.toYAML();
result.addKeyValuePair("loggingEnabledForReads", ValueElement.of(loggingEnabledForReads));
return result;
}
syn MappingElement MSendDefinition.toYAML() {
MappingElement result = super.toYAML();
result.addKeyValuePair("sender", StringElement.of(sender()));
result.addKeyValuePair("lastValue", StringElement.of(lastValue()));
result.addKeyValuePair("loggingEnabledForWrites", ValueElement.of(loggingEnabledForWrites));
result.addKeyValuePair("updateMethod", StringElement.of(updateMethod()));
result.addKeyValuePair("writeMethod", StringElement.of(writeMethod()));
result.addKeyValuePair("tokenResetMethod", StringElement.of(tokenResetMethod()));
return result;
}
syn Element MMappingDefinition.toYAML() {
MappingElement inner = new MappingElement();
// #MappingDefinitions -> MMappingDefinition
// toType
// methodName
// fromType
// fromVariableName
// content - special chars
return inner;
MappingElement result = new MappingElement();
result.addKeyValuePair("toType", StringElement.of(toType()));
result.addKeyValuePair("methodName", StringElement.of(methodName()));
result.addKeyValuePair("fromType", StringElement.of(fromType()));
result.addKeyValuePair("fromVariableName", StringElement.of(fromVariableName()));
result.addKeyValuePair("content", StringElement.of(
content().replace("\"", "\\\"").replace("\n", "\\n")));
return result;
}
syn Element MDependencyDefinition.toYAML() {
MappingElement inner = new MappingElement();
// #DependencyDefinitions -> MDependencyDefinition
// targetParentTypeName
// dependencyMethod
// sourceParentTypeName
// internalRelationPrefix
return inner;
MappingElement result = new MappingElement();
result.addKeyValuePair("targetParentTypeName", StringElement.of(targetParentTypeName()));
result.addKeyValuePair("dependencyMethod", StringElement.of(dependencyMethod()));
result.addKeyValuePair("sourceParentTypeName", StringElement.of(sourceParentTypeName()));
result.addKeyValuePair("internalRelationPrefix", StringElement.of(internalRelationPrefix()));
return result;
}
syn Element MTokenComponent.toYAML() {
MappingElement result = new MappingElement();
result.addKeyValuePair("parentTypeName", StringElement.of(parentTypeName()));
result.addKeyValuePair("name", StringElement.of(name()));
result.addKeyValuePair("javaType", StringElement.of(javaType()));
result.addKeyValuePair("internalName", StringElement.of(internalName()));
ListElement dependencyDefinitions = new ListElement();
for (MDependencyDefinition def : getDependencyDefinitionList()) {
MappingElement inner = new MappingElement();
// #TokenComponents -> MTokenComponent
// parentTypeName
// name
// javaType
// internalName
// #DependencyDefinitions -> MDependencyDefinition
// targetParentTypeName
// internalRelationPrefix
// #targetEndpointDefinition -> MSendDefinition
// updateMethod
// writeMethod
return inner;
inner.addKeyValuePair("targetParentTypeName", StringElement.of(def.targetParentTypeName()));
inner.addKeyValuePair("internalRelationPrefix", StringElement.of(def.internalRelationPrefix()));
MappingElement targetEndpointDefinition = new MappingElement();
targetEndpointDefinition.addKeyValuePair("updateMethod", StringElement.of(def.targetEndpointDefinition().updateMethod()));
targetEndpointDefinition.addKeyValuePair("writeMethod", StringElement.of(def.targetEndpointDefinition().writeMethod()));
inner.addKeyValuePair("targetEndpointDefinition", targetEndpointDefinition);
dependencyDefinitions.addElement(inner);
}
result.addKeyValuePair("DependencyDefinitions", dependencyDefinitions);
return result;
}
ListElement MEndpointDefinition.innerMappingDefinitionsAsListElement() {
ListElement innerMappingDefinitions = new ListElement();
for (MInnerMappingDefinition def : getInnerMappingDefinitionList()) {
MappingElement inner = new MappingElement();
inner.addKeyValuePair("toType", StringElement.of(def.toType()));
inner.addKeyValuePair("methodName", StringElement.of(def.methodName()));
inner.addKeyValuePair("inputVarName", StringElement.of(def.inputVarName()));
inner.addKeyValuePair("last", ValueElement.of(def.isLast()));
innerMappingDefinitions.addElement(inner);
}
return innerMappingDefinitions;
}
}
......@@ -70,7 +70,9 @@ public class Compiler extends AbstractCompiler {
if (optionPrintYaml.value()) {
ASTNode.rootNode = ragConnect.getProgram().resolveTypeDecl(optionRootNode.value());
System.out.println(ragConnect.toMustache().toYAML().prettyPrint());
String yamlContent = ragConnect.toMustache().toYAML().prettyPrint();
System.out.println(yamlContent);
writeToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.yml"), yamlContent);
return 0;
}
......@@ -98,9 +100,9 @@ public class Compiler extends AbstractCompiler {
}
for (GrammarFile grammarFile : ragConnect.getProgram().getGrammarFileList()) {
Path outputFile = getConfiguration().outputDir().toPath().resolve(grammarFile.getFileName());
sendToFile(outputFile, grammarFile.generateAbstractGrammar());
writeToFile(outputFile, grammarFile.generateAbstractGrammar());
}
sendToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.jadd"), ragConnect.generateAspect(optionRootNode.value()));
writeToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.jadd"), ragConnect.generateAspect(optionRootNode.value()));
return 0;
}
......@@ -139,7 +141,7 @@ public class Compiler extends AbstractCompiler {
System.out.println(message);
}
private void sendToFile(Path path, String str) throws CompilerException {
private void writeToFile(Path path, String str) throws CompilerException {
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
writer.append(str);
} catch (Exception e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment