RelAst.parser 6.02 KB
Newer Older
1
GrammarFile goal
2
  = comment_list.c grammar_file.f {: f.getDeclarationList().insertChild(new EmptyDeclaration(c), 0); return f; :}
3
4
5
6
7
;

GrammarFile grammar_file
  = declaration.d grammar_file.f {: f.getDeclarationList().insertChild(d, 0); return f; :}
  |                              {: return new GrammarFile(); :}
8
9
10
;

Declaration declaration
11
12
13
14
15
16
17
  = type_decl.d comment_list.c {: d.setCommentList(c); return d; :}
  | relation.r  comment_list.c {: r.setCommentList(c); return r; :}
;

// this method would be create by the JAstAddParser from a usage of
// 'comment+' in a rule, but only for the standard list class 'List'.
JastAddList comment_list
18
19
  = comment.c comment_list.l {: l.insertChild(c, 0); return l; :}
  | /* epsilon */            {: return new JastAddList(); :}
20
21
22
;

Comment comment
23
24
25
26
27
  = WHITESPACE.c        {: return new WhitespaceComment(c); :}
  | MULTILINECOMMENT.c  {: return new MultiLineComment(c.substring(2,c.length()-2));  :}
  | DOCCOMMENT.c        {: return new DocComment(c.substring(3,c.length()-2));        :}
  | SINGLELINECOMMENT.c {: return new SingleLineComment(c.substring(2)); :}
;
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
54
55
56
57
58
59
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

TypeDecl type_decl
  = ID components_opt.c SCOL
    {:
      TypeDecl result = new TypeDecl();
      result.setName(ID);
      result.setAbstract(false);
      result.setComponentList(c);
      return result;
    :}
  | 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(); :}
  | ASSIGN components.l     {: return l; :}
;

JastAddList components
  = /* empty */                 {: return new JastAddList(); :}
  | components.l component.c    {: return l.add(c); :}
;

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;
    :}
135
  | LT ID.name GT
136
137
    {:
      TokenComponent result = new TokenComponent();
138
      result.setName(name);
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
219
220
221
222
223
224
225
226
227
228
229
230
231
      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;
    :}
;