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

Use mustache submodule.

parent 75f973c2
Pipeline #7700 passed with stage
in 1 minute and 22 seconds
[submodule "relast-preprocessor"] [submodule "relast-preprocessor"]
path = relast-preprocessor path = relast-preprocessor
url = ../relast-preprocessor.git url = ../relast-preprocessor.git
[submodule "ragconnect.base/src/main/jastadd/mustache"]
path = ragconnect.base/src/main/jastadd/mustache
url = ../mustache
...@@ -51,7 +51,7 @@ task newVersion() { ...@@ -51,7 +51,7 @@ task newVersion() {
} }
} }
File genSrc = file("src/gen/java"); File genSrc = file("src/gen/java")
sourceSets.main.java.srcDir genSrc sourceSets.main.java.srcDir genSrc
idea.module.generatedSourceDirs += genSrc idea.module.generatedSourceDirs += genSrc
...@@ -67,16 +67,20 @@ jar { ...@@ -67,16 +67,20 @@ jar {
archiveBaseName = 'ragconnect' archiveBaseName = 'ragconnect'
} }
File preprocessorGrammar = file('../relast-preprocessor/src/main/jastadd/RelAst.relast')
File ragConnectGrammar = file('./src/main/jastadd/RagConnect.relast')
File intermediateGrammar = file('./src/main/jastadd/intermediate/MustacheNodes.relast')
File mustacheGrammar = file('./src/main/jastadd/mustache/Mustache.relast')
task relast(type: JavaExec) { task relast(type: JavaExec) {
group = 'Build' group = 'Build'
main = "-jar" main = "-jar"
args = [ args = [
"../libs/relast.jar", "../libs/relast.jar",
"../relast-preprocessor/src/main/jastadd/RelAst.relast", preprocessorGrammar,
"./src/main/jastadd/RagConnect.relast", ragConnectGrammar,
"./src/main/jastadd/MustacheNodes.relast", intermediateGrammar,
"./src/main/jastadd/YAML.relast", mustacheGrammar,
"--listClass=java.util.ArrayList", "--listClass=java.util.ArrayList",
"--jastAddList=JastAddList", "--jastAddList=JastAddList",
"--useJastAddNames", "--useJastAddNames",
...@@ -86,10 +90,10 @@ task relast(type: JavaExec) { ...@@ -86,10 +90,10 @@ task relast(type: JavaExec) {
] ]
inputs.files("../libs/relast.jar", inputs.files("../libs/relast.jar",
"../relast-preprocessor/src/main/jastadd/RelAst.relast", preprocessorGrammar,
"./src/main/jastadd/RagConnect.relast", ragConnectGrammar,
"./src/main/jastadd/MustacheNodes.relast", intermediateGrammar,
"./src/main/jastadd/YAML.relast") mustacheGrammar)
outputs.files("./src/gen/jastadd/RagConnect.ast", outputs.files("./src/gen/jastadd/RagConnect.ast",
"./src/gen/jastadd/RagConnect.jadd", "./src/gen/jastadd/RagConnect.jadd",
"./src/gen/jastadd/RagConnectRefResolver.jadd", "./src/gen/jastadd/RagConnectRefResolver.jadd",
......
aspect Printing { aspect Printing {
String ASTNode.PRINT_INDENT = " ";
syn String MappingDefinitionType.prettyPrint(); syn String MappingDefinitionType.prettyPrint();
eq JavaMappingDefinitionType.prettyPrint() = getType().getName(); eq JavaMappingDefinitionType.prettyPrint() = getType().getName();
eq JavaArrayMappingDefinitionType.prettyPrint() = getType().getName() + "[]"; eq JavaArrayMappingDefinitionType.prettyPrint() = getType().getName() + "[]";
...@@ -10,66 +8,4 @@ aspect Printing { ...@@ -10,66 +8,4 @@ aspect Printing {
generateAbstractGrammar(sb); generateAbstractGrammar(sb);
return sb.toString(); return sb.toString();
} }
syn String Document.prettyPrint() {
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");
}
return sb.toString();
}
syn StringBuilder Element.prettyPrint(StringBuilder sb, boolean printIndent, String indent);
eq ValueElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
sb.append(getValue());
return sb;
}
eq StringElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
sb.append("\"").append(getValue()).append("\"");
return sb;
}
eq ListElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (isEmpty()) {
sb.append("[]");
} else {
for (Element element : getElementList()) {
sb.append(indent).append("- ");
element.prettyPrint(sb, false, indent + PRINT_INDENT);
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
return sb;
}
eq KeyValuePair.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (printIndent) sb.append(indent);
sb.append(getKey()).append(": ");
if (getValue().isComplex() && !getValue().isEmpty()) {
sb.append("\n");
getValue().prettyPrint(sb, true, indent + PRINT_INDENT); //);
} else {
getValue().prettyPrint(sb, false, indent);
}
return sb;
}
eq MappingElement.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (isEmpty()) {
sb.append("{}");
} else {
boolean first = true;
for (KeyValuePair pair : getKeyValuePairList()) {
if (!first || printIndent) sb.append(indent);
first = false;
pair.prettyPrint(sb, false, indent); // + PRINT_INDENT
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
return sb;
}
} }
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.getChild().containedFileName() = getFileName();
syn boolean Element.isComplex() = false;
eq ComplexElement.isComplex() = true;
syn boolean Element.isEmpty() = false;
eq MappingElement.isEmpty() = getNumKeyValuePair() == 0;
eq ListElement.isEmpty() = getNumElement() == 0;
}
aspect Helper {
public static ValueElement ValueElement.of(int value) {
return new ValueElement(String.valueOf(value));
}
public static ValueElement ValueElement.of(boolean value) {
return new ValueElement(String.valueOf(value));
}
public static ValueElement ValueElement.of(String value) {
return new ValueElement(value);
}
public static StringElement StringElement.of(String value) {
return new StringElement(value);
}
public void MappingElement.addKeyValuePair(String key, Element value) {
addKeyValuePair(new KeyValuePair(key, value));
}
}
Document ::= <FileName> ComplexElement* ;
abstract Element ;
abstract ComplexElement : Element ;
MappingElement : ComplexElement ::= KeyValuePair* ;
KeyValuePair : ComplexElement ::= <Key> Value:Element ;
ListElement : ComplexElement ::= Element* ;
abstract SimpleElement : Element ;
ValueElement : SimpleElement ::= <Value> ;
StringElement : SimpleElement ::= <Value> ;
...@@ -60,7 +60,7 @@ aspect MustacheNodesToYAML { ...@@ -60,7 +60,7 @@ aspect MustacheNodesToYAML {
} }
root.addKeyValuePair("TokenComponents", tokenComponents); root.addKeyValuePair("TokenComponents", tokenComponents);
doc.addComplexElement(root); doc.setRootElement(root);
return doc; return doc;
} }
...@@ -151,5 +151,11 @@ aspect MustacheNodesToYAML { ...@@ -151,5 +151,11 @@ aspect MustacheNodesToYAML {
} }
return innerMappingDefinitions; return innerMappingDefinitions;
} }
}
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.getChild().containedFileName() = getFileName();
} }
Subproject commit 2bf869031ffc69bdb88dafd2cb4464a26502ae2b
...@@ -82,7 +82,7 @@ public class SimpleMain { ...@@ -82,7 +82,7 @@ public class SimpleMain {
firstLevel.addKeyValuePair(goalPoses); firstLevel.addKeyValuePair(goalPoses);
root.setValue(firstLevel); root.setValue(firstLevel);
doc.addComplexElement(root); doc.setRootElement(root);
System.out.println(doc.prettyPrint()); System.out.println(doc.prettyPrint());
} }
......
Supports Markdown
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