Ttcn3BaseLexer.g4 19.4 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
lexer grammar Ttcn3BaseLexer;
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
 ******************************************************************************
*/

/*
 * author Arpad Lovassy
15
 * author Miklos Magyari
Elemer Lelik's avatar
Elemer Lelik committed
16
17
18
 */

@header {
19
import java.util.List;
Elemer Lelik's avatar
Elemer Lelik committed
20
21
import java.util.ArrayList;
import java.util.HashMap;
Elemer Lelik's avatar
Elemer Lelik committed
22
23
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Elemer Lelik's avatar
Elemer Lelik committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.texteditor.MarkerUtilities;

import org.eclipse.titan.designer.core.LoadBalancingUtilities;
import org.eclipse.titan.designer.consoles.TITANDebugConsole;
import org.eclipse.titan.designer.parsers.ParserMarkerSupport;
import org.eclipse.titan.common.parsers.Interval;
import org.eclipse.titan.common.parsers.IntervalDetector;
import org.eclipse.titan.common.parsers.Interval.interval_type;
import org.eclipse.titan.common.parsers.TITANMarker;
import org.eclipse.titan.designer.AST.Location;
}

@members {
41
  protected boolean isOopEnabled = false;
Elemer Lelik's avatar
Elemer Lelik committed
42
43
44
  protected boolean isTTCNPP = false;
  private int tokenCounter = 0;

45
  public void enableOop(boolean isEnabled) {
46
	isOopEnabled = isEnabled;
47
48
  }

Elemer Lelik's avatar
Elemer Lelik committed
49
50
51
52
53
  public void setTTCNPP() {
  	isTTCNPP = true;
  }

  private IFile actualFile = null;
54

Elemer Lelik's avatar
Elemer Lelik committed
55
56
57
  public void setActualFile(IFile file) {
    actualFile = file;
  }
58

Elemer Lelik's avatar
Elemer Lelik committed
59
  private int actualLine = 1;
60

Elemer Lelik's avatar
Elemer Lelik committed
61
62
63
  public void setActualLine(int line) {
    actualLine = line;
  }
Elemer Lelik's avatar
Elemer Lelik committed
64
65
66

  /**
   * Creates and places a task marker on the provided location.
67
   *
Elemer Lelik's avatar
Elemer Lelik committed
68
69
70
71
72
73
74
75
76
   * @param taskMarker the data of the marker needed for this operation
   * */
  public void createTaskMarker(TITANMarker taskMarker){
    if (actualFile == null) {
      return;
    }

    ParserMarkerSupport.createTaskMarker(actualFile, taskMarker);
  }
77

Elemer Lelik's avatar
Elemer Lelik committed
78
79
  /**
   * Creates and places a task marker on the provided location.
80
   *
Elemer Lelik's avatar
Elemer Lelik committed
81
82
83
84
85
86
87
88
89
90
   * @param taskMarker the data of the marker needed for this operation
   */
  public void createWarningMarker(TITANMarker warningMarker) {
    if (actualFile == null) {
      return;
    }

    ParserMarkerSupport.createWarningMarker(actualFile, warningMarker);
  }

Arpad Lovassy's avatar
Arpad Lovassy committed
91
  IntervalDetector intervalDetector = new IntervalDetector();
Elemer Lelik's avatar
Elemer Lelik committed
92
93
94
95
96
97
98
99
100

  public Interval getRootInterval() {
    return intervalDetector.getRootInterval();
  }

  public void initRootInterval(int length) {
    intervalDetector.initRootInterval(length);
  }

Elemer Lelik's avatar
Elemer Lelik committed
101
102
103
104
105
106
  /**
   * true, if todo/fixme markers can be placed by the lexer,
   *       typically it is set if full parsing is done
   * false otherwise
   */
  private boolean mCommentTodo = false;
107

Elemer Lelik's avatar
Elemer Lelik committed
108
109
110
  public void setCommentTodo( boolean aCommentTodo ) {
    mCommentTodo = aCommentTodo;
  }
Elemer Lelik's avatar
Elemer Lelik committed
111
112
113
114
115

  //TODO: we will need it later for the performance
  /** Used to preload the class, also loading the TTCN-3 lexer. */
  public static void preLoad() {
  }
116

Elemer Lelik's avatar
Elemer Lelik committed
117
118
	/** pattern for matching todo/fixme in a comment line */
	final static Pattern PATTERN_TODO_FIXME = Pattern.compile("((TODO|FIXME).*?)\\s*(?=(TODO|FIXME|$))");
119

Elemer Lelik's avatar
Elemer Lelik committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	/**
	 * Extracts todo and fixme information from comment text
	 * @param aCommentText the full text of the comment token
	 * @param aMultiLine type of comment. true: / * ... * /, false: / / ... \n
	 */
	private void detectTasks( final String aCommentText, final boolean aMultiLine ) {
		if ( !mCommentTodo ) {
			return;
		}
		// remove comment boundary characters
		String commentText;
		if ( aMultiLine ) {
			commentText = aCommentText.substring( 2, aCommentText.length() - 2 );
		} else {
			commentText = aCommentText.substring( 2 );
		}
136

Elemer Lelik's avatar
Elemer Lelik committed
137
138
139
140
141
142
143
144
145
		String commentLines[] = commentText.split("\\r?\\n");
		for( int i = 0; i < commentLines.length; i++ ) {
			String commentLine = commentLines[ i ];
			Matcher m = PATTERN_TODO_FIXME.matcher(commentLine);
			while ( m.find() ) {
				String text = m.group( 1 );
				if ( text != null ) {
					createTaskMarker( new TITANMarker( text, actualLine + i + _tokenStartLine, -1, -1,
							IMarker.SEVERITY_INFO, text.startsWith("TODO") ? IMarker.PRIORITY_NORMAL : IMarker.PRIORITY_HIGH ) );
Elemer Lelik's avatar
Elemer Lelik committed
146
147
148
				}
			}
		}
Elemer Lelik's avatar
Elemer Lelik committed
149
	}
150
151
152
153
154
155
156
157
158
159
160

	/** binstr is valid bitstring */
	boolean valid_bit = true;
	/** binstr is valid octetstring */
	boolean valid_oct = true;
	/** binstr is not a valid octetstr but a valid hexstr */
	boolean half_oct = false;
	/** binstr contains matching symbol */
	boolean contains_match = false;
	/** binstr contains whitespace characters */
	boolean contains_ws = false;
161
162
	/** error is reported for invalid characters */
	boolean invalid_char_reported = false;
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
	/** token start index */
	int startIndex = 0;

	private List<TITANMarker> warningsAndErrors = new ArrayList<TITANMarker>();

	public List<TITANMarker> getWarningsAndErrors() {
		return warningsAndErrors;
	}

	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) ? aStartToken.getLine() : -1,
			(aStartToken != null) ? aStartToken.getStartIndex() : -1,
			(aEndToken != null) ? aEndToken.getStopIndex() + 1 : -1,
			aSeverity, aPriority );
		return marker;
	}

	public TITANMarker createMarker( final String aMessage, final int line, final int start, final int stop, final int aSeverity, final int aPriority ) {
		TITANMarker marker = new TITANMarker(
			aMessage,
			line, start, stop,
			aSeverity, aPriority );
		return marker;
	}

	private void reportWarning( final String aMessage, final Token aStartToken, final Token aEndToken ) {
		TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL );
		warningsAndErrors.add(marker);
	}

	private void reportWarning( final String aMessage, final int line, final int start, final int stop ) {
		TITANMarker marker = createMarker( aMessage, line, start, stop, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL );
		warningsAndErrors.add(marker);
	}

	private void reportError( final String aMessage, final Token aStartToken, final Token aEndToken ) {
		TITANMarker marker = createMarker( aMessage, aStartToken, aEndToken, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL );
		warningsAndErrors.add(marker);
	}

	private void reportError( final String aMessage, final int line, final int start, final int stop ) {
		TITANMarker marker = createMarker( aMessage, line, start, stop, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL );
		warningsAndErrors.add(marker);
	}

	private void warning( final String msg ) {
		final int line = getLine();
		final int stopIndex = getCharIndex();
		reportWarning( msg, line, startIndex, stopIndex );
	}
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	private void error( final String msg ) {
		final int line = getLine();
		final int stopIndex = getCharIndex();
		reportError( msg, line, startIndex, stopIndex );
	}

	/**
	 * Report error for invalid character and shows marker only for one character
	 * @param msg error message
	 */
	private void errorChar( final String msg ) {
		final int line = getLine();
		final int stopIndex = getCharIndex();
		reportError( msg, line, stopIndex - 1, stopIndex );
	}

Elemer Lelik's avatar
Elemer Lelik committed
232
233
234
235
236
}

/*------------------------------------------- Keywords -------------------------------------------*/

tokens {
237
238
239
240
241
  ACTION,                     ACTIVATE,                   ADDRESS,
  ALIVE,                      ALL,                        ALT,
  ALTSTEP,                    AND,                        AND4B,
  ANY,                        ANYTYPE,                    ANY2UNISTR,
  APPLY,
242

243
  BITSTRING,                  BOOLEAN,                    BREAK,
Elemer Lelik's avatar
Elemer Lelik committed
244

245
246
  CALL,                       CASE,                       CATCH,
  CHARKEYWORD,                CHARSTRING,                 CHECK,
247
248
  CHECKSTATE,                 CLASS,
  CLEAR,                      COMPLEMENTKEYWORD,
249
250
251
  COMPONENT,                  CONJUNCT,                   CONNECT,
  CONST,                      CONTINUE,                   CONTROL,
  CREATE,
Elemer Lelik's avatar
Elemer Lelik committed
252

253
254
255
  DEACTIVATE,                 DEFAULT,                    DECMATCH,
  DECVALUE,                   DECVALUE_UNICHAR,           DEREFERS,
  DISCONNECT,                 DISPLAY,                    DO,
256
257
  DONE,

258
259
260
261
  ELSE,                       ENCODE,                     ENCVALUE,
  ENCVALUE_UNICHAR,           ENUMERATED,                 ERROR,
  EXCEPT,                     EXCEPTION,                  EXECUTE,
  EXTENDS,                    EXTENSION,                  EXTERNAL,
Elemer Lelik's avatar
Elemer Lelik committed
262

263
264
  FAIL,                       FALSE,                      FINALLY,
  FLOAT,
265
  FOR,                        FRIEND,                     FROM,
Elemer Lelik's avatar
Elemer Lelik committed
266
267
  FUNCTION,

ekrisza's avatar
ekrisza committed
268
269
  GETCALL,                    GETREF,                     GETREPLY,
  GETVERDICT,                 GOTO,                       GROUP,
Elemer Lelik's avatar
Elemer Lelik committed
270

271
  HALT,                       HEXSTRING,                  HOSTID,
Elemer Lelik's avatar
Elemer Lelik committed
272

273
274
275
276
  IF,                         IFPRESENT,                  IMPLIES,                  
  IMPORT,                     IN,                         INCONC,
  INFINITY,                   INOUT,                      INTEGER,
  INTERLEAVE,                 ISTEMPLATEKIND,
Elemer Lelik's avatar
Elemer Lelik committed
277

278
  KILL,                       KILLED,
Elemer Lelik's avatar
Elemer Lelik committed
279

280
  LABEL,                      LANGUAGE,                   LENGTH,
Elemer Lelik's avatar
Elemer Lelik committed
281
282
  LOG,

283
284
285
  MAP,                        MATCH,                      MESSAGE,
  MIXED,                      MOD,                        MODIFIES,
  MODULE,                     MODULEPAR,                  MTC,
Elemer Lelik's avatar
Elemer Lelik committed
286

287
  NOBLOCK,                    NONE,
288
289
290
  NOT,                        NOT4B,                      NOW,
  NOWAIT,                     NOT_A_NUMBER,               NULL1,
  NULL2,
Elemer Lelik's avatar
Elemer Lelik committed
291

292
293
  OBJECTIDENTIFIERKEYWORD,    OBJECTKEYWORD,              OCTETSTRING,                
  OF,
294
295
  OMIT,                       ON,                         OPTIONAL,
  OR,                         OR4B,                       OUT,
Elemer Lelik's avatar
Elemer Lelik committed
296
297
  OVERRIDEKEYWORD,

298
299
300
  PARAM,                      PASS,                       PATTERNKEYWORD,
  PERMUTATION,                PORT,                       PUBLIC,
  PRESENT,                    PRIVATE,                    PROCEDURE,
301
  PROTECTED,
Elemer Lelik's avatar
Elemer Lelik committed
302

303
304
305
306
307
  RAISE,                      READ,                       REALTIME,
  RECEIVE,                    RECORD,                     RECURSIVE,
  REFERS,                     REM,                        REPEAT,
  REPLY,                      RETURN,                     RUNNING,
  RUNS,
Elemer Lelik's avatar
Elemer Lelik committed
308

309
310
  SELECT,                     SELF,                       SEND,
  SENDER,                     SET,                        SETVERDICT,
ekrisza's avatar
ekrisza committed
311
  SETSTATE,                   SIGNATURE,                  START,
312
313
  STOP,                       SUBSET,                     SUPER,
  SUPERSET,					  SYSTEM,
Elemer Lelik's avatar
Elemer Lelik committed
314

315
316
  TEMPLATE,                   TESTCASE,                   THIS,
  TIMEOUT,
317
318
  TIMER,                      TIMESTAMP,                  TO,
  TRIGGER,                    TRUE,                       TYPE,
Elemer Lelik's avatar
Elemer Lelik committed
319

320
  UNION,                      UNIVERSAL,                  UNMAP,
Elemer Lelik's avatar
Elemer Lelik committed
321

322
323
  VALUE,                      VALUEOF,                    VAR,
  VARIANT,                    VERDICTTYPE,
Elemer Lelik's avatar
Elemer Lelik committed
324

325
  WHILE,                      WITH,
Elemer Lelik's avatar
Elemer Lelik committed
326

327
  XOR,                        XOR4B,
Elemer Lelik's avatar
Elemer Lelik committed
328
329

  /*------------------------------ Predefined function identifiers --------------------------------*/
330
331

  BIT2HEX,                    BIT2INT,                    BIT2OCT,
332
  BIT2STR,                    BSON2JSON,
333

334
  CBOR2JSON,                  CHAR2INT,                   CHAR2OCT,
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

  DECODE_BASE64,              DECOMP,

  ENCODE_BASE64,              ENUM2INT,

  FLOAT2INT,                  FLOAT2STR,

  GET_STRINGENCODING,

  HEX2BIT,                    HEX2INT,                    HEX2OCT,
  HEX2STR,

  INT2BIT,                    INT2CHAR,                   INT2ENUM,
  INT2FLOAT,                  INT2HEX,                    INT2OCT,
  INT2STR,                    INT2UNICHAR,                ISBOUND,
  ISCHOSEN,                   ISPRESENT,                  ISVALUE,

352
353
  JSON2BSON,                  JSON2CBOR,

354
355
356
357
358
359
360
361
  LENGTHOF,                   LOG2STR,

  OCT2BIT,                    OCT2CHAR,                   OCT2HEX,
  OCT2INT,                    OCT2STR,                    OCT2UNICHAR,

  REGEXP,                     REMOVE_BOM,                 RND,
  REPLACE,

Gergo Ujhelyi's avatar
Gergo Ujhelyi committed
362
363
364
  SETENCODE,                  SIZEOF,                     STR2BIT,
  STR2FLOAT,                  STR2HEX,                    STR2INT,
  STR2OCT,                    STRING2TTCN,                SUBSTR,
365
366
367
368
369

  TESTCASENAME,               TTCN2STRING,

  UNICHAR2CHAR,               UNICHAR2INT,                UNICHAR2OCT,

370
  /* general macro, used for code completion, see TTCN3KeywordLessLexer */
371
  MACRO,
372

373
374
375
376
377
378
379
380
381
  /*------------------------------ Binary string tokens --------------------------------*/

  BSTRING,
  BSTRINGMATCH,
  //HSTRING,	// already defined in rule HSTRING
  HSTRINGMATCH,
  OSTRING,
  OSTRINGMATCH,
  BHOSTRING_WRONG
382

Elemer Lelik's avatar
Elemer Lelik committed
383
384
}

Kristof Szabados's avatar
Kristof Szabados committed
385
WS:	[ \t\r\n\f]+	-> channel(HIDDEN);
Elemer Lelik's avatar
Elemer Lelik committed
386

387
388
389
390
391
392
393
LINE_COMMENT:	'//' ~[\r\n]*
{
	detectTasks(getText(), false);
} -> channel(HIDDEN);

BLOCK_COMMENT:	'/*' .*? '*/'
{
Elemer Lelik's avatar
Elemer Lelik committed
394
395
	intervalDetector.pushInterval(_tokenStartCharIndex, _tokenStartLine, interval_type.MULTILINE_COMMENT);
	intervalDetector.popInterval(_input.index(), _interp.getLine());
396
397
	detectTasks(getText(), true);
} -> channel(HIDDEN);
Elemer Lelik's avatar
Elemer Lelik committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421

//TODO: check that nothing else preceeds it in current line
PREPROCESSOR_DIRECTIVE:
(   '#'
	(
		{ isTTCNPP }? (
			~('\n'|'\r'|'\\')
			|	{ _input.LA(2)!='\n' && _input.LA(2)!='\r' }? '\\'
			|	( '\\\n' | '\\\r' | '\\\r\n' )
		)*
	|
		{ !isTTCNPP }? ( (' '|'\t')* ('0'..'9')+ (' '|'\t')+ CSTRING ('0'..'9'|' '|'\t')* )
	)
)
{if (!isTTCNPP) {skip();};};

IDENTIFIER:
	[A-Za-z][A-Za-z0-9_]*
;

ASSIGNMENTCHAR:	':=';

PORTREDIRECTSYMBOL:	'->';

422
CLASSCASTING:	'=>'		{ isOopEnabled }? ;
423

Elemer Lelik's avatar
Elemer Lelik committed
424
425
426
427
428
429
430
431
432
CSTRING:
'"'
(	'\\' .
|	'""'
|	~( '\\' | '"' )
)*
'"'
;

433
434
435
436
437
//[uU][+]?[0-9A-Fa-f]{1,8} but the optional + sign is handled with identifiers
UID:
	[uU][+][0-9a-fA-F]+
;

Elemer Lelik's avatar
Elemer Lelik committed
438
439
440
441
fragment BIN: [01];
fragment BINORMATCH: BIN | '?' | '*';
fragment HEX: [0-9A-Fa-f];
fragment HEXORMATCH: HEX | '?' | '*';
442
fragment OCT: HEX WS? HEX;
Elemer Lelik's avatar
Elemer Lelik committed
443
444
445
446
fragment OCTORMATCH: OCT | '?' | '*';

// Corresponds to titan/compiler2/ttcn3/compiler.l
// TTCN-3 standard is more strict, it does NOT allow whitespaces between the bin/hex/oct digits
447
448

// BHOSTRING_WRONG is for for erroneous cases for [BHO]STRING(MATCH)? rules
Elemer Lelik's avatar
Elemer Lelik committed
449
450
//  - wrong character between the quotes
//  - odd number of hex digits in case of OSTRING(MATCH)?)
451
// These tokens are not used in any parser rules, but these cases must be parser errors instead of lexer errors
452

453
454
455
456
457
458
HSTRING:
{	valid_bit = true;
	valid_oct = true;
	half_oct = false;
	contains_match = false;
	contains_ws = false;
459
	invalid_char_reported = false;
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
	startIndex = getCharIndex();
}
	'\''
	(	[01]		{	half_oct = !half_oct;	}
	|	[2-9A-Fa-f]	{	valid_bit = false;
						half_oct = !half_oct;
					}
	|	[?*]		{	contains_match = true;
						if (half_oct) {
							valid_oct = false;
						}
					}
	|	[ \t\r\n\f]
		// a whitespace character. WS is not applicable here, as it can contain any number of characters, and using more Antlr * operators
		// in the lexer can consume a lot of memory, and it can lead to OutOfMemoryError in case of long strings.
					{	contains_ws = true;	}
	|	~['0-9A-Fa-f?* \t\r\n\f]
		// We make sure, that the options do NOT have any intersection
					{	errorChar("Invalid character `" + (char)_input.LA(0) + "' in binary string");
479
						invalid_char_reported = true;
480
481
482
483
484
485
486
487
488
489
490
						setType( BHOSTRING_WRONG );
					}
	)*
	(	'\''
		(	[Bb]	{	if ( _input.LA(0) == 'b' ) {
							warning("The last character of a bitstring literal should be `B' instead of `b'");
						}
						if (valid_bit) {
							if (contains_ws) {
								warning("Bitstring " + ( contains_match ? "match" : "value" ) + " contains whitespace and/or newline character(s)");
							}
491
							setType( contains_match ? BSTRINGMATCH : BSTRING );
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
						} else {
							error("Bitstring value contains invalid character");
							setType( BHOSTRING_WRONG );
						}
					}
		|	[Hh]	{	if ( _input.LA(0) == 'h' ) {
							warning("The last character of a hexstring literal should be `H' instead of `h'");
						}
						if (contains_ws) {
							warning("Hexstring " + ( contains_match ? "match" : "value" ) + " contains whitespace and/or newline character(s)");
						}
       					setType( contains_match ? HSTRINGMATCH : HSTRING );
					}
		|	[Oo]	{	if ( _input.LA(0) == 'o' ) {
							warning("The last character of a octetstring literal should be `O' instead of `o'");
						}
						if (valid_oct && !half_oct) {
							if (contains_ws) {
								warning("Octetstring " + ( contains_match ? "match" : "value" ) + " contains whitespace and/or newline character(s)");
							}
512
							setType( contains_match ? OSTRINGMATCH : OSTRING );
513
514
515
516
						} else if (contains_match) {
							error("Octetstring match contains half octet(s)");
							setType( BHOSTRING_WRONG );
						} else {
517
518
519
							if (invalid_char_reported == false) {
								error("Octetstring value contains odd number of hexadecimal digits");
							}
520
521
522
523
524
525
526
527
528
529
530
531
							setType( BHOSTRING_WRONG );
						}
					}
		|			{	error("Invalid binary string literal. Expecting `B', `H' or `O' after the closing `''");
						setType( BHOSTRING_WRONG );
					}
		)
	|		{	error("Unterminated binary string literal");
				setType( BHOSTRING_WRONG );
			}
	)
;
Elemer Lelik's avatar
Elemer Lelik committed
532

Elemer Lelik's avatar
Elemer Lelik committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
// Macros
MACRO_MODULEID:			'%moduleId' | '__MODULE__';
MACRO_DEFINITION_ID:	'%definitionId';
MACRO_TESTCASEID:		'%testcaseId' | '__TESTCASE__';
MACRO_FILENAME:			'%fileName';
MACRO_LINENUMBER:		'%lineNumber';
MACRO_FILEPATH:			'__FILE__';
MACRO_BFILENAME:		'__BFILE__';
MACRO_LINENUMBER_C:		'__LINE__';
MACRO_SCOPE:			'__SCOPE__';

// TITAN specific keywords
TITANSPECIFICTRY:	'@try';
TITANSPECIFICCATCH:	'@catch';
Gergo Ujhelyi's avatar
Gergo Ujhelyi committed
547
TITANSPECIFICUPDATEKEYWORD: '@update';
548
549

// modifier keywords
550
551
ABSTRACTKEYWORD:		'@abstract'				{ isOopEnabled }? ;
FINALKEYWORD:			'@final'				{ isOopEnabled }? ;
552
553
554
555
NOCASEKEYWORD:			'@nocase';
LAZYKEYWORD:			'@lazy';
DECODEDKEYWORD:			'@decoded';
DETERMINISTICKEYWORD:	'@deterministic';
556
CONTROLMODIFIER:		'@control'				{ isOopEnabled }? ;
557
DYNAMICKEYWORD:			'@dynamic';
558
559
FUZZYKEYWORD:			'@fuzzy';
INDEXKEYWORD:			'@index';
560
LOCALKEYWORD:			'@local';
561
562
563
564
TRAITKEYWORD:			'@trait'				{ isOopEnabled }? ;
PROPERTYKEYWORD:		'@property'				{ isOopEnabled }? ;
SETKEYWORD:				'@set'					{ isOopEnabled }? ;
GETKEYWORD:				'@get'					{ isOopEnabled }? ;
Elemer Lelik's avatar
Elemer Lelik committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658

fragment DIGIT: [0-9];

fragment INT: [1-9] DIGIT* | '0';

NUMBER: INT;

// Corresponds to FLOAT in titan/compiler2/ttcn3/compiler.l
// TTCN-3 standard is more strict, it allows only 'E' '-'? in the exponent part
FLOATVALUE:
(	INT '.' DIGIT+
|	INT ( '.' DIGIT+ )? [Ee] [+-]? INT
);

RANGEOP: '..';

DOT: '.';

SEMICOLON: ';';

COMMA: ',';

COLON: ':';

BEGINCHAR:
	'{'
{
  intervalDetector.pushInterval(_tokenStartCharIndex, _tokenStartLine, interval_type.NORMAL);
};

ENDCHAR:
	'}'
{
  intervalDetector.popInterval(_tokenStartCharIndex, _tokenStartLine);
};

SQUAREOPEN:
	'['
{
  intervalDetector.pushInterval(_tokenStartCharIndex, _tokenStartLine, interval_type.INDEX);
};

SQUARECLOSE:
	']'
{
  intervalDetector.popInterval(_tokenStartCharIndex, _tokenStartLine);
};

LPAREN:
	'('
{
  intervalDetector.pushInterval(_tokenStartCharIndex, _tokenStartLine, interval_type.PARAMETER);
};

RPAREN:
	')'
{
  intervalDetector.popInterval(_tokenStartCharIndex, _tokenStartLine);
};

LESSTHAN: '<';

MORETHAN: '>';

NOTEQUALS: '!=';

MOREOREQUAL: '>=';

LESSOREQUAL: '<=';

EQUAL: '==';

PLUS: '+';

MINUS: '-';

STAR: '*';

SLASH: '/';

EXCLAMATIONMARK: '!';

QUESTIONMARK: '?';

SHIFTLEFT: '<<';

SHIFTRIGHT: '>>';

ROTATELEFT: '<@';

ROTATERIGHT: '@>';

STRINGOP: '&';

659
660
661
662
// This should be the LAST lexer rule in your grammar
UNKNOWN_CHAR
    :   .
    ;