summaryrefslogtreecommitdiffstats
blob: 4d62e2fe8723a69ab9c21f43a3528bd70c7c84e3 (plain)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*******************************************************************************
 * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
 * 		Eyrak Paen
 *
 ******************************************************************************/

/**
 * @author Henrik Rentz-Reichert and Thomas Schuetz
 *
 * Xtext Grammar for ROOM models 
 * this grammar is the base for the ROOM tool eTrice
 * 
 */

grammar org.eclipse.etrice.core.Room with org.eclipse.etrice.core.fsm.FSM

import "http://www.eclipse.org/etrice/core/fsm/FSM"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate room "http://www.eclipse.org/etrice/Room"

RoomModel :
'RoomModel' name=FQN (docu=Documentation)? '{'
	(imports+=Import)*
	(
		primitiveTypes+=PrimitiveType	|
		enumerationTypes+=EnumerationType	|
		externalTypes+=ExternalType	|
		dataClasses+=DataClass	|
		protocolClasses+=GeneralProtocolClass |
		actorClasses+=ActorClass  |
		subSystemClasses+=SubSystemClass |
		systems+=LogicalSystem |
		annotationTypes+=AnnotationType
	)*
	'}'
;

RoomClass: DataType | GeneralProtocolClass | StructureClass;
StructureClass: ActorContainerClass | LogicalSystem;
ActorContainerClass: ActorClass | SubSystemClass;

// **************************************************************
// data class

VarDecl:
	name=ID ':' refType=RefableType;

RefableType: type=[DataType|FQN] (ref?='ref')?;

DataType: PrimitiveType | EnumerationType | ComplexType;
ComplexType: DataClass | ExternalType;

PrimitiveType: 'PrimitiveType' name=ID ':' type=LiteralType '->' targetName=FQN ('(' castName=FQN ')')? 'default' defaultValueLiteral=STRING (docu=Documentation)?;

EnumerationType:
	'Enumeration' name=ID (docu=Documentation)? ('of' primitiveType=[PrimitiveType|FQN])? '{'
		(literals+=EnumLiteral (',' literals+=EnumLiteral)*)?
	'}'
;

EnumLiteral:
	name=ID ('=' literal=IntLiteral)?
;

ExternalType: 'ExternalType' name=ID '->' targetName=STRING ('default' defaultValueLiteral=STRING)? (docu=Documentation)?;

// TODOHRR: define detail level language?
DataClass:
	'DataClass' name=ID (docu=Documentation)? ('extends' base=[DataClass|FQN])? '{'
		annotations+=Annotation*
		('usercode1' userCode1=DetailCode)?
		('usercode2' userCode2=DetailCode)?
		('usercode3' userCode3=DetailCode)?
		attributes+=Attribute*
		operations+=StandardOperation*
	'}';
	
	
Attribute:
	'Attribute' name=ID ('[' size=INT ']')? ':' type=RefableType ('=' defaultValueLiteral=STRING)? (docu=Documentation)?;

Operation: StandardOperation | PortOperation; 

StandardOperation:
	'Operation' (destructor?='~')? name=ID '(' (arguments+=VarDecl (',' arguments+=VarDecl)*)? ')' (':' ('void' | (returnType=RefableType)))?
		(docu=Documentation)?
		detailCode=DetailCode
;

PortOperation:
    'Operation' name=ID '(' (arguments+=VarDecl (',' arguments+=VarDecl)*)? ')' ( (':' ('void' | (returnType=RefableType))) | ('sends' sendsMsg=[Message|ID]) )?
            (docu=Documentation)?
            detailCode=DetailCode
; 

// **************************************************************
// protocol class

enum CommunicationType:
	EVENT_DRIVEN='eventdriven' |
	DATA_DRIVEN='datadriven' |
	SYNCHRONOUS='sync'
;

GeneralProtocolClass: ProtocolClass | CompoundProtocolClass;

ProtocolClass:
	(commType=CommunicationType)?
	'ProtocolClass' name=ID (docu=Documentation)? ('extends' base=[ProtocolClass|FQN])? '{'
		annotations+=Annotation*
		('usercode1' userCode1=DetailCode)?
		('usercode2' userCode2=DetailCode)?
		('usercode3' userCode3=DetailCode)?
		('incoming' '{' incomingMessages+=Message* '}')?
		('outgoing' '{' outgoingMessages+=Message* '}')?
		('regular' 'PortClass' regular=PortClass)?
		('conjugated' 'PortClass' conjugated=PortClass)?
		(semantics=ProtocolSemantics)?
	'}';
	
CompoundProtocolClass:
	'CompoundProtocolClass' name=ID (docu=Documentation)? '{'
		annotations+=Annotation*
		subProtocols+=SubProtocol*
	'}'
;

SubProtocol: 'SubProtocol' name=ID ':' protocol=[GeneralProtocolClass|FQN];

Message:
	(priv?='private')? 'Message' name=ID '(' (data=VarDecl)? ')'
	(docu=Documentation)?;

PortClass:
	{PortClass}
	'{'
		('usercode' userCode=DetailCode)?
		(attributes+=Attribute |
		operations+=PortOperation |
		msgHandlers+=MessageHandler)*
	'}';

MessageHandler: InMessageHandler|OutMessageHandler;

InMessageHandler:
	'handle' 'incoming' msg=[Message|ID]
		detailCode=DetailCode
	;

OutMessageHandler:
	'handle' 'outgoing' msg=[Message|ID]
		detailCode=DetailCode
	;

// **************************************************************
// actor class

ModelComponent: ActorClass;

// some notes on ports
//
// in ROOM ports can be contained in the structure and/or the interface
// p in s ==> internal end port
// p in i ==> relay port
// p in i and p in s ==> external end port
// since double containment is not supported we decided to define external ports as reference to interface ports
ActorClass:
	(abstract?='abstract'? & commType=ComponentCommunicationType?)
	'ActorClass' name=ID (docu=Documentation)? ('extends' base=[ActorClass|FQN])? '{'
		annotations+=Annotation*
		('Interface' '{'
			interfacePorts+=Port*
			serviceProvisionPoints+=SPP*
		'}')?
		('Structure' (structureDocu=Documentation)? '{'
			('usercode1' userCode1=DetailCode)?
			('usercode2' userCode2=DetailCode)?
			('usercode3' userCode3=DetailCode)?
			((internalPorts+=Port |
			externalPorts+=ExternalPort)* &
			actorRefs+=ActorRef* &
			serviceImplementations+=ServiceImplementation* &
			serviceAccessPoints+=SAP* &
			bindings+=Binding* &
			connections+=LayerConnection* &
			attributes+=Attribute*)
		'}')?
		('Behavior' (behaviorDocu=Documentation)? '{'
			behaviorAnnotations+=Annotation*
			operations+=StandardOperation*
			(stateMachine=StateMachine)?
		'}')?
	'}';

InterfaceItem: Port | SAP | SPP;

Port:
	(conjugated?='conjugated')? 'Port' name=ID (multiplicity=MULTIPLICITY)? ':' protocol=[GeneralProtocolClass|FQN] (docu=Documentation)?;
ExternalPort:
	'external' 'Port' interfacePort=[Port|ID] ;

SAP:
	'SAP' name=ID ':' protocol=[ProtocolClass|FQN] ;

SPP:
	'SPP' name=ID ':' protocol=[ProtocolClass|FQN] ;
ServiceImplementation:
	'ServiceImplementation' 'of' spp=[SPP|ID];

LogicalSystem:
	'LogicalSystem' name=ID (docu=Documentation)? '{'
		annotations+=Annotation*
		(subSystems+=SubSystemRef* &
		bindings+=Binding* &
		connections+=LayerConnection*)
	'}';

ActorContainerRef: SubSystemRef | ActorRef;

SubSystemRef:
	'SubSystemRef' name=ID ':' type=[SubSystemClass|FQN] (docu=Documentation)?;

SubSystemClass:
	'SubSystemClass' name=ID (docu=Documentation)? '{'
		annotations+=Annotation*
		('usercode1' userCode1=DetailCode)?
		('usercode2' userCode2=DetailCode)?
		('usercode3' userCode3=DetailCode)?
		(relayPorts+=Port* &
		serviceProvisionPoints+=SPP* &
		actorRefs+=ActorRef* &
		bindings+=Binding* &
		connections+=LayerConnection* &
		threads+=LogicalThread* &
		actorInstanceMappings+=ActorInstanceMapping*)
	'}';

LogicalThread:
	'LogicalThread' name=ID
;

ActorInstanceMapping:
	'ActorInstanceMapping' path=RefPath '->' thread=[LogicalThread|ID] ('{'
		actorInstanceMappings+=ActorInstanceMapping*
	'}')?
;

RefPath:
	refs+=RefSegment ('/' refs+=RefSegment)*;

RefSegment:
	ref=ID (':' idx=INT)?
;
	
Binding:
	'Binding' endpoint1=BindingEndPoint 'and' endpoint2=BindingEndPoint ;
	
BindingEndPoint:
	(actorRef=[ActorContainerRef|ID]'.')?  port=[Port|ID] ('sub' sub=[SubProtocol|ID])?;

LayerConnection:
	'LayerConnection' from=SAPoint 'satisfied_by' to=SPPoint 
;

SAPoint: RefSAPoint | RelaySAPoint;

RefSAPoint:
	// satisfies a sub actor
	'ref' ref=[ActorContainerRef|ID];
RelaySAPoint:
	// relays from own interface
	'relay_sap' relay=[SPP|ID];

SPPoint:
	ref=[ActorContainerRef|ID] '.'  service=[SPP|ID]
;

ActorRef:
	(refType=ReferenceType)? 'ActorRef' name=ID (multiplicity=MULTIPLICITY)? ':' type=[ActorClass|FQN] (docu=Documentation)?;

enum ReferenceType:
	FIXED='fixed' |
	OPTIONAL='optional'
	// IMPORTED='imported'
;

// **************************************************************
// concrete message and interface item for state machines 

//AbstractMessage: Message;
AbstractInterfaceItem: InterfaceItem;

// **************************************************************
// general

// the following is a data type rule (accompanied by a value converter) and must not be a terminal rule
// (because then the lexer already would find this in places where it is not expected, e.g. in an Attribute)
MULTIPLICITY returns ecore::EInt : '[' ('*'|INT) ']';

AnnotationTargetType:
	'DataClass' | 
	'ActorClass' | 
	'ActorBehavior' | 
	'ProtocolClass' | 
	'CompoundProtocolClass' | 
	'SubSystemClass' | 
	'LogicalSystem'
;

enum RoomAnnotationTargetEnum:
	DATA_CLASS='DataClass' |
	ACTOR_CLASS='ActorClass' |
	ACTOR_BEHAVIOR='ActorBehavior' |
	PROTOCOL_CLASS='ProtocolClass' |
	COMPOUND_PROTOCOL_CLASS='CompoundProtocolClass' |
	SUBSYSTEM_CLASS='SubSystemClass' |
	LOGICAL_SYSTEM_CLASS='LogicalSystem'
;