RelAst.parser 5.29 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
2
3
4
GrammarFile goal
  = declaration.d goal.p     {: p.getDeclarationList().insertChild(d, 0); return p; :}
  |                          {: return new GrammarFile(); :}
;
Johannes Mey's avatar
Johannes Mey committed
5

Johannes Mey's avatar
Johannes Mey committed
6
7
8
9
10
11
12
13
14
15
16
Declaration declaration
  = type_decl
  | relation
  | comment
;

Comment comment
  = COMMENT  {: return new Comment(COMMENT); :};

TypeDecl type_decl
  = ID components_opt.c SCOL
Johannes Mey's avatar
Johannes Mey committed
17
18
    {:
      TypeDecl result = new TypeDecl();
Johannes Mey's avatar
Johannes Mey committed
19
      result.setName(ID);
Johannes Mey's avatar
Johannes Mey committed
20
21
22
23
      result.setAbstract(false);
      result.setComponentList(c);
      return result;
    :}
Johannes Mey's avatar
Johannes Mey committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  | ID COL ID.s components_opt.c SCOL
    {:
      TypeDecl result = new TypeDecl();
      result.setName(ID);
      result.setAbstract(false);
      result.setSuperType(TypeDecl.createRef(s));
      result.setComponentList(c);
      return result;
    :}
  | ABSTRACT ID components_opt.c SCOL
    {:
      TypeDecl result = new TypeDecl();
      result.setName(ID);
      result.setAbstract(true);
      result.setComponentList(c);
      return result;
    :}
  | ABSTRACT ID COL ID.s components_opt.c SCOL
    {:
      TypeDecl result = new TypeDecl();
      result.setName(ID);
      result.setAbstract(true);
      result.setSuperType(TypeDecl.createRef(s));
      result.setComponentList(c);
      return result;
    :}
;

JastAddList components_opt
  = /* empty */             {: return new JastAddList(); :}
Johannes Mey's avatar
Johannes Mey committed
54
  | ASSIGN components.l     {: return l; :}
Johannes Mey's avatar
Johannes Mey committed
55
;
Johannes Mey's avatar
Johannes Mey committed
56

Johannes Mey's avatar
Johannes Mey committed
57
58
JastAddList components
  = /* empty */                 {: return new JastAddList(); :}
Johannes Mey's avatar
Johannes Mey committed
59
  | components.l component.c    {: return l.add(c); :}
Johannes Mey's avatar
Johannes Mey committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
;

Component component
  = SLASH actual_component.c SLASH
      {:
        c.setNTA(true);
        return c;
      :}
  | actual_component
;

Component actual_component
  = ID.name COL ID.type STAR
    {:
      ListComponent result = new ListComponent();
      result.setName(name);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | ID.name COL ID.type
    {:
      NormalComponent result = new NormalComponent();
      result.setName(name);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | ID.type STAR
    {:
      ListComponent result = new ListComponent();
      result.setName(type);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | ID.type
    {:
      NormalComponent result = new NormalComponent();
      result.setName(type);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | LBRACKET ID.name COL ID.type RBRACKET
    {:
      OptComponent result = new OptComponent();
      result.setName(name);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | LBRACKET ID.type RBRACKET
    {:
      OptComponent result = new OptComponent();
      result.setName(type);
      result.setTypeDecl(TypeDecl.createRef(type));
      return result;
    :}
  | LT ID.name COL java_type_use.type GT
    {:
      TokenComponent result = new TokenComponent();
      result.setName(name);
      result.setJavaTypeUse(type);
      return result;
    :}
  | LT ID.type GT
    {:
      TokenComponent result = new TokenComponent();
      result.setName(type);
      result.setJavaTypeUse(new SimpleJavaTypeUse(type));
      return result;
    :}
;


JavaTypeUse java_type_use
  = parameterized_java_type_use
  | simple_java_type_use
;

ArrayList qualified_name
  = ID
  | qualified_name DOT ID
;


JastAddList java_type_use_list
  = java_type_use.u                                 {: return new JastAddList().add(u); :}
  | java_type_use_list.l COMMA java_type_use.u      {: return l.add(u); :}
;

SimpleJavaTypeUse simple_java_type_use
  = qualified_name.n
    {:
      return new SimpleJavaTypeUse((String)n.stream().map( x -> ((Symbol)x).value.toString()).collect(java.util.stream.Collectors.joining(".")));
    :}
;

ParameterizedJavaTypeUse parameterized_java_type_use
  = simple_java_type_use.i LT java_type_use_list.l GT
    {:
      return new ParameterizedJavaTypeUse(i.getName(), l);
    :}
;

Relation relation
  = RELATION unnamed_role.a LEFT navigable_role.b SCOL
    {:
       LeftDirectedRelation result = new LeftDirectedRelation();
       result.setSource(b);
       result.setTarget(a);
       return result;
    :}
  | RELATION navigable_role.a RIGHT unnamed_role.b SCOL
    {:
       RightDirectedRelation result = new RightDirectedRelation();
       result.setSource(a);
       result.setTarget(b);
       return result;
    :}
  | RELATION navigable_role.a BIDIRECTIONAL navigable_role.b SCOL
    {:
       BidirectionalRelation result = new BidirectionalRelation();
       result.setLeft(a);
       result.setRight(b);
       return result;
    :}
;


UnnamedRole unnamed_role
  = ID.type
    {:
      UnnamedRole result = new UnnamedRole();
      result.setType(TypeDecl.createRef(type));
      return result;
    :}
  | navigable_role
;

NavigableRole navigable_role
  = ID.type DOT ID.name
    {:
      NormalRole result = new NormalRole();
      result.setName(name);
      result.setType(TypeDecl.createRef(type));
      return result;
    :}
  | ID.type DOT ID.name STAR
    {:
      ListRole result = new ListRole();
      result.setName(name);
      result.setType(TypeDecl.createRef(type));
      return result;
    :}
  | ID.type DOT ID.name QUESTION_MARK
    {:
      OptRole result = new OptRole();
      result.setName(name);
      result.setType(TypeDecl.createRef(type));
      return result;
    :}
;