AbstractGrammar.jadd 4.5 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
aspect BackendAbstractGrammar {

  public static String ASTNode.listInterface = "java.util.List";
  public static String ASTNode.listClass = "java.util.ArrayList";
  public static String ASTNode.jastAddListType = "List";
  public static String ASTNode.jastAddOptType = "Opt";

  public String Program.generateAbstractGrammar() {
    StringBuilder sb = new StringBuilder();
    generateAbstractGrammar(sb);
    return sb.toString();
  }

Johannes Mey's avatar
Johannes Mey committed
14
15
16
  public void Program.generateAbstractGrammar(StringBuilder b) {
    for (GrammarFile file : getGrammarFileList()) {
      file.generateAbstractGrammar(b);
Johannes Mey's avatar
Johannes Mey committed
17
18
19
    }
  }

Johannes Mey's avatar
Johannes Mey committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  public void GrammarFile.generateAbstractGrammar(StringBuilder b) {
    b.append("// Grammar for file ").append(getFileName()).append("\n");
    super.generateAbstractGrammar(b);
    b.append("\n");
  }

  public void Grammar.generateAbstractGrammar(StringBuilder b) {

    for (Declaration decl : getDeclarationList()) {
      decl.generateAbstractGrammar(b);
    }
  }

  abstract public void Declaration.generateAbstractGrammar(StringBuilder b);

  public void Comment.generateAbstractGrammar(StringBuilder b) {
    b.append(getText()).append("\n");
  }

  public void TypeDecl.generateAbstractGrammar(StringBuilder b) {
Johannes Mey's avatar
Johannes Mey committed
40
    if (getAbstract()) {
Johannes Mey's avatar
Johannes Mey committed
41
      b.append("abstract ");
Johannes Mey's avatar
Johannes Mey committed
42
    }
Johannes Mey's avatar
Johannes Mey committed
43
44
45
    b.append(getName()).append(" ");
    if (hasSuperType()) {
      b.append(": ").append(getSuperType().getName()).append(" ");
Johannes Mey's avatar
Johannes Mey committed
46
    }
Johannes Mey's avatar
Johannes Mey committed
47
48
49
50
    b.append("::=");
    for (Component component : getComponentList()) {
      b.append(" ");
      component.generateAbstractGrammar(b);
Johannes Mey's avatar
Johannes Mey committed
51
    }
Johannes Mey's avatar
Johannes Mey committed
52
53
54
55
56
57
58
59
    b.append(";\n");
  }

  public abstract void Component.generateAbstractGrammar(StringBuilder b);

  public void NormalComponent.generateAbstractGrammar(StringBuilder b) {
    if (getNTA()) {
      b.append("/");
Johannes Mey's avatar
Johannes Mey committed
60
61
    }

Johannes Mey's avatar
Johannes Mey committed
62
63
64
65
66
67
68
    if (!getName().equals("")) {
      b.append(getName()).append(":");
    }
    b.append(getTypeDecl().getName());
    if (getNTA()) {
      b.append("/");
    }
Johannes Mey's avatar
Johannes Mey committed
69
70
  }

Johannes Mey's avatar
Johannes Mey committed
71
72
73
74
75
76
77
78
79
80
81
  public void ListComponent.generateAbstractGrammar(StringBuilder b) {
    if (getNTA()) {
      b.append("/");
    }

    if (!getName().equals("")) {
      b.append(getName()).append(":");
    }
    b.append(getTypeDecl().getName()).append("*");
    if (getNTA()) {
      b.append("/");
Johannes Mey's avatar
Johannes Mey committed
82
83
    }
  }
Johannes Mey's avatar
Johannes Mey committed
84
85
86
87
88
89
90
91
92
93
94
95
96

  public void OptComponent.generateAbstractGrammar(StringBuilder b) {
    if (getNTA()) {
      b.append("/");
    }
    b.append("[");
    if (!getName().equals("")) {
      b.append(getName()).append(":");
    }
    b.append(getTypeDecl().getName()).append("]");
    if (getNTA()) {
      b.append("/");
    }
Johannes Mey's avatar
Johannes Mey committed
97
  }
Johannes Mey's avatar
Johannes Mey committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111

  public void TokenComponent.generateAbstractGrammar(StringBuilder b) {
    if (getNTA()) {
      b.append("/");
    }
    b.append("<");
    if (!getName().equals("")) {
      b.append(getName()).append(":");
    }
    getJavaTypeUse().generateAbstractGrammar(b);
    b.append(">");
    if (getNTA()) {
      b.append("/");
    }
Johannes Mey's avatar
Johannes Mey committed
112
113
  }

Johannes Mey's avatar
Johannes Mey committed
114
115
116
117
  abstract public void JavaTypeUse.generateAbstractGrammar(StringBuilder b);

  public void SimpleJavaTypeUse.generateAbstractGrammar(StringBuilder b) {
    b.append(getName());
Johannes Mey's avatar
Johannes Mey committed
118
119
  }

Johannes Mey's avatar
Johannes Mey committed
120
121
122
123
124
125
126
127
128
129
  public void ParameterizedJavaTypeUse.generateAbstractGrammar(StringBuilder b) {
    b.append("<");
    boolean first = true;
    for (JavaTypeUse javaTypeUse : getJavaTypeUseList()) {
      if (first) {
        first = false;
      } else {
        b.append(", ");
      }
      javaTypeUse.generateAbstractGrammar(b);
Johannes Mey's avatar
Johannes Mey committed
130
    }
Johannes Mey's avatar
Johannes Mey committed
131
    b.append(">");
Johannes Mey's avatar
Johannes Mey committed
132
133
  }

Johannes Mey's avatar
Johannes Mey committed
134
135
136
137
138
139
140
141
  abstract public void Relation.generateAbstractGrammar(StringBuilder b);

  public void DirectedRelation.generateAbstractGrammar(StringBuilder b) {
    b.append("rel ");
    getSource().generateAbstractGrammar(b);
    b.append(" -> ");
    getTarget().generateAbstractGrammar(b);
    b.append(";\n");
Johannes Mey's avatar
Johannes Mey committed
142
143
  }

Johannes Mey's avatar
Johannes Mey committed
144
145
146
147
148
149
  public void BidirectionalRelation.generateAbstractGrammar(StringBuilder b) {
    b.append("rel ");
    getLeft().generateAbstractGrammar(b);
    b.append(" <-> ");
    getRight().generateAbstractGrammar(b);
    b.append(";\n");
Johannes Mey's avatar
Johannes Mey committed
150
151
  }

Johannes Mey's avatar
Johannes Mey committed
152
153
154
155
156
157
158
159
  abstract public void Role.generateAbstractGrammar(StringBuilder b);

  public void NormalRole.generateAbstractGrammar(StringBuilder b) {
    b.append(getType().getName()).append(".").append(getName());
  }

  public void ListRole.generateAbstractGrammar(StringBuilder b) {
    b.append(getType().getName()).append(".").append(getName()).append("*");
Johannes Mey's avatar
Johannes Mey committed
160
161
  }

Johannes Mey's avatar
Johannes Mey committed
162
163
  public void OptRole.generateAbstractGrammar(StringBuilder b) {
    b.append(getType().getName()).append(".").append(getName()).append("?");
Johannes Mey's avatar
Johannes Mey committed
164
165
  }

Johannes Mey's avatar
Johannes Mey committed
166
167
  public void UnnamedRole.generateAbstractGrammar(StringBuilder b) {
    b.append(getType().getName());
Johannes Mey's avatar
Johannes Mey committed
168
169
  }

Johannes Mey's avatar
Johannes Mey committed
170

Johannes Mey's avatar
Johannes Mey committed
171
}