Ttcn3Parser.g4 279 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
parser grammar Ttcn3Parser;
Elemer Lelik's avatar
Elemer Lelik committed
2
3
4

/*
 ******************************************************************************
Adam Knapp's avatar
Adam Knapp committed
5
 * Copyright (c) 2000-2021 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
6
 * All rights reserved. This program and the accompanying materials
7
 * are made available under the terms of the Eclipse Public License v2.0
Elemer Lelik's avatar
Elemer Lelik committed
8
 * which accompanies this distribution, and is available at
9
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
Elemer Lelik's avatar
Elemer Lelik committed
10
11
12
13
14
15
 ******************************************************************************
*/

/*
NOTE:

earplov's avatar
earplov committed
16
 pr_(Bit|Hex|Octet)String(Match)? rules are for [BHO]STRING(MATCH)? to remove
Elemer Lelik's avatar
Elemer Lelik committed
17
18
19
20
21
22
23
 the beginning "'" and ending "'[BHO]" strings,
 as lexer cannot remove them as it was done in the ANTLR V2 Parser.
 Do NOT use [BHO]STRING(MATCH)? in any rule, use these instead.

 Rule pr_CString is for CSTRING to remove the beginning and ending '"' characters,
 as lexer cannot remove them as it was done in the ANTLR V2 Parser.
 Do NOT use CSTRING in any rule, use this instead.
Elemer Lelik's avatar
Elemer Lelik committed
24

25
--------------------------
26
Precedence of TTCN-3 operators with precedence levels (higher number is higher precedence)
Elemer Lelik's avatar
Elemer Lelik committed
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

15 ( ... )
14 +, - (unary)
13 *, /, mod, rem
12 +, -, &
11 not4b (unary)
10 and4b
 9 xor4b
 8 or4b
 7 <<, >>, <@, @>
 6 <, >, <=, >=
 5 ==, !=
 4 not (unary)
 3 and
 2 xor
 1 or

Simplified* expression rules using precedence climbing method:

E1 : E2 ( OR E2 )*
E2 : E3 ( XOR E3 )*
E3 : E4 ( AND E4 )*
E4 : NOT E4 | E5
E5 : E6 ( ( '==' | '!=' ) E6 )*
E6 : E7 ( ( '<' | '>' | '<=' | '>=' ) E7 )*
E7 : E8 ( ( '<<' | '>>' | '<@' | '@>' ) E8 )*
E8 : E9 ( OR4B E9 )*
E9 : E10 ( XOR4B E10 )*
E10: E11 ( AND4B E11 )*
E11: NOT4B E11 | E12
E12: E13 ( ( '+' | '-' | '&' ) E13 )*
E13: P ( ( '*' | '/' | MOD | REM ) P )*
P : NOT E4 | NOT4B E11 | ( '+' | '-' ) P | '(' E1 ')' | v

*: without java code, but the structure is identical to the used rules, where
  En: rule for the n-th precedence level
  E1: pr_SingleExpression in case of Ttcn3Parser.g4
earplov's avatar
earplov committed
64
  P: last rule with unary operations, pr_UnaryExpression in case of Ttcn3Parser.g4
Elemer Lelik's avatar
Elemer Lelik committed
65
66
  v: atomic expression without any operators, pr_Primary in case of Ttcn3Parser.g4

earplov's avatar
typos    
earplov committed
67
NOTE: unary operators, which are not on the highest priority level, are used twice, because they must be handled at their precedence level,
Elemer Lelik's avatar
Elemer Lelik committed
68
69
70
71
      and also at the last (highest precedence) level, if there is no match to other operators.
      If any of these unary operators was matched in the last rule, control must jump back to the rule of its precedence level ( NOT E4, NOT4B E11 ).
      Example case:
        not4b a & not4b b  <=>  not4b ( a & ( not4b b ) )
72
        1st not4b matches in rule E11, but the 2nd not4b matches in rule P.
Elemer Lelik's avatar
Elemer Lelik committed
73
74
75
*/

options {
Elemer Lelik's avatar
Elemer Lelik committed
76
tokenVocab=Ttcn3Lexer;
Elemer Lelik's avatar
Elemer Lelik committed
77
78
79
80
81
82
83
84
85
86
87
}

@header
{
import java.util.List;
import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;

88
import org.eclipse.titan.common.logging.ErrorReporter;
89
import org.eclipse.titan.common.parsers.CharstringExtractor;
Elemer Lelik's avatar
Elemer Lelik committed
90
import org.eclipse.titan.common.parsers.SyntacticErrorStorage;
Elemer Lelik's avatar
Elemer Lelik committed
91
import org.eclipse.titan.common.parsers.TITANMarker;
Elemer Lelik's avatar
Elemer Lelik committed
92
import org.eclipse.titan.common.parsers.TitanListener;
Elemer Lelik's avatar
Elemer Lelik committed
93
94
95
96
97
98
99

import org.eclipse.titan.designer.AST.*;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.ASN1.values.ASN1_Null_Value;
import org.eclipse.titan.designer.AST.TTCN3.*;
import org.eclipse.titan.designer.AST.TTCN3.attributes.*;
100
import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type;
Elemer Lelik's avatar
Elemer Lelik committed
101
102
103
import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification.Indicator_Type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.*;
Kristof Szabados's avatar
Kristof Szabados committed
104
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter.parameterEvaluationType;
Elemer Lelik's avatar
Elemer Lelik committed
105
106
107
import org.eclipse.titan.designer.AST.TTCN3.statements.*;
import org.eclipse.titan.designer.AST.TTCN3.types.*;
import org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody.OperationModes;
Kristof Szabados's avatar
Kristof Szabados committed
108
import org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter.ParamaterDirection;
Elemer Lelik's avatar
Elemer Lelik committed
109
110
111
112
113
import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.*;
import org.eclipse.titan.designer.AST.TTCN3.templates.*;
import org.eclipse.titan.designer.AST.TTCN3.templates.PatternString.PatternType;
import org.eclipse.titan.designer.AST.TTCN3.values.*;
import org.eclipse.titan.designer.AST.TTCN3.values.expressions.*;
114
import org.eclipse.titan.designer.parsers.ParserUtilities;
Elemer Lelik's avatar
Elemer Lelik committed
115
116
117
118
119

}

@members
{
120
protected boolean isOopEnabled = false;
Elemer Lelik's avatar
Elemer Lelik committed
121

122
public void enableOop(boolean isEnabled) {
123
	isOopEnabled = isEnabled;
124
}
125
126
127
/**
 * The currently parsed file object, or null if string is parsed
 */
Elemer Lelik's avatar
Elemer Lelik committed
128
129
130
private IFile actualFile = null;

/**
131
132
 * The line number of the first parsed character in the file.
 * Line number starts from 1, it is 1 if the whole file is parsed. 
Elemer Lelik's avatar
Elemer Lelik committed
133
 */
134
private int line = 1;
Elemer Lelik's avatar
Elemer Lelik committed
135
136

/**
137
138
 * The index of the first parsed character in the file. This is NOT the column index.
 * Offset number starts from 0, it is 0 if the whole file is parsed. 
Elemer Lelik's avatar
Elemer Lelik committed
139
 */
140
private int offset = 0;
Elemer Lelik's avatar
Elemer Lelik committed
141

142
143
144
/**
 * markers of syntactical warnings and errors
 */
145
private List<TITANMarker> warningsAndErrors = new ArrayList<TITANMarker>();
Elemer Lelik's avatar
Elemer Lelik committed
146

Elemer Lelik's avatar
Elemer Lelik committed
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
/**
 * Creates a marker.
 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
 * @param aMessage marker message
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 * @param aSeverity severity (info/warning/error)
 * @param aPriority priority (low/normal/high)
 * @return new marker
 */
public TITANMarker createMarker( final String aMessage, final Token aStartToken, final Token aEndToken, final int aSeverity, final int aPriority ) {
	TITANMarker marker = new TITANMarker(
		aMessage,
		(aStartToken != null) ? line - 1 + aStartToken.getLine() : -1,
		(aStartToken != null) ? offset + aStartToken.getStartIndex() : -1,
		(aEndToken != null) ? offset + aEndToken.getStopIndex() + 1 : -1,
		aSeverity, aPriority );
	return marker;
}

/**
 * Adds a warning marker.
 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
 * @param aMessage marker message
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 */
public void reportWarning( final String aMessage, final Token aStartToken, final Token aEndToken ) {
	TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL );
182
	warningsAndErrors.add(marker);
Elemer Lelik's avatar
Elemer Lelik committed
183
184
}

Elemer Lelik's avatar
Elemer Lelik committed
185
186
187
188
189
190
191
192
193
194
/**
 * Adds a warning marker, where the start and end token is the same.
 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
 * @param aMessage marker message
 * @param aToken the start and end token
 */
public void reportWarning( final String aMessage, final Token aToken ) {
	reportWarning( aMessage, aToken, aToken );
}

195
196
197
/**
 * @return markers of syntactical warnings and errors
 */
198
199
public List<TITANMarker> getWarningsAndErrors() {
	return warningsAndErrors;
Elemer Lelik's avatar
Elemer Lelik committed
200
201
}

202
203
204
205
/**
 * markers of unsupported constructs
 */
private List<TITANMarker> unsupportedConstructs = new ArrayList<TITANMarker>();
Elemer Lelik's avatar
Elemer Lelik committed
206

Elemer Lelik's avatar
Elemer Lelik committed
207
208
209
210
211
212
213
214
215
216
217
218
/**
 * Adds a marker for configurable unsupported constructs.
 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
 * @param aMessage marker message
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 */
public void reportUnsupportedConstruct( final String aMessage, final Token aStartToken, final Token aEndToken ) {
	TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL );
Elemer Lelik's avatar
Elemer Lelik committed
219
220
221
	unsupportedConstructs.add(marker);
}

222
223
224
225
/**
 * @return markers of unsupported constructs
 */
public List<TITANMarker> getUnsupportedConstructs() {
Elemer Lelik's avatar
Elemer Lelik committed
226
227
228
	return unsupportedConstructs;
}

Elemer Lelik's avatar
Elemer Lelik committed
229
230
231
232
233
234
235
236
237
238
239
240
/**
 * Adds an error marker for unsupported constructs.
 * Locations of input tokens are not moved by offset and line yet, this function does this conversion.
 * @param aMessage marker message
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 */
public void reportError( final String aMessage, final Token aStartToken, final Token aEndToken ) {
	TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL );
241
	warningsAndErrors.add(marker);
Elemer Lelik's avatar
Elemer Lelik committed
242
243
}

244
public void setActualFile(final IFile file) {
Elemer Lelik's avatar
Elemer Lelik committed
245
246
247
248
249
250
251
252
253
254
255
256
257
	actualFile = file;
}

public void setLine(final int line) {
	this.line = line;
}

public void setOffset(final int offset) {
	this.offset = offset;
}

private IProject project = null;

258
public void setProject(final IProject project) {
Elemer Lelik's avatar
Elemer Lelik committed
259
260
261
	this.project = project;
}

262
263
264
/**
 * The currently parsed TTCN-3 module 
 */
Elemer Lelik's avatar
Elemer Lelik committed
265
266
267
268
269
270
271
272
private TTCN3Module act_ttcn3_module;

public TTCN3Module getModule() {
	return act_ttcn3_module;
}

public void reset() {
	super.reset();
273
274
	if(warningsAndErrors != null) {
		warningsAndErrors.clear();
275
276
	}
	if(unsupportedConstructs != null) {
Elemer Lelik's avatar
Elemer Lelik committed
277
278
279
280
		unsupportedConstructs.clear();
	}
}

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
327
328
329
330
331
332
333
334
/**
 * Gets the documentation comment for the current context, or null if no doc comment found
 * The comment should end in the previous line
 *
 * Both single line and multiline doc comments are supported
 */
public String getDocCommentText() {
	BufferedTokenStream stream = (BufferedTokenStream)_input;
	Token start = _ctx.getStart();
	List<Token> t = null;
	if (start != null) {
		int pos = start.getTokenIndex();

		try {
			t = stream.getHiddenTokensToLeft(pos, 1);
		} catch (Exception e) {
			return null;
		}

		if (t == null) {
			return null;
		}
		int len = t.size();
		if (len < 2) {
			return null;
		}
		Token prev = t.get(len - 1);
		if (prev.getType() != ONENEWLINE) {
			return null;
		}
		prev = t.get(len - 2);
		if (prev.getType() == BLOCK_DOCUMENT) {
			return prev.getText();
		}
		StringBuilder builder = new StringBuilder();
		boolean stop = false;
		for (int i = len - 2; !stop && i >= 0; i--) {
			prev = t.get(i);
			switch (prev.getType()) {
			case ONENEWLINE:
			case WS:
				continue;
			case LINE_DOCUMENT:
				builder.insert(0, prev.getText() + "\n");
				break;
			default:
				stop = true;
			}
		}
		return builder.length() > 0 ? builder.toString() : null;
	}
	return null;
}

335
336
/**
 * Gets the last visible token of the current rule.
337
 *
338
339
340
 * This is used inside the rule, because \$stop is filled only
 * in the finally block in the generated java code, so it does
 * NOT have the correct value in @after and @finally actions.
341
 *
342
 * This method can be used in any part of the rule.
343
 *
344
 * Please note that visible means that the token is not on the hidden channel!
345
 *
346
347
348
349
350
351
352
353
354
355
356
 * @return last consumed token
 */
public Token getLastVisibleToken() {
	int index = _input.index() - 1;
	Token temp = _input.get( index );
	while (index >= 0 && temp.getChannel() == temp.HIDDEN_CHANNEL) {
		index--;
		temp = _input.get( index );
	}

	return temp;
357
}
358

Elemer Lelik's avatar
Elemer Lelik committed
359
360
361
362
363
/**
 * Create new location, which modified by the parser offset and line,
 * where the start and end token is the same
 * @param aToken the start and end token
 */
Elemer Lelik's avatar
Elemer Lelik committed
364
365
366
367
private Location getLocation(final Token aToken) {
	return getLocation(aToken, aToken);
}

Elemer Lelik's avatar
Elemer Lelik committed
368
369
370
371
372
373
374
375
/**
 * Create new location, which modified by the parser offset and line
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 */
Elemer Lelik's avatar
Elemer Lelik committed
376
private Location getLocation(final Token aStartToken, final Token aEndToken) {
377
	final Token endToken = (aEndToken != null) ? aEndToken : aStartToken;
Elemer Lelik's avatar
Elemer Lelik committed
378
379
380
381
382
383
384
385
386
387
388
389
	return new Location(actualFile, line - 1 + aStartToken.getLine(), offset + aStartToken.getStartIndex(), offset + endToken.getStopIndex() + 1);
}

/**
 * Create new large location, which modified by the parser offset and line
 * @param aStartToken the 1st token, its line and start position will be used for the location
 *                  NOTE: start position is the column index of the tokens 1st character.
 *                        Column index starts with 0.
 * @param aEndToken the last token, its end position will be used for the location.
 *                  NOTE: end position is the column index after the token's last character.
 */
private LargeLocation getLargeLocation(final Token aStartToken, final Token aEndToken) {
390
	final Token endToken = (aEndToken != null) ? aEndToken : aStartToken;
Elemer Lelik's avatar
Elemer Lelik committed
391
	return new LargeLocation(actualFile, line - 1 + aStartToken.getLine(), line - 1 + endToken.getLine(), offset + aStartToken.getStartIndex(), offset + endToken.getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
392
393
}

Elemer Lelik's avatar
Elemer Lelik committed
394
/**
395
 * Create new location, which modified by the parser offset and line
Elemer Lelik's avatar
Elemer Lelik committed
396
397
398
399
 * @param aBaseLocation location of the start token, location is already modified by offset and line
 * @param aEndToken end token, NOT null, not modified by offset and line yet
 */
private Location getLocation(final Location aBaseLocation, final Token aEndToken) {
Elemer Lelik's avatar
Elemer Lelik committed
400
	return new Location(actualFile, aBaseLocation.getLine(), aBaseLocation.getOffset(), offset + aEndToken.getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
401
}
402
403
404
405
406

/**
 * Gets the location of the comments before a token.
 * Last comment location cannot be handled in the lexer, because lexer and parser are not always synchronized,
 * lexer reads more, than the parser, because  when the parser reaches a point, the tokens must be already tokenized
407
 * at least until that point.
408
409
410
411
412
413
414
 * @param aToken the token, this will NOT be printed
 * @return location, which contains all of the comments before the given token
 */
private Location getLastCommentLocation( final Token aToken ) {
	return ParserUtilities.getCommentsBefore( aToken, this, actualFile );
}

Elemer Lelik's avatar
Elemer Lelik committed
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/**
 * @return list of errors, collected by the TitanListener
 *         or null if there is no TitanListener (this case should NOT happen)
 */
public List<SyntacticErrorStorage> getErrors() {
	TitanListener titanListener = null;
	for ( ParseTreeListener listener : this.getParseListeners() ) {
		// there should be only 1 listener, which is a TitanListener, but let's make it safe
		if ( listener instanceof TitanListener ) {
			titanListener = (TitanListener)listener;
			return titanListener.getErrorsStored();
		}
	}
	return null;
}

/**
 * @return true if error list is empty
 */
public boolean isErrorListEmpty() {
Elemer Lelik's avatar
Elemer Lelik committed
435
436
437
438
439
440
441
442
443
444
445
	for ( ParseTreeListener listener : this.getParseListeners() ) {
		if(listener instanceof TitanListener && !((TitanListener) listener).getErrorsStored().isEmpty()) {
			return false;
		}
	}
	for(ANTLRErrorListener listener : getErrorListeners()) {
		if(listener instanceof TitanListener && !((TitanListener) listener).getErrorsStored().isEmpty()) {
			return false;
		}
	}
	return true;
Elemer Lelik's avatar
Elemer Lelik committed
446
}
Elemer Lelik's avatar
Elemer Lelik committed
447
448
449
450
451
}

/**
 * @author Kristof Szabados
 * @author Arpad Lovassy
452
 * @author Miklos Magyari
Elemer Lelik's avatar
Elemer Lelik committed
453
454
455
456
457
458
459
460
461
462
463
 */

pr_TTCN3File:
	pr_TTCN3Module?
	EOF
;

//-----------------------------------------------------
// erroneous attribute specification syntax for negative testing
//-----------------------------------------------------

464
pr_ErroneousAttributeSpec returns [ErroneousAttributeSpecification errAttrSpec]
Elemer Lelik's avatar
Elemer Lelik committed
465
@init {
466
	$errAttrSpec = null;
Elemer Lelik's avatar
Elemer Lelik committed
467
468
469
470
471
472
473
474
475
476
	boolean isRaw = false;
	boolean hasAllKeyword = false;
}:
(	indicator = pr_ErroneousIndicator
	(	pr_LParen
		raw_id = pr_Identifier
//TODO: create token
		{	if ( $raw_id.identifier != null && "raw".equals( $raw_id.identifier.getName() ) ) {
				isRaw = true;
			} else {
Elemer Lelik's avatar
Elemer Lelik committed
477
				reportUnsupportedConstruct( "Invalid keyword, only the optional `raw' keyword can be used here.", $raw_id.start, $raw_id.stop );
Elemer Lelik's avatar
Elemer Lelik committed
478
479
480
481
482
483
484
485
486
487
488
			}
		}
		pr_RParen
	)?
	pr_AssignmentChar
	t = pr_TemplateInstance
	( pr_AllKeyword { hasAllKeyword = true; } )?
	z = EOF // end of string
)
{
	$errAttrSpec = new ErroneousAttributeSpecification($indicator.indicator, isRaw, $t.templateInstance, hasAllKeyword);
Elemer Lelik's avatar
Elemer Lelik committed
489
	$errAttrSpec.setLocation(getLocation( $indicator.start, $z));
Elemer Lelik's avatar
Elemer Lelik committed
490
491
};

492
493
494
495
pr_ErroneousIndicator returns [Indicator_Type indicator]
@init {
	$indicator = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
496
497
498
499
500
501
502
503
504
505
506
(	pr_ValueKeyword { $indicator = Indicator_Type.Value_Indicator; }
|	id = pr_Identifier
		{
//TODO: create token
			if ( $id.identifier !=null && "before".equals( $id.identifier.getName() ) ) {
				$indicator = Indicator_Type.Before_Indicator;
//TODO: create token
			} else if ( $id.identifier!=null && "after".equals( $id.identifier.getName() ) ) {
				$indicator = Indicator_Type.After_Indicator;
			} else {
				$indicator = Indicator_Type.Invalid_Indicator;
Elemer Lelik's avatar
Elemer Lelik committed
507
				reportUnsupportedConstruct( "Invalid indicator. Valid indicators are: `before', `value' and `after'", $id.start, $id.stop );
Elemer Lelik's avatar
Elemer Lelik committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
			}
		}
);

//-----------------------------------------------------
//                    TTCN Module  1.6.0
//-----------------------------------------------------

pr_TTCN3Module
@init {
	Token col = null;
	Token endcol = null;
	Token definitionsEnd = null;
	ControlPart controlpart = null;
	MultipleWithAttributes attributes = null;
523
	List<String> languageSpecifications = null;
524
525

	String docComment = getDocCommentText();
Elemer Lelik's avatar
Elemer Lelik committed
526
527
}:
(	m = pr_TTCN3ModuleKeyword	{ col = $m.start; }
Elemer Lelik's avatar
Elemer Lelik committed
528
	i = pr_TTCN3ModuleId		{ act_ttcn3_module = new TTCN3Module( $i.identifier, project ); }
529
	( l = pr_LanguageSpec 		{ languageSpecifications = $l.languageSpec; } )?
Elemer Lelik's avatar
Elemer Lelik committed
530
531
532
533
534
535
536
537
	begin = pr_BeginChar
	pr_ModuleDefinitionsList[null]
	( c = pr_ModuleControlPart	{ definitionsEnd = $c.stop; controlpart = $c.controlpart; } )?
	enda = pr_EndChar			{ endcol = $enda.stop; if ( definitionsEnd == null ) { definitionsEnd = $enda.stop; } }
	( a = pr_WithStatement		{ endcol = $a.stop; attributes = $a.attributes; } )?
	( endb = pr_SemiColon		{ endcol = $endb.stop; } )?
)
{
538
	act_ttcn3_module.setLanguageSpecifications(languageSpecifications);
Elemer Lelik's avatar
Elemer Lelik committed
539
	act_ttcn3_module.setLocation( getLargeLocation( col, endcol ) );
Elemer Lelik's avatar
Elemer Lelik committed
540
	act_ttcn3_module.setDefinitionsLocation( getLocation( $begin.start, definitionsEnd ) );
Elemer Lelik's avatar
Elemer Lelik committed
541
	act_ttcn3_module.setWithAttributes( attributes );
542
	act_ttcn3_module.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
543
544
545
546
	if ( controlpart != null ) {
		act_ttcn3_module.addControlpart( controlpart );
		controlpart.setAttributeParentPath( act_ttcn3_module.getAttributePath() );
	}
547
548
549
	// if (docComment != null) {
	// 	// act_ttcn3_module.setDocumentationComment(docComment);
	// }
Elemer Lelik's avatar
Elemer Lelik committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
};

pr_TTCN3ModuleKeyword returns[String stringValue]:
	MODULE
{
	$stringValue = $MODULE.getText();
};

// ASN.1 with TTCN-3 BNF Extension Start

pr_ObjectIdentifierKeyword:
	OBJECTIDENTIFIERKEYWORD
;

pr_ObjectIdentifierValue returns [ObjectIdentifier_Value value]:
	OBJECTIDENTIFIERKEYWORD
	pr_BeginChar
	v = pr_ObjIdComponentList
	endcol = pr_EndChar
{
	$value = $v.value;
Elemer Lelik's avatar
Elemer Lelik committed
571
	$value.setLocation(getLocation( $OBJECTIDENTIFIERKEYWORD, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
572
573
574
575
576
577
578
579
580
581
};

pr_ObjIdComponentList returns [ObjectIdentifier_Value value]
@init {
	$value = new ObjectIdentifier_Value();
}:
(	o = pr_ObjIdComponent	{if($o.objidComponent != null) { $value.addObjectIdComponent($o.objidComponent); } }
)+
;

582
583
584
585
pr_ObjIdComponent returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
586
(	i = pr_Identifier
Elemer Lelik's avatar
Elemer Lelik committed
587
588
		{	if ($i.identifier != null) {
				$objidComponent = new ObjectIdentifierComponent($i.identifier, null);
Elemer Lelik's avatar
Elemer Lelik committed
589
				$objidComponent.setLocation(getLocation( $i.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
590
591
			}
		}
Elemer Lelik's avatar
Elemer Lelik committed
592
593
594
595
596
597
|	v = pr_ReferencedValue
		{	if ($v.value != null) {
				$objidComponent = new ObjectIdentifierComponent($v.value);
				$objidComponent.setLocation(getLocation( $v.start, $v.stop));
			}
		}
Elemer Lelik's avatar
Elemer Lelik committed
598
599
600
601
|	o = pr_NumberForm { $objidComponent = $o.objidComponent;}
|	o2 = pr_NameAndNumberForm { $objidComponent = $o2.objidComponent;}
);

602
603
604
605
pr_NumberForm returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
606
607
608
	NUMBER
{
	Value value = new Integer_Value($NUMBER.getText());
Elemer Lelik's avatar
Elemer Lelik committed
609
	value.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
610
	$objidComponent = new ObjectIdentifierComponent(null, value);
Elemer Lelik's avatar
Elemer Lelik committed
611
	$objidComponent.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
612
613
};

614
615
616
617
pr_NameAndNumberForm returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
618
619
620
621
622
623
	i = pr_Identifier
	LPAREN
	NUMBER
	RPAREN
{
	Value value = new Integer_Value($NUMBER.getText());
Elemer Lelik's avatar
Elemer Lelik committed
624
	value.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
625
	$objidComponent = new ObjectIdentifierComponent($i.identifier, value);
Elemer Lelik's avatar
Elemer Lelik committed
626
	$objidComponent.setLocation(getLocation( $i.start, $RPAREN));
Elemer Lelik's avatar
Elemer Lelik committed
627
628
629
630
};

// ASN.1 with TTCN-3 BNF Extension End

631
632
633
634
pr_TTCN3ModuleId returns[Identifier identifier]
@init {
	$identifier = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
635
636
637
638
639
640
(	i = pr_OwnGlobalModuleId
)
{
	$identifier = $i.identifier;
};

641
642
643
644
pr_OwnGlobalModuleId returns [Identifier identifier]
@init {
	$identifier = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
(	id = pr_Identifier
	(	DOT
		pr_ObjectIdentifierValue
	)?
)
{
	$identifier = $id.identifier;
};


//------------------------------------------------------
//          Module Definitions Part      1.6.1  136
//------------------------------------------------------

pr_ModuleDefinitionsList [Group parent_group]:
(	(	col = pr_ModuleDefinition[parent_group]
	)*
);

pr_ModuleDefinition [Group parent_group]:
(	d = pr_ModuleDef
		{
			List<Definition> defs = $d.definitions;
			act_ttcn3_module.addDefinitions(defs);
			if(parent_group == null) {
				for(Definition def : defs) {
					def.setAttributeParentPath(act_ttcn3_module.getAttributePath());
				}
			} else {
				parent_group.addDefinitions(defs);
				for(Definition def : defs) {
					def.setAttributeParentPath(parent_group.getAttributePath());
				}
			}
		}
680
|	pr_ImportDef[parent_group]
681
682
|	pr_GroupDef[parent_group] pr_SemiColon?
|	pr_FriendModuleDef[parent_group] pr_SemiColon?
Elemer Lelik's avatar
Elemer Lelik committed
683
684
685
686
687
688
689
);

pr_ModuleDef returns [List<Definition> definitions]
@init {
	$definitions = new ArrayList<Definition>();
	VisibilityModifier modifier = null;
	MultipleWithAttributes attributes = null;
690
	boolean semicolon = false;
Elemer Lelik's avatar
Elemer Lelik committed
691
692
693
694
}:
(	(	m = pr_Visibility { modifier = $m.modifier; }	)?
	(	d1 = pr_TypeDef { if($d1.def_type != null) { $definitions.add($d1.def_type); } }
	|	d2 = pr_ConstDef { if($d2.array != null) { $definitions.addAll($d2.array); } }
695
696
697
698
699
700
701
702
703
704
705
706
707
	|	{	boolean isTemplateVar = false;	}
		(	pr_VarKeyword	{	isTemplateVar = true;	}	)?
		d3 = pr_TemplateDef
		{
			final Def_Template templateDef = $d3.def_template;
			if ( isTemplateVar ) {
				final String templateName = templateDef != null ? " `" + templateDef.getIdentifier() + "'" : "";
				reportError( "Code generation for global template variable" + templateName + " is not supported", $start, $d3.stop );
			}
			else if ( $d3.def_template != null ) {
				$definitions.add( $d3.def_template );
			}
		}
Elemer Lelik's avatar
Elemer Lelik committed
708
709
710
711
712
713
714
715
716
	|	d4 = pr_FunctionDef { if($d4.def_func != null) { $definitions.add($d4.def_func); } }
	|	d5 = pr_SignatureDef { if($d5.def_type != null) { $definitions.add($d5.def_type); } }
	|	d6 = pr_TestcaseDef { if($d6.def_testcase != null) { $definitions.add($d6.def_testcase); } }
	|	d7 = pr_AltstepDef { if($d7.def_altstep != null) { $definitions.add($d7.def_altstep); } }
	|	d8 = pr_ExtFunctionDef { if($d8.def_extfunction != null) { $definitions.add($d8.def_extfunction); } }
	|	d9 = pr_ExtConstDef { $definitions.addAll($d9.definitions); }
	|	d10 = pr_ModuleParDef { if($d10.parameters != null) { $definitions.addAll($d10.parameters); } }
	)
	(	a = pr_WithStatement { attributes = $a.attributes; }	)?
717
	(	pr_SemiColon {semicolon = true;}	)?
Elemer Lelik's avatar
Elemer Lelik committed
718
719
720
721
722
723
724
)
{
	for ( int i = 0; i < $definitions.size(); i++ ) {
		Definition definition = $definitions.get(i);
		if ( modifier != null ) {
			definition.setVisibility( modifier );
			Location loc = definition.getLocation();
Elemer Lelik's avatar
Elemer Lelik committed
725
			loc.setOffset( offset + $start.getStartIndex() );
Elemer Lelik's avatar
Elemer Lelik committed
726
727
728
729
		}
		if( attributes != null ) {
			definition.setWithAttributes( attributes );
			Location loc = definition.getLocation();
730
731
732
733
734
			loc.setEndOffset(offset + getLastVisibleToken().getStopIndex() + 1);
		}
		if(semicolon) {
			Location loc = definition.getLocation();
			loc.setEndOffset(offset + getLastVisibleToken().getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
735
		}
736
		definition.setCumulativeDefinitionLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
737
738
739
	}

	for ( Definition definition : $definitions ) {
740
		definition.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
741
742
743
744
745
746
747
	}
};

//------------------------------------------------------
//   Typdef Definitions  1.6.1.1  136
// -----------------------------------------------------

748
749
750
751
pr_TypeDef returns[Def_Type def_type]
@init {
	$def_type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
752
753
754
755
(	pr_TypeDefKeyword
	(	d1 = pr_StructuredTypeDef { $def_type = $d1.def_type; }
	|	d2 = pr_SubTypeDef { $def_type = $d2.def_type; }
	)
Elemer Lelik's avatar
Elemer Lelik committed
756
757
)
{	if ( $def_type != null ) {
758
		$def_type.setLocation(getLocation( $start, getLastVisibleToken() ));
Elemer Lelik's avatar
Elemer Lelik committed
759
760
	}
};
Elemer Lelik's avatar
Elemer Lelik committed
761
762
763
764
765

pr_TypeDefKeyword:
	TYPE
;

766
767
768
769
pr_StructuredTypeDef returns[Def_Type def_type]
@init {
	$def_type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
770
771
772
773
774
775
776
777
778
779
780
(	t1 = pr_RecordOfDef { $def_type = $t1.def_type; }
|	t2 = pr_RecordDef { $def_type = $t2.def_type; }
|	t3 = pr_UnionDef { $def_type = $t3.def_type; }
|	t4 = pr_SetOfDef { $def_type = $t4.def_type; }
|	t5 = pr_SetDef { $def_type = $t5.def_type; }
|	t6 = pr_EnumDef { $def_type = $t6.def_type; }
|	t7 = pr_PortDef { $def_type = $t7.def_type; }
|	t8 = pr_ComponentDef { $def_type = $t8.def_type; }
|	t9 = pr_FunctionTypeDef { $def_type = $t9.def_type; }
|	t10 = pr_AltstepTypeDef { $def_type = $t10.def_type; }
|	t11 = pr_TestcaseTypeDef { $def_type = $t11.def_type; }
781
|	t12 = pr_ClassTypeDef { $def_type = $t12.def_type; }
Elemer Lelik's avatar
Elemer Lelik committed
782
);
Elemer Lelik's avatar
Elemer Lelik committed
783

784
pr_RecordDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
785
@init {
786
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
787
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
788
789
790
791
792
793
794
}:
(	col = pr_RecordKeyword
	i = pr_StructDefBody[compFieldMap]
)
{
	if($i.identifier != null) {
		TTCN3_Sequence_Type type = new TTCN3_Sequence_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
795
		type.setLocation(getLocation( $col.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
796
797
798
799
800
801
802
803
		$def_type = new Def_Type($i.identifier, type);
	}
};

pr_RecordKeyword:
	RECORD
;

804
pr_StructDefBody[CompFieldMap compFieldMap] returns[Identifier identifier]
Elemer Lelik's avatar
Elemer Lelik committed
805
@init {
806
	$identifier = null;
Elemer Lelik's avatar
Elemer Lelik committed
807
808
809
}:
(	(	i = pr_Identifier { $identifier = $i.identifier; }
		pr_StructDefFormalParList?
810
	|	ADDRESS  { $identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
811
812
813
814
815
816
817
818
819
820
	)
	begin = pr_BeginChar
	(	c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		(	pr_Comma
			c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		)*
	)?
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
821
	if( $compFieldMap != null ) { $compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop)); }
Elemer Lelik's avatar
Elemer Lelik committed
822
823
824
825
826
827
828
829
830
831
832
};

pr_StructDefFormalParList:
(	col = pr_LParen
	pr_StructDefFormalPar
	(	pr_Comma
		pr_StructDefFormalPar
	)*
	endcol = pr_RParen
)
{
833
	reportUnsupportedConstruct( "Type parameterization is not yet supported", $col.start, $endcol.stop );
Elemer Lelik's avatar
Elemer Lelik committed
834
835
836
837
838
839
};

pr_StructDefFormalPar:
	pr_FormalValuePar
;

840
pr_StructFieldDef returns[CompField compField]
Elemer Lelik's avatar
Elemer Lelik committed
841
@init {
842
	$compField = null;
Elemer Lelik's avatar
Elemer Lelik committed
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
	Type type = null;
	ArrayDimensions dimensions = null;
	List<ParsedSubType> parsedSubTypes = null;
	boolean optional = false;
}:
(	(	t = pr_Type { type = $t.type; }
	|	t2 = pr_NestedTypeDef { type = $t2.type; }
	)
	i = pr_Identifier
	( d = pr_ArrayDef { dimensions = $d.dimensions; } )?
	( p = pr_SubTypeSpec { parsedSubTypes = $p.parsedSubTypes; } )?
	( pr_OptionalKeyword { optional = true; } )?
)
{
	if($i.identifier != null && type != null) {
		if(parsedSubTypes != null) {
			IType t = type;
			boolean seof = true;
			while(seof) {
				seof = t instanceof AbstractOfType;
				if (seof) {
					t = ((AbstractOfType) t).getOfType();
				}
			}
			t.setParsedRestrictions(parsedSubTypes);
		}
		if( dimensions != null ) {
			for ( int i = dimensions.size() - 1; i >= 0; i-- ) {
				type = new Array_Type(type, dimensions.get(i), true);
Elemer Lelik's avatar
Elemer Lelik committed
872
				type.setLocation(getLocation( $d.start, $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
873
874
875
			}
		}
		$compField = new CompField($i.identifier, type, optional, null);
876
		$compField.setLocation(getLocation( $start, getLastVisibleToken()));
877
		$compField.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
878
879
880
	}
};

881
882
883
884
pr_NestedTypeDef returns[Type type]
@init {
	$type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
885
886
887
888
889
890
891
892
893
894
895
(	t1 = pr_NestedRecordDef			{ $type = $t1.type; }
|	t2 = pr_NestedUnionDef			{ $type = $t2.type; }
|	t3 = pr_NestedSetDef			{ $type = $t3.type; }
|	t4 = pr_NestedRecordOfDef		{ $type = $t4.type; }
|	t5 = pr_NestedSetOfDef			{ $type = $t5.type; }
|	t6 = pr_NestedEnumDef			{ $type = $t6.type; }
|	t7 = pr_NestedFunctionTypeDef	{ $type = $t7.type; }
|	t8 = pr_NestedAltstepTypeDef	{ $type = $t8.type; }
|	t9 = pr_NestedTestcaseTypeDef	{ $type = $t9.type; }
);

896
pr_NestedRecordDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
897
@init {
898
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
899
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
900
901
902
903
904
905
906
907
908
909
910
}:
(	col = pr_RecordKeyword
	begin = pr_BeginChar
	(	c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		(	pr_Comma
			c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		)*
	)?
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
911
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
912
	$type = new TTCN3_Sequence_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
913
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
914
915
};

916
pr_NestedUnionDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
917
@init {
918
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
919
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
920
921
922
923
924
925
926
927
928
929
930
}:
(	col = pr_UnionKeyword
	begin = pr_BeginChar
	(	c = pr_UnionFieldDef { compFieldMap.addComp($c.compField); }
		(	pr_Comma
			c = pr_UnionFieldDef { compFieldMap.addComp($c.compField); }
		)*
	)
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
931
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
932
	$type = new TTCN3_Choice_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
933
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
934
935
};

936
pr_NestedSetDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
937
@init {
938
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
939
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
940
941
942
943
944
945
946
947
948
949
950
}:
(	col = pr_SetKeyword
	begin = pr_BeginChar
	(	c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		(	pr_Comma
			c = pr_StructFieldDef { compFieldMap.addComp($c.compField); }
		)*
	)?
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
951
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
952
	$type = new TTCN3_Set_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
953
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
954
955
};

956
pr_NestedRecordOfDef returns[SequenceOf_Type type]
Elemer Lelik's avatar
Elemer Lelik committed
957
@init {
958
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
	LengthRestriction restriction = null;
	Type ofType = null;
}:
(	col = pr_RecordKeyword
	( r = pr_StringLength { restriction = $r.restriction; } )?
	pr_OfKeyword
	(	t1 = pr_Type { ofType = $t1.type; }
	|	t2 = pr_NestedTypeDef { ofType = $t2.type; }
	)
)
{
	$type = new SequenceOf_Type(ofType);
	if(restriction != null) {
		List<ParsedSubType> parsedSubTypes = new ArrayList<ParsedSubType>();
		parsedSubTypes.add(new Length_ParsedSubType(restriction));
		$type.setParsedRestrictions(parsedSubTypes);
	}
976
	$type.setLocation(getLocation( $col.start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
977
978
};

979
pr_NestedSetOfDef returns[SetOf_Type type]
Elemer Lelik's avatar
Elemer Lelik committed
980
@init {
981
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
	LengthRestriction restriction = null;
	Type ofType = null;
}:
(	col = pr_SetKeyword
	( r = pr_StringLength { restriction = $r.restriction; } )?
	pr_OfKeyword
	(	t1 = pr_Type { ofType = $t1.type; }
	|	t2 = pr_NestedTypeDef { ofType = $t2.type; }
	)
)
{
	$type = new SetOf_Type(ofType);
	if(restriction != null) {
		List<ParsedSubType> parsedSubTypes = new ArrayList<ParsedSubType>();
		parsedSubTypes.add(new Length_ParsedSubType(restriction));
		$type.setParsedRestrictions(parsedSubTypes);
	}
999
	$type.setLocation(getLocation( $col.start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
1000
1001
};

1002
pr_NestedEnumDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
1003
@init {
1004
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1005
1006
1007
1008
1009
1010
1011
1012
	EnumerationItems items = null;
}:
(	col = pr_EnumKeyword
	pr_BeginChar
	i = pr_EnumerationList { items = $i.items; }
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1013
	if(items != null) { items.setLocation(getLocation( $col.start, $endcol.stop)); }
Elemer Lelik's avatar
Elemer Lelik committed
1014
	$type = new TTCN3_Enumerated_Type(items);
Elemer Lelik's avatar
Elemer Lelik committed
1015
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1016
1017
};

1018
pr_NestedFunctionTypeDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
1019
@init {
1020
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1021
1022
1023
1024
	FormalParameterList parList = null;
	ReturnType_Helper helper = null;
	Type returnType = null;
	boolean returnsTemplate = false;
Elemer Lelik's avatar
Elemer Lelik committed
1025
	TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
Elemer Lelik's avatar
Elemer Lelik committed
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
	Configuration_Helper confighelper = new Configuration_Helper();
}:
(	col = pr_FunctionKeyword
	start1 = pr_LParen
	( p = pr_FunctionFormalParList { parList = $p.parList; } )?
	end1 = pr_RParen
	(	end2 = pr_RunsOnReferenceOrSelf[confighelper]	)?
	(	h = pr_ReturnType
			{	helper = $h.helper;
				if( helper != null ) {
					returnType = helper.type;
					returnsTemplate = helper.returnsTemplate;
Elemer Lelik's avatar
Elemer Lelik committed
1038
					templateRestriction = helper.templateRestriction;
Elemer Lelik's avatar
Elemer Lelik committed
1039
1040
1041
1042
1043
1044
				}
			}
	)?
)
{
	if(parList == null) { parList = new FormalParameterList(new ArrayList<FormalParameter>()); }
Elemer Lelik's avatar
Elemer Lelik committed
1045
	parList.setLocation(getLocation( $start1.start, $end1.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1046
	$type = new Function_Type(parList, confighelper.runsonReference, confighelper.runsOnSelf, returnType, returnsTemplate, templateRestriction);
1047
	$type.setLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
1048
1049
};

1050
pr_NestedAltstepTypeDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
1051
@init {
1052
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
	FormalParameterList parList = null;
	Configuration_Helper confighelper =  new Configuration_Helper();
}:
(	col = pr_AltstepKeyword
	start1 = pr_LParen
	( p = pr_FunctionFormalParList { parList = $p.parList; } )?
	end1 = pr_RParen
	(	end2 = pr_RunsOnReferenceOrSelf[confighelper]	)?
)
{
	if(parList == null) { parList = new FormalParameterList(new ArrayList<FormalParameter>()); }
Elemer Lelik's avatar
Elemer Lelik committed
1064
	parList.setLocation(getLocation( $start1.start, $end1.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1065
	$type = new Altstep_Type(parList, confighelper.runsonReference, confighelper.runsOnSelf);
1066
	$type.setLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
1067
1068
};

1069
pr_NestedTestcaseTypeDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
1070
@init {
1071
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
	FormalParameterList parList = null;
	Configuration_Helper helper = null;
	Reference runsonReference = null;
	Reference systemReference = null;
}:
	col = pr_TestcaseKeyword
	start1 = pr_LParen
	( p = pr_TestcaseFormalParList { parList = $p.parList; } )?
	end = pr_RParen
	h = pr_ConfigSpec
		{	helper = $h.helper;
			if(helper != null) {
				runsonReference = helper.runsonReference;
				systemReference = helper.systemReference;
			}
		}
{
	if(parList == null) { parList = new TestcaseFormalParameterList(new ArrayList<FormalParameter>()); }
Elemer Lelik's avatar
Elemer Lelik committed
1090
	parList.setLocation(getLocation( $start1.start, $end.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1091
	$type = new Testcase_Type(parList, runsonReference, systemReference);
Elemer Lelik's avatar
Elemer Lelik committed
1092
	$type.setLocation(getLocation( $col.start, $h.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1093
1094
1095
1096
1097
1098
};

pr_OptionalKeyword:
	OPTIONAL
;

1099
pr_UnionDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1100
@init {
1101
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1102
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
1103
1104
1105
1106
1107
1108
1109
}:
(	col = pr_UnionKeyword
	i = pr_UnionDefBody[compFieldMap]
)
{
	if($i.identifier != null) {
		TTCN3_Choice_Type type = new TTCN3_Choice_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
1110
		type.setLocation(getLocation( $col.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1111
1112
1113
1114
1115
1116
1117
1118
		$def_type = new Def_Type($i.identifier, type);
	}
};

pr_UnionKeyword:
	UNION
;

1119
pr_UnionDefBody[CompFieldMap compFieldMap] returns[Identifier identifier]
Elemer Lelik's avatar
Elemer Lelik committed
1120
@init {
1121
	$identifier = null;
Elemer Lelik's avatar
Elemer Lelik committed
1122
1123
1124
1125
	CompField compField = null;
}:
(	(	i = pr_Identifier { $identifier = $i.identifier; }
		pr_StructDefFormalParList?
1126
	|	ADDRESS { $identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
1127
1128
	)
	(	begin = pr_BeginChar
1129
1130
1131
1132
1133
1134
		(	{	reportError( "Union must have at least one field", $begin.start, $begin.stop );	}
		|	c = pr_UnionFieldDef { compFieldMap.addComp($c.compField); }
			(	pr_Comma
				c = pr_UnionFieldDef { compFieldMap.addComp($c.compField); }
			)*
		)
Elemer Lelik's avatar
Elemer Lelik committed
1135
1136
1137
1138
		endcol = pr_EndChar
	)
)
{
Elemer Lelik's avatar
Elemer Lelik committed
1139
	if( $compFieldMap != null ) { $compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop )); }
Elemer Lelik's avatar
Elemer Lelik committed
1140
1141
};

1142
pr_UnionFieldDef returns[CompField compField]
Elemer Lelik's avatar
Elemer Lelik committed
1143
@init {
1144
	$compField = null;
Elemer Lelik's avatar
Elemer Lelik committed
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
	Type type = null;
	ArrayDimensions dimensions = null;
	List<ParsedSubType> parsedSubTypes = null;
}:
(	(	t1 = pr_Type { type = $t1.type; }
	|	t2 = pr_NestedTypeDef { type = $t2.type; }
	)
	i = pr_Identifier
	( d = pr_ArrayDef { dimensions = $d.dimensions; } )?
	( p = pr_SubTypeSpec { parsedSubTypes = $p.parsedSubTypes; } )?
)
{
	if(type != null && parsedSubTypes != null) {
		IType t = type;
		boolean seof = true;
		while(seof) {
			seof = t instanceof AbstractOfType;
			if (seof) {
				t = ((AbstractOfType) t).getOfType();
			}
		}
		t.setParsedRestrictions(parsedSubTypes);
	}
	if (dimensions != null) {
		for (int i = dimensions.size() - 1; i >= 0; i--) {
			type = new Array_Type(type, dimensions.get(i), true);
Elemer Lelik's avatar
Elemer Lelik committed
1171
			type.setLocation(getLocation( $d.start, $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1172
1173
1174
		}
	}
	$compField = new CompField($i.identifier, type, false, null);
1175
	$compField.setLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
1176
1177
};

1178
pr_SetDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1179
@init {
1180
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1181
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
1182
1183
1184
1185
1186
1187
1188
}:
(	col = pr_SetKeyword
	i = pr_StructDefBody[compFieldMap]
)
{
	if($i.identifier != null) {
		TTCN3_Set_Type type = new TTCN3_Set_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
1189
		type.setLocation(getLocation( $col.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1190
1191
1192
1193
1194
1195
1196
1197
		$def_type = new Def_Type($i.identifier, type);
	}
};

pr_SetKeyword:
	SET
;

1198
pr_RecordOfDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1199
@init {
1200
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
	Type_Identifier_Helper helper = null;
	LengthRestriction restriction = null;
}:
(	col = pr_RecordKeyword
	( r = pr_StringLength { restriction = $r.restriction; } )?
	pr_OfKeyword
	h = pr_StructOfDefBody { helper = $h.helper; }
)
{
	if(helper.identifier != null && helper.type != null) {
		SequenceOf_Type type = new SequenceOf_Type(helper.type);
		if(restriction != null) {
			List<ParsedSubType> parsedSubTypes = new ArrayList<ParsedSubType>();
			parsedSubTypes.add(new Length_ParsedSubType(restriction));
			type.setParsedRestrictions(parsedSubTypes);
		}
Elemer Lelik's avatar
Elemer Lelik committed
1217
		type.setLocation(getLocation( $col.start, $h.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1218
		$def_type = new Def_Type(helper.identifier, type);
1219
		$def_type.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
	}
};

pr_OfKeyword:
	OF
;

pr_StructOfDefBody returns[Type_Identifier_Helper helper]
@init {
	$helper = new Type_Identifier_Helper();
	Type type = null;
	Identifier identifier = null;
	List<ParsedSubType> parsedSubTypes = null;
}:
(	(	t1 = pr_Type { type = $t1.type; }
	|	t2 = pr_NestedTypeDef { type = $t2.type; }
	)
1237

Elemer Lelik's avatar
Elemer Lelik committed
1238
	(	i = pr_Identifier { identifier = $i.identifier; }
1239
	|	ADDRESS { identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
1240
	)
1241

Elemer Lelik's avatar
Elemer Lelik committed
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
	( p = pr_SubTypeSpec { parsedSubTypes = $p.parsedSubTypes; } )?
)
{
	if(type != null && parsedSubTypes != null) {
		IType t = type;
		boolean seof = true;
		while(seof) {
			seof = t instanceof AbstractOfType;
			if (seof) {
				t = ((AbstractOfType) t).getOfType();
			}
		}
		t.setParsedRestrictions(parsedSubTypes);
	}
	$helper.type = type;
	$helper.identifier = identifier;
};

1260
pr_SetOfDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1261
@init {
1262
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
	Type_Identifier_Helper helper = null;
	LengthRestriction restriction = null;
}:
(	col = pr_SetKeyword
	( r = pr_StringLength { restriction = $r.restriction; } )?
	pr_OfKeyword
	h = pr_StructOfDefBody { helper = $h.helper; }
)
{
	if(helper.identifier != null && helper.type != null) {
		SetOf_Type type = new SetOf_Type(helper.type);
		if(restriction != null) {
			List<ParsedSubType> parsedSubTypes = new ArrayList<ParsedSubType>();
			parsedSubTypes.add(new Length_ParsedSubType(restriction));
			type.setParsedRestrictions(parsedSubTypes);
		}
Elemer Lelik's avatar
Elemer Lelik committed
1279
		type.setLocation(getLocation( $col.start, $h.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1280
1281
1282
1283
		$def_type = new Def_Type(helper.identifier, type);
	}
};

1284
pr_EnumDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1285
@init {
1286
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1287
1288
1289
1290
1291
	Identifier identifier = null;
	EnumerationItems items = null;
}:
(	col = pr_EnumKeyword
	(	id = pr_Identifier { identifier = $id.identifier; }
1292
	|	ADDRESS { identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
1293
1294
1295
1296
1297
1298
1299
1300
	)
	pr_BeginChar
	e = pr_EnumerationList { items = $e.items; }
	endcol = pr_EndChar
)
{
	if(identifier != null && items != null) {
		Type type = new TTCN3_Enumerated_Type(items);
Elemer Lelik's avatar
Elemer Lelik committed
1301
		type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
		$def_type = new Def_Type(identifier, type);
	}
};

pr_EnumKeyword:
	ENUMERATED
;

pr_EnumerationList returns[EnumerationItems items]
@init {
	$items = new EnumerationItems();
}:
(	e = pr_Enumeration { $items.addEnumItem($e.enumItem); }
	(	pr_Comma
		e = pr_Enumeration { $items.addEnumItem($e.enumItem); }
	)*
);

1320
pr_Enumeration returns[EnumItem enumItem]
Elemer Lelik's avatar
Elemer Lelik committed
1321
@init {
1322
	$enumItem = null;
1323
	Value value = null;
Elemer Lelik's avatar
Elemer Lelik committed
1324
1325
1326
}:
(	i = pr_Identifier
	(	pr_LParen
1327
		v = pr_SingleExpression
Elemer Lelik's avatar
Elemer Lelik committed
1328
			{
1329
				value = $v.value;
Elemer Lelik's avatar
Elemer Lelik committed
1330
1331
1332
1333
1334
1335
			}
		pr_RParen
	)?
)
{
	$enumItem = new EnumItem($i.identifier, value);
1336
	$enumItem.setLocation(getLocation( $i.start, getLastVisibleToken()));
1337
	$enumItem.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
1338
1339
};

1340
pr_SubTypeDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1341
@init {
1342
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1343
1344
1345
1346
1347
1348
	Identifier identifier = null;
	ArrayDimensions dimensions = null;
	List<ParsedSubType> parsedSubTypes = null;
}:
(	t = pr_Type
	(	i = pr_Identifier { identifier = $i.identifier; }
1349
	|	ADDRESS	{ identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
1350
1351
1352
1353
1354
1355
1356
1357
1358
	)
	( a = pr_ArrayDef { dimensions = $a.dimensions; } )?
	( s = pr_SubTypeSpec { parsedSubTypes = $s.parsedSubTypes; } )?
)
{
	if($t.type != null && parsedSubTypes != null) {
		$t.type.setParsedRestrictions(parsedSubTypes);
	}
	if (dimensions != null) {
Kristof Szabados's avatar
Kristof Szabados committed
1359
		final Location location = getLocation( $a.start, $a.stop);
Elemer Lelik's avatar
Elemer Lelik committed
1360
1361
		for (int i = dimensions.size() - 1; i >= 0; i--) {
			$t.type = new Array_Type($t.type, dimensions.get(i), true);
Kristof Szabados's avatar
Kristof Szabados committed
1362
			$t.type.setLocation(location);
Elemer Lelik's avatar
Elemer Lelik committed
1363
1364
1365
1366
1367
1368
1369
		}
	}
	if(identifier != null && $t.type != null) {
		$def_type = new Def_Type(identifier, $t.type);
	}
};

1370
1371
1372
1373
pr_SubTypeSpec returns[List<ParsedSubType> parsedSubTypes]
@init {
	$parsedSubTypes = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
(	a = pr_AllowedValues { $parsedSubTypes = $a.parsedSubTypes; }
	( r = pr_StringLength
		{	if($r.restriction != null && $parsedSubTypes != null) {
				$parsedSubTypes.add(new Length_ParsedSubType($r.restriction));
			}
		}
	)?
|	r = pr_StringLength
		{	if($r.restriction != null) {
				$parsedSubTypes = new ArrayList<ParsedSubType>();
				$parsedSubTypes.add(new Length_ParsedSubType($r.restriction));
			}
		}
);

pr_AllowedValues returns[List<ParsedSubType> parsedSubTypes]
@init {
	$parsedSubTypes = new ArrayList<ParsedSubType>();
}:
(	pr_LParen
	(	p = pr_ValueOrRange	{ if( $p.parsedSubType != null ) { $parsedSubTypes.add( $p.parsedSubType ); }}
		(	pr_Comma
			p = pr_ValueOrRange	{ if( $p.parsedSubType != null ) { $parsedSubTypes.add( $p.parsedSubType ); }}
		)*
1398
	|	pr_CharStringMatch	// an unsupported construct, but must not be reported
Elemer Lelik's avatar
Elemer Lelik committed
1399
1400
1401
1402
1403
	)
	pr_RParen
);

// TODO: Rename for TemplateOrValue and rework its content !
1404
1405
1406
1407
pr_ValueOrRange returns[ParsedSubType parsedSubType]
@init {
	$parsedSubType = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
1408
1409
1410
1411
(	p = pr_RangeDef { $parsedSubType = $p.parsedSubType; }
|	v = pr_Expression { if($v.value != null) { $parsedSubType = new Single_ParsedSubType($v.value); } }
);

1412
pr_RangeDef returns[ParsedSubType parsedSubType]
Elemer Lelik's avatar
Elemer Lelik committed
1413
@init {
1414
	$parsedSubType = null;
Elemer Lelik's avatar
Elemer Lelik committed
1415
1416
	boolean minExclusive = false;
	boolean maxExclusive = false;
Elemer Lelik's avatar
Elemer Lelik committed
1417
}:
Elemer Lelik's avatar
Elemer Lelik committed
1418
(	( pr_ExcludeBound { minExclusive = true; } )?
Elemer Lelik's avatar
Elemer Lelik committed
1419
1420
	min = pr_LowerBound
	RANGEOP
Elemer Lelik's avatar
Elemer Lelik committed
1421
	( pr_ExcludeBound { maxExclusive = true; } )?
Elemer Lelik's avatar
Elemer Lelik committed
1422
1423
1424
1425
	max = pr_UpperBound
)
{
	if ( $min.value != null && $max.value != null ) {
Elemer Lelik's avatar
Elemer Lelik committed
1426
		$parsedSubType = new Range_ParsedSubType( $min.value, minExclusive, $max.value, maxExclusive );
Elemer Lelik's avatar
Elemer Lelik committed
1427
1428
1429
1430
1431
1432
1433
	}
};

pr_ExcludeBound:
	EXCLAMATIONMARK
;

1434
pr_StringLength returns[LengthRestriction restriction]
Elemer Lelik's avatar
Elemer Lelik committed
1435
@init {
1436
	$restriction = null;
Elemer Lelik's avatar
Elemer Lelik committed
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
	boolean range = false;
}:
(	col = pr_LengthKeyword
	pr_LParen
	lower = pr_SingleExpression
	(	RANGEOP	{ range = true; }
		upper = pr_UpperBound
	)?
	endcol = pr_RParen
)
{
	if( !range ) {
		$restriction = new SingleLenghtRestriction( $lower.value );
	} else {
		$restriction = new RangeLenghtRestriction( $lower.value, $upper.value );
	}
Elemer Lelik's avatar
Elemer Lelik committed
1453
	$restriction.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1454
1455
1456
1457
1458
1459
};

pr_LengthKeyword:
	LENGTH
;

1460
1461
1462
1463
pr_PortType returns[Reference reference]
@init {
	$reference = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
(	(	r = pr_GlobalModuleId { $reference = $r.reference; }
		pr_Dot
	)?
	id = pr_Identifier
)
{
	if($reference == null) {
		$reference = new Reference(null);
	}
	FieldSubReference subReference = new FieldSubReference($id.identifier);
Elemer Lelik's avatar
Elemer Lelik committed
1474
	subReference.setLocation(getLocation( $id.start, $id.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1475
	$reference.addSubReference(subReference);
Elemer Lelik's avatar
Elemer Lelik committed
1476
	$reference.setLocation(getLocation( $start, $id.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1477
1478
};

1479
pr_PortDef returns[ Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
1480
@init {
1481
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
1482
1483
1484
1485
1486
1487
}:
(	col = pr_PortKeyword
	i = pr_Identifier
	b = pr_PortDefAttribs
)
{
ekrisza's avatar
ekrisza committed
1488
1489
1490
	if($i.identifier != null && $b.portType != null && $b.body != null) {
		//Type type = new Port_Type($b.body);
		$b.portType.setLocation(getLocation( $col.start, $b.stop));
Elemer Lelik's avatar
Elemer Lelik committed
1491

ekrisza's avatar
ekrisza committed
1492
		$def_type = new Def_Type($i.identifier, $b.portType);
1493
		$def_type.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
1494
1495
1496
1497
1498
1499
1500
	}
};

pr_PortKeyword:
	PORT
;

1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
pr_PortMap returns [ List<Reference> outerPortTypeRefs ]
@init {
	$outerPortTypeRefs = new ArrayList<Reference>();
}:
	pr_MapKeyword
	pr_ToKeyword
	outerPortTypeRef = pr_PortType
		{	if ( $outerPortTypeRef.reference != null ) {
				$outerPortTypeRefs.add( $outerPortTypeRef.reference );
			}
		}
	(	pr_Comma
		outerPortTypeRef = pr_PortType
			{	if ( $outerPortTypeRef.reference != null ) {
					$outerPortTypeRefs.add( $outerPortTypeRef.reference );
				}
			}
	)*
;

ekrisza's avatar
ekrisza committed
1521
pr_PortDefAttribs returns[Port_Type portType, PortTypeBody body]
1522
1523
1524
@init {
	$body = null;
}:
ekrisza's avatar
ekrisza committed
1525
(	b = pr_MessageAttribs { $portType = $b.portType; $body = $b.body; }
ekrisza's avatar
ekrisza committed
1526
1527
|	b2 = pr_ProcedureAttribs { $portType = $b2.portType; $body = $b2.body; }
|	b3 = pr_MixedAttribs { $portType = $b3.portType; $body = $b3.body; }
Elemer Lelik's avatar
Elemer Lelik committed
1528
1529
1530
)
{
	if($body != null) {