Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mustache
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
mustache
Commits
130a96ef
Commit
130a96ef
authored
4 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
Printing without deleting newlines.
parent
2bf86903
Branches
master
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Mustache.relast
+1
-1
1 addition, 1 deletion
Mustache.relast
Navigation.jrag
+6
-0
6 additions, 0 deletions
Navigation.jrag
Printing.jrag
+17
-10
17 additions, 10 deletions
Printing.jrag
with
24 additions
and
11 deletions
Mustache.relast
+
1
−
1
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> ;
...
...
This diff is collapsed.
Click to expand it.
Navigation.jrag
+
6
−
0
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;
}
This diff is collapsed.
Click to expand it.
Printing.jrag
+
17
−
10
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);
sb.append("\n");
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
sb.append("\n");
pair.prettyPrint(sb, false, indent);
if (pair.needTrailingNewLine()) {
sb.append("\n");
}
}
// delete last newline
sb.deleteCharAt(sb.length() - 1);
}
return sb;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment