Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 28ac86405ec1240f57bf70f8485b7d209a4767f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
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
219
220
221
222
223
224
grammar org.eclipse.emf.ecore.xcore.Xcore 
  with org.eclipse.xtext.xbase.Xbase 

import "platform:/resource/org.eclipse.emf.ecore.xcore/model/Xcore.ecore"
import "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore" as ecore
import "platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore" as genmodel
// import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.ecore" as xbase


XPackage returns XPackage:
	(annotations+=XAnnotation)*
	'package'
	name = QualifiedName
	(importDirectives += XImportDirective)*
	(annotationDirectives += XAnnotationDirective)*
	(classifiers += XClassifier)*
;

XAnnotation:
	'@' source=[XAnnotationDirective|ValidID]
	('(' details+=XStringToStringMapEntry (',' details+=XStringToStringMapEntry)* ')')?
;

XStringToStringMapEntry:
	key=QualifiedName
	'='
	value=STRING
;

XImportDirective:
	'import' importedNamespace=QualifiedNameWithWildcard
;

QualifiedNameWithWildcard returns ecore::EString:
  QualifiedName '.*'?
;

XAnnotationDirective:
	'annotation' sourceURI=STRING 'as' name=ValidID
;

XClassifier:
	XClass |
	XDataType |
	XEnum
;

XDataType:
	(annotations+=XAnnotation)*
	'type' name = ID 
	('<' typeParameters+=XTypeParameter (',' typeParameters+=XTypeParameter)* '>')?
	'wraps' instanceTypeName=QualifiedName
	(
	  /*
	   * In scope for create should be what's visible in XyzFactoryImpl and 'this' will denote the literal value.
	   * The block expression must yield null or an instance of the wrapped type.
	   */
	  (serializable?='create' createBody=XBlockExpression)? &
	  /*
	   * In scope for create should be what's visible in XyzFactoryImpl 
	   * and 'this' will denote an instance of the wrapped type.
	   * The block expression must yield a java.lang.String.
	   */
	  ('convert' convertBody=XBlockExpression)?
	)
;

XEnum:
	(annotations+=XAnnotation)*
	'enum' name = ID
	'{'
	  (literals+=XEnumLiteral ((',')? literals+=XEnumLiteral)*)?
	'}'
;

XEnumLiteral:
	(annotations+=XAnnotation)*
    name=ID 
    ('as' literal=STRING)? 
    ('=' value=INT)?
;

XClass:
	{XClass}
	(annotations+=XAnnotation)*
	((abstract?='abstract'? 'class') | interface?= 'interface') name = ID
	('<' typeParameters+=XTypeParameter (',' typeParameters+=XTypeParameter)* '>')?
	('extends' superTypes+=XGenericType)?
	('wraps' instanceTypeName=QualifiedName)?
	'{'
	   (members+=XMember)*
	'}'
;

XMember:
	XOperation |
	XReference |
	XAttribute
;

XAttribute:
	(annotations+=XAnnotation)*
	(
	  (unordered?='unordered')? &
	  (unique?='unique')? &
	  (readonly?='readonly')? &
	  (transient?='transient')? &
	  (volatile?='volatile')? &
	  (unsettable?='unsettable')? &
	  (derived?='derived')? &
	  (iD?='id')?
	)
    (type=XGenericType | 'void')
	multiplicity=XMultiplicity?
    name=ID
    ('=' defaultValueLiteral=STRING)?
	/*
	 * In scope for getBody should be what's visible in AbcImpl
	 * and 'this' will denote an instance of the feature's type.
	 * The block expression must yield a value of the feature's type.
	 */
	(('get' getBody=XBlockExpression)? &
	 ('set' setBody=XBlockExpression)? &
	 ('isSet' isSetBody=XBlockExpression)? &
	 ('unset' unsetBody=XBlockExpression)?)
;

XReference:
	(annotations+=XAnnotation)*
	((resolveProxies?='resolving'? & (containment?='containment' | container?='container')) | (local?='local'? & 'refers'))
	(
	  (unordered?='unordered')? &
	  (unique?='unique')? &
	  (readonly?='readonly')? &
	  (transient?='transient')? &
	  (volatile?='volatile')? &
	  (unsettable?='unsettable')? &
	  (derived?='derived')?
	)
	type=XGenericType
	multiplicity=XMultiplicity?
    name=ID
    (
      'opposite' opposite=[genmodel::GenFeature|ValidID] 
    )?
    (
      'keys' keys+=[genmodel::GenFeature|ValidID] (',' keys+=[genmodel::GenFeature|ValidID])*
    )?
	/*
	 * In scope for getBody should be what's visible in AbcImpl
	 * and 'this' will denote an instance of the feature's type.
	 * The block expression must yield a value of the feature's type.
	 */
	(('get' getBody=XBlockExpression)? &
	 ('set' setBody=XBlockExpression)? &
	 ('isSet' isSetBody=XBlockExpression)? &
	 ('unset' unsetBody=XBlockExpression)?)
;

XOperation:
	(annotations+=XAnnotation)*
	'op'
	(
	  unordered?='unordered' unique?='unique'? |
	  unique?='unique' unordered?='unordered'? 
	)?
	('<' typeParameters+=XTypeParameter (',' typeParameters+=XTypeParameter)* '>')? 
	(type=XGenericType | 'void') 
	multiplicity=XMultiplicity?
	name=ID 
	'(' (parameters+=XParameter (',' parameters+=XParameter)*)? ')' 
	('throws' exceptions+=XGenericType (',' exceptions+=XGenericType)*)?
	/*
	 * This is the logic for the operation.
	 * How are we going to resolve all references that are in scope for Xbase language?
	 * Will things like variables that are actually there in generated in the Impl class be accessible directly?
	 */
	(body=XBlockExpression)?
;

XParameter:
	(annotations+=XAnnotation)*
	(
	  unordered?='unordered' unique?='unique'? |
	  unique?='unique' unordered?='unordered'? 
	)?
    type=XGenericType 
    multiplicity=XMultiplicity?
    name=ID
;

XTypeParameter :
	(annotations+=XAnnotation)*
	name=ID ('extends' bounds+=XGenericType ('&' bounds+=XGenericType)*)?
;

XMultiplicity returns XMultiplicity:
	'['
	('?' | '*' | '+' | (INT ('..' (INT | '?' | '*'))?))?
	']'
;

XBlockExpression returns xbase::XBlockExpression:
 {xbase::XBlockExpression}
 '{'
  (expressions+=XExpressionInsideBlock ';'?)*
 '}'
;

XGenericType returns XGenericType:
  // classifier=[XClassifier|QualifiedName] (=>'<' typeArguments+=XGenericTypeArgument (',' typeArguments+=XGenericTypeArgument)* '>')?
  type=[genmodel::GenBase|QualifiedName] (=>'<' typeArguments+=XGenericTypeArgument (',' typeArguments+=XGenericTypeArgument)* '>')?
;

XGenericTypeArgument returns XGenericType :
	XGenericType |
	XGenericWildcardTypeArgument
;

XGenericWildcardTypeArgument returns XGenericType :
   {XGenericType}
   '?' ('extends' upperBound=XGenericType | 'super' lowerBound=XGenericType)?
;

Back to the top