Ttcn3Parser.g4 258 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
120

}

@members
{

121
122
123
/**
 * The currently parsed file object, or null if string is parsed
 */
Elemer Lelik's avatar
Elemer Lelik committed
124
125
126
private IFile actualFile = null;

/**
127
128
 * 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
129
 */
130
private int line = 1;
Elemer Lelik's avatar
Elemer Lelik committed
131
132

/**
133
134
 * 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
135
 */
136
private int offset = 0;
Elemer Lelik's avatar
Elemer Lelik committed
137

138
139
140
/**
 * markers of syntactical warnings and errors
 */
141
private List<TITANMarker> warningsAndErrors = new ArrayList<TITANMarker>();
Elemer Lelik's avatar
Elemer Lelik committed
142

Elemer Lelik's avatar
Elemer Lelik committed
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
/**
 * 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 );
178
	warningsAndErrors.add(marker);
Elemer Lelik's avatar
Elemer Lelik committed
179
180
}

Elemer Lelik's avatar
Elemer Lelik committed
181
182
183
184
185
186
187
188
189
190
/**
 * 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 );
}

191
192
193
/**
 * @return markers of syntactical warnings and errors
 */
194
195
public List<TITANMarker> getWarningsAndErrors() {
	return warningsAndErrors;
Elemer Lelik's avatar
Elemer Lelik committed
196
197
}

198
199
200
201
/**
 * markers of unsupported constructs
 */
private List<TITANMarker> unsupportedConstructs = new ArrayList<TITANMarker>();
Elemer Lelik's avatar
Elemer Lelik committed
202

Elemer Lelik's avatar
Elemer Lelik committed
203
204
205
206
207
208
209
210
211
212
213
214
/**
 * 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
215
216
217
	unsupportedConstructs.add(marker);
}

218
219
220
221
/**
 * @return markers of unsupported constructs
 */
public List<TITANMarker> getUnsupportedConstructs() {
Elemer Lelik's avatar
Elemer Lelik committed
222
223
224
	return unsupportedConstructs;
}

Elemer Lelik's avatar
Elemer Lelik committed
225
226
227
228
229
230
231
232
233
234
235
236
/**
 * 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 );
237
	warningsAndErrors.add(marker);
Elemer Lelik's avatar
Elemer Lelik committed
238
239
}

240
public void setActualFile(final IFile file) {
Elemer Lelik's avatar
Elemer Lelik committed
241
242
243
244
245
246
247
248
249
250
251
252
253
	actualFile = file;
}

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

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

private IProject project = null;

254
public void setProject(final IProject project) {
Elemer Lelik's avatar
Elemer Lelik committed
255
256
257
	this.project = project;
}

258
259
260
/**
 * The currently parsed TTCN-3 module 
 */
Elemer Lelik's avatar
Elemer Lelik committed
261
262
263
264
265
266
267
268
private TTCN3Module act_ttcn3_module;

public TTCN3Module getModule() {
	return act_ttcn3_module;
}

public void reset() {
	super.reset();
269
270
	if(warningsAndErrors != null) {
		warningsAndErrors.clear();
271
272
	}
	if(unsupportedConstructs != null) {
Elemer Lelik's avatar
Elemer Lelik committed
273
274
275
276
		unsupportedConstructs.clear();
	}
}

277
278
/**
 * Gets the last visible token of the current rule.
279
 *
280
281
282
 * 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.
283
 *
284
 * This method can be used in any part of the rule.
285
 *
286
 * Please note that visible means that the token is not on the hidden channel!
287
 *
288
289
290
291
292
293
294
295
296
297
298
 * @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;
299
}
300

Elemer Lelik's avatar
Elemer Lelik committed
301
302
303
304
305
/**
 * 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
306
307
308
309
private Location getLocation(final Token aToken) {
	return getLocation(aToken, aToken);
}

Elemer Lelik's avatar
Elemer Lelik committed
310
311
312
313
314
315
316
317
/**
 * 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
318
private Location getLocation(final Token aStartToken, final Token aEndToken) {
319
	final Token endToken = (aEndToken != null) ? aEndToken : aStartToken;
Elemer Lelik's avatar
Elemer Lelik committed
320
321
322
323
324
325
326
327
328
329
330
331
	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) {
332
	final Token endToken = (aEndToken != null) ? aEndToken : aStartToken;
Elemer Lelik's avatar
Elemer Lelik committed
333
	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
334
335
}

Elemer Lelik's avatar
Elemer Lelik committed
336
/**
337
 * Create new location, which modified by the parser offset and line
Elemer Lelik's avatar
Elemer Lelik committed
338
339
340
341
 * @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
342
	return new Location(actualFile, aBaseLocation.getLine(), aBaseLocation.getOffset(), offset + aEndToken.getStopIndex() + 1);
Elemer Lelik's avatar
Elemer Lelik committed
343
}
344
345
346
347
348

/**
 * 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
349
 * at least until that point.
350
351
352
353
354
355
356
 * @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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/**
 * @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
377
378
379
380
381
382
383
384
385
386
387
	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
388
}
Elemer Lelik's avatar
Elemer Lelik committed
389
390
391
392
393
}

/**
 * @author Kristof Szabados
 * @author Arpad Lovassy
394
 * @author Miklos Magyari
Elemer Lelik's avatar
Elemer Lelik committed
395
396
397
398
399
400
401
402
403
404
405
 */

pr_TTCN3File:
	pr_TTCN3Module?
	EOF
;

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

406
pr_ErroneousAttributeSpec returns [ErroneousAttributeSpecification errAttrSpec]
Elemer Lelik's avatar
Elemer Lelik committed
407
@init {
408
	$errAttrSpec = null;
Elemer Lelik's avatar
Elemer Lelik committed
409
410
411
412
413
414
415
416
417
418
	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
419
				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
420
421
422
423
424
425
426
427
428
429
430
			}
		}
		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
431
	$errAttrSpec.setLocation(getLocation( $indicator.start, $z));
Elemer Lelik's avatar
Elemer Lelik committed
432
433
};

434
435
436
437
pr_ErroneousIndicator returns [Indicator_Type indicator]
@init {
	$indicator = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
438
439
440
441
442
443
444
445
446
447
448
(	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
449
				reportUnsupportedConstruct( "Invalid indicator. Valid indicators are: `before', `value' and `after'", $id.start, $id.stop );
Elemer Lelik's avatar
Elemer Lelik committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
			}
		}
);

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

pr_TTCN3Module
@init {
	Token col = null;
	Token endcol = null;
	Token definitionsEnd = null;
	ControlPart controlpart = null;
	MultipleWithAttributes attributes = null;
465
	List<String> languageSpecifications = null;
Elemer Lelik's avatar
Elemer Lelik committed
466
467
}:
(	m = pr_TTCN3ModuleKeyword	{ col = $m.start; }
Elemer Lelik's avatar
Elemer Lelik committed
468
	i = pr_TTCN3ModuleId		{ act_ttcn3_module = new TTCN3Module( $i.identifier, project ); }
469
	( l = pr_LanguageSpec 		{ languageSpecifications = $l.languageSpec; } )?
Elemer Lelik's avatar
Elemer Lelik committed
470
471
472
473
474
475
476
477
	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; } )?
)
{
478
	act_ttcn3_module.setLanguageSpecifications(languageSpecifications);
Elemer Lelik's avatar
Elemer Lelik committed
479
	act_ttcn3_module.setLocation( getLargeLocation( col, endcol ) );
Elemer Lelik's avatar
Elemer Lelik committed
480
	act_ttcn3_module.setDefinitionsLocation( getLocation( $begin.start, definitionsEnd ) );
Elemer Lelik's avatar
Elemer Lelik committed
481
	act_ttcn3_module.setWithAttributes( attributes );
482
	act_ttcn3_module.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
	if ( controlpart != null ) {
		act_ttcn3_module.addControlpart( controlpart );
		controlpart.setAttributeParentPath( act_ttcn3_module.getAttributePath() );
	}
};

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
508
	$value.setLocation(getLocation( $OBJECTIDENTIFIERKEYWORD, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
509
510
511
512
513
514
515
516
517
518
};

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

519
520
521
522
pr_ObjIdComponent returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
523
(	i = pr_Identifier
Elemer Lelik's avatar
Elemer Lelik committed
524
525
		{	if ($i.identifier != null) {
				$objidComponent = new ObjectIdentifierComponent($i.identifier, null);
Elemer Lelik's avatar
Elemer Lelik committed
526
				$objidComponent.setLocation(getLocation( $i.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
527
528
			}
		}
Elemer Lelik's avatar
Elemer Lelik committed
529
530
531
532
533
534
|	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
535
536
537
538
|	o = pr_NumberForm { $objidComponent = $o.objidComponent;}
|	o2 = pr_NameAndNumberForm { $objidComponent = $o2.objidComponent;}
);

539
540
541
542
pr_NumberForm returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
543
544
545
	NUMBER
{
	Value value = new Integer_Value($NUMBER.getText());
Elemer Lelik's avatar
Elemer Lelik committed
546
	value.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
547
	$objidComponent = new ObjectIdentifierComponent(null, value);
Elemer Lelik's avatar
Elemer Lelik committed
548
	$objidComponent.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
549
550
};

551
552
553
554
pr_NameAndNumberForm returns [ObjectIdentifierComponent objidComponent]
@init {
	$objidComponent = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
555
556
557
558
559
560
	i = pr_Identifier
	LPAREN
	NUMBER
	RPAREN
{
	Value value = new Integer_Value($NUMBER.getText());
Elemer Lelik's avatar
Elemer Lelik committed
561
	value.setLocation(getLocation( $NUMBER));
Elemer Lelik's avatar
Elemer Lelik committed
562
	$objidComponent = new ObjectIdentifierComponent($i.identifier, value);
Elemer Lelik's avatar
Elemer Lelik committed
563
	$objidComponent.setLocation(getLocation( $i.start, $RPAREN));
Elemer Lelik's avatar
Elemer Lelik committed
564
565
566
567
};

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

568
569
570
571
pr_TTCN3ModuleId returns[Identifier identifier]
@init {
	$identifier = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
572
573
574
575
576
577
(	i = pr_OwnGlobalModuleId
)
{
	$identifier = $i.identifier;
};

578
579
580
581
pr_OwnGlobalModuleId returns [Identifier identifier]
@init {
	$identifier = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
(	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());
				}
			}
		}
617
|	pr_ImportDef[parent_group]
618
619
|	pr_GroupDef[parent_group] pr_SemiColon?
|	pr_FriendModuleDef[parent_group] pr_SemiColon?
Elemer Lelik's avatar
Elemer Lelik committed
620
621
622
623
624
625
626
);

pr_ModuleDef returns [List<Definition> definitions]
@init {
	$definitions = new ArrayList<Definition>();
	VisibilityModifier modifier = null;
	MultipleWithAttributes attributes = null;
627
	boolean semicolon = false;
Elemer Lelik's avatar
Elemer Lelik committed
628
629
630
631
}:
(	(	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); } }
632
633
634
635
636
637
638
639
640
641
642
643
644
	|	{	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
645
646
647
648
649
650
651
652
653
	|	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; }	)?
654
	(	pr_SemiColon {semicolon = true;}	)?
Elemer Lelik's avatar
Elemer Lelik committed
655
656
657
658
659
660
661
)
{
	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
662
			loc.setOffset( offset + $start.getStartIndex() );
Elemer Lelik's avatar
Elemer Lelik committed
663
664
665
666
		}
		if( attributes != null ) {
			definition.setWithAttributes( attributes );
			Location loc = definition.getLocation();
667
668
669
670
671
			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
672
		}
673
		definition.setCumulativeDefinitionLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
674
675
676
	}

	for ( Definition definition : $definitions ) {
677
		definition.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
678
679
680
681
682
683
684
	}
};

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

685
686
687
688
pr_TypeDef returns[Def_Type def_type]
@init {
	$def_type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
689
690
691
692
(	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
693
694
)
{	if ( $def_type != null ) {
695
		$def_type.setLocation(getLocation( $start, getLastVisibleToken() ));
Elemer Lelik's avatar
Elemer Lelik committed
696
697
	}
};
Elemer Lelik's avatar
Elemer Lelik committed
698
699
700
701
702

pr_TypeDefKeyword:
	TYPE
;

703
704
705
706
pr_StructuredTypeDef returns[Def_Type def_type]
@init {
	$def_type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
707
708
709
710
711
712
713
714
715
716
717
(	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; }
718
|	t12 = pr_ClassTypeDef { $def_type = $t12.def_type; }
Elemer Lelik's avatar
Elemer Lelik committed
719
);
Elemer Lelik's avatar
Elemer Lelik committed
720

721
pr_RecordDef returns[Def_Type def_type]
Elemer Lelik's avatar
Elemer Lelik committed
722
@init {
723
	$def_type = null;
Elemer Lelik's avatar
Elemer Lelik committed
724
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
725
726
727
728
729
730
731
}:
(	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
732
		type.setLocation(getLocation( $col.start, $i.stop));
Elemer Lelik's avatar
Elemer Lelik committed
733
734
735
736
737
738
739
740
		$def_type = new Def_Type($i.identifier, type);
	}
};

pr_RecordKeyword:
	RECORD
;

741
pr_StructDefBody[CompFieldMap compFieldMap] returns[Identifier identifier]
Elemer Lelik's avatar
Elemer Lelik committed
742
@init {
743
	$identifier = null;
Elemer Lelik's avatar
Elemer Lelik committed
744
745
746
}:
(	(	i = pr_Identifier { $identifier = $i.identifier; }
		pr_StructDefFormalParList?
747
	|	ADDRESS  { $identifier = new Identifier(Identifier_type.ID_TTCN, "address", getLocation( $ADDRESS)); }
Elemer Lelik's avatar
Elemer Lelik committed
748
749
750
751
752
753
754
755
756
757
	)
	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
758
	if( $compFieldMap != null ) { $compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop)); }
Elemer Lelik's avatar
Elemer Lelik committed
759
760
761
762
763
764
765
766
767
768
769
};

pr_StructDefFormalParList:
(	col = pr_LParen
	pr_StructDefFormalPar
	(	pr_Comma
		pr_StructDefFormalPar
	)*
	endcol = pr_RParen
)
{
770
	reportUnsupportedConstruct( "Type parameterization is not yet supported", $col.start, $endcol.stop );
Elemer Lelik's avatar
Elemer Lelik committed
771
772
773
774
775
776
};

pr_StructDefFormalPar:
	pr_FormalValuePar
;

777
pr_StructFieldDef returns[CompField compField]
Elemer Lelik's avatar
Elemer Lelik committed
778
@init {
779
	$compField = null;
Elemer Lelik's avatar
Elemer Lelik committed
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
	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
809
				type.setLocation(getLocation( $d.start, $d.stop));
Elemer Lelik's avatar
Elemer Lelik committed
810
811
812
			}
		}
		$compField = new CompField($i.identifier, type, optional, null);
813
		$compField.setLocation(getLocation( $start, getLastVisibleToken()));
814
		$compField.setCommentLocation( getLastCommentLocation( $start ) );
Elemer Lelik's avatar
Elemer Lelik committed
815
816
817
	}
};

818
819
820
821
pr_NestedTypeDef returns[Type type]
@init {
	$type = null;
}:
Elemer Lelik's avatar
Elemer Lelik committed
822
823
824
825
826
827
828
829
830
831
832
(	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; }
);

833
pr_NestedRecordDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
834
@init {
835
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
836
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
837
838
839
840
841
842
843
844
845
846
847
}:
(	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
848
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
849
	$type = new TTCN3_Sequence_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
850
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
851
852
};

853
pr_NestedUnionDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
854
@init {
855
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
856
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
857
858
859
860
861
862
863
864
865
866
867
}:
(	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
868
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
869
	$type = new TTCN3_Choice_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
870
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
871
872
};

873
pr_NestedSetDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
874
@init {
875
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
876
	CompFieldMap compFieldMap = new CompFieldMap();
Elemer Lelik's avatar
Elemer Lelik committed
877
878
879
880
881
882
883
884
885
886
887
}:
(	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
888
	compFieldMap.setLocation(getLocation( $begin.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
889
	$type = new TTCN3_Set_Type(compFieldMap);
Elemer Lelik's avatar
Elemer Lelik committed
890
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
891
892
};

893
pr_NestedRecordOfDef returns[SequenceOf_Type type]
Elemer Lelik's avatar
Elemer Lelik committed
894
@init {
895
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
	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);
	}
913
	$type.setLocation(getLocation( $col.start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
914
915
};

916
pr_NestedSetOfDef returns[SetOf_Type type]
Elemer Lelik's avatar
Elemer Lelik committed
917
@init {
918
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
	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);
	}
936
	$type.setLocation(getLocation( $col.start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
937
938
};

939
pr_NestedEnumDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
940
@init {
941
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
942
943
944
945
946
947
948
949
	EnumerationItems items = null;
}:
(	col = pr_EnumKeyword
	pr_BeginChar
	i = pr_EnumerationList { items = $i.items; }
	endcol = pr_EndChar
)
{
Elemer Lelik's avatar
Elemer Lelik committed
950
	if(items != null) { items.setLocation(getLocation( $col.start, $endcol.stop)); }
Elemer Lelik's avatar
Elemer Lelik committed
951
	$type = new TTCN3_Enumerated_Type(items);
Elemer Lelik's avatar
Elemer Lelik committed
952
	$type.setLocation(getLocation( $col.start, $endcol.stop));
Elemer Lelik's avatar
Elemer Lelik committed
953
954
};

955
pr_NestedFunctionTypeDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
956
@init {
957
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
958
959
960
961
	FormalParameterList parList = null;
	ReturnType_Helper helper = null;
	Type returnType = null;
	boolean returnsTemplate = false;
Elemer Lelik's avatar
Elemer Lelik committed
962
	TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
Elemer Lelik's avatar
Elemer Lelik committed
963
964
965
966
967
968
969
970
971
972
973
974
	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
975
					templateRestriction = helper.templateRestriction;
Elemer Lelik's avatar
Elemer Lelik committed
976
977
978
979
980
981
				}
			}
	)?
)
{
	if(parList == null) { parList = new FormalParameterList(new ArrayList<FormalParameter>()); }
Elemer Lelik's avatar
Elemer Lelik committed
982
	parList.setLocation(getLocation( $start1.start, $end1.stop));
Elemer Lelik's avatar
Elemer Lelik committed
983
	$type = new Function_Type(parList, confighelper.runsonReference, confighelper.runsOnSelf, returnType, returnsTemplate, templateRestriction);
984
	$type.setLocation(getLocation( $start, getLastVisibleToken()));
Elemer Lelik's avatar
Elemer Lelik committed
985
986
};

987
pr_NestedAltstepTypeDef returns[Type type]
Elemer Lelik's avatar
Elemer Lelik committed
988
@init {
989
	$type = null;
Elemer Lelik's avatar
Elemer Lelik committed
990
991
992
993
994
995
996
997
998
999
1000
	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>()); }
For faster browsing, not all history is shown. View entire blame