Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
JastAdd
mustache
Compare Revisions
2bf869031ffc69bdb88dafd2cb4464a26502ae2b...130a96efa74f90c9d2f8634e2ddc6d6c705f146d
Commits (1)
Printing without deleting newlines.
· 130a96ef
René Schöne
authored
Aug 27, 2020
130a96ef
Show whitespace changes
Inline
Side-by-side
Mustache.relast
View file @
130a96ef
...
...
@@ -2,7 +2,7 @@ Document ::= <FileName> [RootElement:ComplexElement] ;
abstract Element ;
abstract ComplexElement : Element ;
MappingElement : ComplexElement ::= KeyValuePair* ;
KeyValuePair
: ComplexElement
::= <Key> Value:Element ;
KeyValuePair ::= <Key> Value:Element ;
ListElement : ComplexElement ::= Element* ;
abstract SimpleElement : Element ;
ValueElement : SimpleElement ::= <Value> ;
...
...
Navigation.jrag
View file @
130a96ef
...
...
@@ -5,4 +5,10 @@ aspect Navigation {
syn boolean Element.isEmpty() = false;
eq MappingElement.isEmpty() = getNumKeyValuePair() == 0;
eq ListElement.isEmpty() = getNumElement() == 0;
inh ListElement Element.containingListElement();
eq ListElement.getElement().containingListElement() = this;
eq KeyValuePair.getValue().containingListElement() = null;
eq Document.getRootElement().containingListElement() = null;
}
Printing.jrag
View file @
130a96ef
aspect Printing {
String ASTNode.PRINT_INDENT = " ";
inh boolean KeyValuePair.isLast();
inh boolean Element.isLast();
eq MappingElement.getKeyValuePair(int i).isLast() = i == getNumKeyValuePair() - 1;
eq ListElement.getElement(int i).isLast() = i == getNumElement() - 1;
eq Document.getRootElement().isLast() = true;
syn boolean KeyValuePair.needTrailingNewLine() = !this.isLast();
syn boolean Element.needTrailingNewLine() = !this.isLast() || containingListElement() == null;
public String Document.prettyPrint() {
return prettyPrint(true);
}
...
...
@@ -8,7 +16,7 @@ aspect Printing {
public String Document.prettyPrint(boolean prependCreationComment) {
StringBuilder sb = new StringBuilder();
if (prependCreationComment) {
sb.append("#
RagConnect c
reated at ").append(java.time.Instant.now()).append("\n");
sb.append("#
C
reated at ").append(java.time.Instant.now()).append("\n");
}
if (hasRootElement()) {
getRootElement().prettyPrint(sb, false, "");
...
...
@@ -41,21 +49,20 @@ aspect Printing {
for (Element element : getElementList()) {
sb.append(indent).append("- ");
element.prettyPrint(sb, false, indent + PRINT_INDENT);
if (element.needTrailingNewLine()) {
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
}
return sb;
}
@Override
protected StringBuilder 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);
//);
getValue().prettyPrint(sb, true, indent + PRINT_INDENT);
} else {
sb.append(" ");
getValue().prettyPrint(sb, false, indent);
...
...
@@ -72,11 +79,11 @@ aspect Printing {
for (KeyValuePair pair : getKeyValuePairList()) {
if (!first || printIndent) sb.append(indent);
first = false;
pair.prettyPrint(sb, false, indent); // + PRINT_INDENT
pair.prettyPrint(sb, false, indent);
if (pair.needTrailingNewLine()) {
sb.append("\n");
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
}
return sb;
}
...
...