Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | lexer grammar CTFLexer; |
2 | ||
3 | options { | |
91fd06f5 | 4 | language = Java; |
866e5b51 FC |
5 | } |
6 | ||
7 | @lexer::header { | |
9ad3c628 AM |
8 | /******************************************************************************* |
9 | * Copyright (c) 2010, 2013 Ericsson, Ecole Polytechnique de Montréal and others | |
10 | * | |
11 | * All rights reserved. This program and the accompanying materials are | |
12 | * made available under the terms of the Eclipse Public License v1.0 which | |
13 | * accompanies this distribution, and is available at | |
14 | * http://www.eclipse.org/legal/epl-v10.html | |
15 | * | |
16 | * Contributors: | |
17 | * Matthew Khouzam - Initial API and implementation | |
18 | * Simon Marchi - Initial API and implementation | |
19 | * Etienne Bergeron - Update to Antlr 3.5 syntax | |
20 | *******************************************************************************/ | |
21 | ||
22 | package org.eclipse.tracecompass.ctf.parser; | |
866e5b51 FC |
23 | } |
24 | ||
25 | /* | |
e8143d31 | 26 | * Lexer tokens |
866e5b51 | 27 | */ |
91fd06f5 | 28 | |
866e5b51 FC |
29 | /* |
30 | * Keywords | |
31 | */ | |
32 | ALIGNTOK : 'align' ; | |
33 | CONSTTOK : 'const' ; | |
34 | CHARTOK : 'char' ; | |
35 | DOUBLETOK : 'double' ; | |
36 | ENUMTOK : 'enum' ; | |
37 | EVENTTOK : 'event' ; | |
38 | FLOATINGPOINTTOK : 'floating_point' ; | |
39 | FLOATTOK : 'float' ; | |
40 | INTEGERTOK : 'integer' ; | |
41 | INTTOK : 'int' ; | |
42 | LONGTOK : 'long' ; | |
43 | SHORTTOK : 'short' ; | |
44 | SIGNEDTOK : 'signed' ; | |
45 | STREAMTOK : 'stream' ; | |
46 | STRINGTOK : 'string' ; | |
47 | STRUCTTOK : 'struct' ; | |
48 | TRACETOK : 'trace' ; | |
49 | TYPEALIASTOK : 'typealias' ; | |
50 | TYPEDEFTOK : 'typedef' ; | |
51 | UNSIGNEDTOK : 'unsigned' ; | |
52 | VARIANTTOK : 'variant' ; | |
53 | VOIDTOK : 'void' ; | |
54 | BOOLTOK : '_Bool' ; | |
55 | COMPLEXTOK : '_Complex' ; | |
56 | IMAGINARYTOK : '_Imaginary' ; | |
57 | ENVTOK : 'env' ; | |
58 | CLOCKTOK : 'clock' ; | |
4c9d2941 | 59 | /* |
e8143d31 | 60 | * Callsite tokens (CTF v1.9) |
4c9d2941 MK |
61 | */ |
62 | CALLSITETOK : 'callsite' ; | |
63 | ||
866e5b51 FC |
64 | |
65 | /* | |
e8143d31 EB |
66 | * These tokens are not part of the CTF standard. |
67 | * There are planned to be in CTF v1.9 | |
866e5b51 FC |
68 | */ |
69 | NANNUMBERTOK : 'NaN' ; | |
70 | INFINITYTOK : '+inf' ; | |
71 | NINFINITYTOK : '-inf' ; | |
72 | ||
73 | /* | |
74 | * Symbols | |
75 | */ | |
76 | SEPARATOR : ',' ; | |
77 | COLON : ':' ; | |
78 | ELIPSES : '...' ; | |
79 | ASSIGNMENT : '=' ; | |
80 | TYPE_ASSIGNMENT : ':=' ; | |
81 | LT : '<' ; | |
82 | GT : '>' ; | |
83 | OPENBRAC : '[' ; | |
84 | CLOSEBRAC : ']' ; | |
85 | LPAREN : '(' ; | |
86 | RPAREN : ')' ; | |
87 | LCURL : '{' ; | |
88 | RCURL : '}' ; | |
89 | TERM : ';' ; | |
90 | POINTER : '*' ; | |
91 | SIGN : '+' | '-' ; | |
92 | ARROW : '->' ; | |
93 | DOT : '.' ; | |
94 | fragment BACKSLASH : '\\' ; | |
95 | ||
e8143d31 EB |
96 | /* Helpers for integer literals */ |
97 | fragment DIGIT : '0'..'9' ; | |
98 | fragment OCT_DIGIT : '0'..'7' ; | |
99 | fragment OCT_PREFIX : '0' ; | |
100 | fragment NONZERO_DIGIT : '1'..'9' ; | |
101 | fragment HEX_DIGIT : DIGIT | ('a'..'f') | ('A'..'F') ; | |
102 | fragment HEX_PREFIX : '0' ('x' | 'X') ; | |
866e5b51 FC |
103 | |
104 | /* | |
105 | * Integer literals | |
106 | */ | |
e8143d31 | 107 | OCTAL_LITERAL : OCT_PREFIX (OCT_DIGIT)+ INTEGER_TYPES_SUFFIX? ; |
866e5b51 | 108 | DECIMAL_LITERAL : DIGIT+ INTEGER_TYPES_SUFFIX? ; |
866e5b51 | 109 | HEX_LITERAL : HEX_PREFIX HEX_DIGIT+ INTEGER_TYPES_SUFFIX? ; |
866e5b51 FC |
110 | |
111 | /** | |
112 | * Integer suffix for long, long long and unsigned. | |
113 | * | |
114 | * Matches all possible combination of L, LL and U. | |
91fd06f5 | 115 | */ |
e8143d31 EB |
116 | fragment INTEGER_TYPES_SUFFIX |
117 | : ('l' ('l')? | 'L' ('L')?) // l, ll | |
91fd06f5 EB |
118 | | ('u' | 'U') // u |
119 | | ('u' | 'U') ('l' ('l')? | 'L' ('L')?) // ul, ull | |
120 | | ('l' ('l')? | 'L' ('L')?) ('u'| 'U') // lu, llu | |
121 | ; | |
866e5b51 FC |
122 | |
123 | /** | |
124 | * Escape sequences | |
125 | */ | |
e8143d31 EB |
126 | fragment ESCAPE_SEQUENCE |
127 | : BACKSLASH ('\'' | '"' | '?' | BACKSLASH | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' ) | |
91fd06f5 EB |
128 | | OCTAL_ESCAPE |
129 | | UNICODE_ESCAPE | |
130 | | HEXADECIMAL_ESCAPE | |
32e3cfd4 | 131 | ; |
866e5b51 FC |
132 | |
133 | /** | |
134 | * Octal escape sequence | |
135 | */ | |
e8143d31 EB |
136 | fragment OCTAL_ESCAPE |
137 | : BACKSLASH ('0'..'3') ('0'..'7') ('0'..'7') | |
866e5b51 FC |
138 | | BACKSLASH ('0'..'7') ('0'..'7') |
139 | | BACKSLASH ('0'..'7') | |
140 | ; | |
141 | ||
142 | /** | |
143 | * Hexadecimal escape sequence | |
144 | */ | |
145 | fragment HEXADECIMAL_ESCAPE : BACKSLASH 'x' HEX_DIGIT+ ; | |
146 | ||
147 | /** | |
148 | * Unicode escape sequence | |
149 | */ | |
e8143d31 EB |
150 | fragment UNICODE_ESCAPE |
151 | : BACKSLASH 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | |
866e5b51 FC |
152 | | BACKSLASH 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT |
153 | ; | |
154 | ||
155 | ||
156 | /* Used in both character and string literal */ | |
157 | fragment STRINGPREFIX : 'L'; | |
158 | ||
159 | /* | |
160 | * Character literal | |
161 | */ | |
162 | CHARACTER_LITERAL : STRINGPREFIX? SINGLEQUOTE CHAR_CONTENT+ SINGLEQUOTE ; | |
163 | fragment CHAR_CONTENT : (ESCAPE_SEQUENCE | ~(BACKSLASH | SINGLEQUOTE)) ; | |
164 | fragment SINGLEQUOTE : '\''; | |
165 | ||
166 | /* | |
167 | * String literal | |
168 | */ | |
169 | STRING_LITERAL : STRINGPREFIX? DOUBLEQUOTE STRING_CONTENT* DOUBLEQUOTE ; | |
170 | fragment STRING_CONTENT : (ESCAPE_SEQUENCE | ~(BACKSLASH | DOUBLEQUOTE)) ; | |
171 | fragment DOUBLEQUOTE : '"' ; | |
172 | ||
173 | /** | |
174 | * Whitespaces | |
175 | */ | |
e8143d31 | 176 | WS : (' ' | '\r' | '\t' | '\u000C' | '\n') { $channel = HIDDEN; } ; |
866e5b51 FC |
177 | |
178 | /** | |
179 | * Multiline comment | |
91fd06f5 | 180 | */ |
866e5b51 | 181 | // About the greedy option: see page 100-101 of The Definitive ANTLR reference |
e8143d31 | 182 | // COMMENT : '/*' ( options { greedy = false; } : . )* '*/' { $channel = HIDDEN; } ; |
866e5b51 FC |
183 | COMMENT : COMMENT_OPEN .* COMMENT_CLOSE { $channel = HIDDEN; } ; |
184 | fragment COMMENT_OPEN : '/*'; | |
185 | fragment COMMENT_CLOSE : '*/'; | |
186 | ||
187 | /** | |
188 | * Single line comment | |
189 | */ | |
e8143d31 | 190 | LINE_COMMENT : '//' ~('\n')* '\n' { $channel = HIDDEN; } ; |
866e5b51 FC |
191 | |
192 | /** | |
193 | * Identifiers | |
194 | */ | |
195 | IDENTIFIER : NONDIGIT (NONDIGIT | DIGIT)* ; | |
196 | fragment NONDIGIT : ('_') | ('A'..'Z') | ('a'..'z') ; |