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

*

parents
aspect Helpers {
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> ;
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 Printing {
String ASTNode.PRINT_INDENT = " ";
syn String MappingDefinitionType.prettyPrint();
eq JavaMappingDefinitionType.prettyPrint() = getType().getName();
eq JavaArrayMappingDefinitionType.prettyPrint() = getType().getName() + "[]";
syn String JavaTypeUse.prettyPrint() {
StringBuilder sb = new StringBuilder();
generateAbstractGrammar(sb);
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;
}
}
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