2 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
3 // file at the top-level directory of this distribution and at
4 // http://rust-lang.org/COPYRIGHT.
6 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 // option. This file may not be copied, modified, or distributed
10 // except according to those terms.
15 static int num_hashes;
16 static int end_hashes;
17 static int saw_non_hash;
42 ident [a-zA-Z\x80-\xff_][a-zA-Z0-9\x80-\xff_]*
46 <suffix>{ident} { BEGIN(INITIAL); }
47 <suffix>(.|\n) { yyless(0); BEGIN(INITIAL); }
52 // UTF-8 byte order mark (BOM), ignore if in line 1, error otherwise
53 if (yyget_lineno() != 1) {
58 \/\/(\/|\!) { BEGIN(doc_line); yymore(); }
59 <doc_line>\n { BEGIN(INITIAL);
62 return ((yytext[2] == '!') ? INNER_DOC_COMMENT : OUTER_DOC_COMMENT);
64 <doc_line>[^\n]* { yymore(); }
66 \/\/|\/\/\/\/ { BEGIN(linecomment); }
67 <linecomment>\n { BEGIN(INITIAL); }
68 <linecomment>[^\n]* { }
70 \/\*(\*|\!)[^*] { yy_push_state(INITIAL); yy_push_state(doc_block); yymore(); }
71 <doc_block>\/\* { yy_push_state(doc_block); yymore(); }
74 if (yy_top_state() == doc_block) {
77 return ((yytext[2] == '!') ? INNER_DOC_COMMENT : OUTER_DOC_COMMENT);
80 <doc_block>(.|\n) { yymore(); }
82 \/\* { yy_push_state(blockcomment); }
83 <blockcomment>\/\* { yy_push_state(blockcomment); }
84 <blockcomment>\*\/ { yy_pop_state(); }
85 <blockcomment>(.|\n) { }
87 _ { return UNDERSCORE; }
88 abstract { return ABSTRACT; }
89 alignof { return ALIGNOF; }
91 become { return BECOME; }
93 break { return BREAK; }
94 catch { return CATCH; }
95 const { return CONST; }
96 continue { return CONTINUE; }
97 crate { return CRATE; }
98 default { return DEFAULT; }
100 else { return ELSE; }
101 enum { return ENUM; }
102 extern { return EXTERN; }
103 false { return FALSE; }
104 final { return FINAL; }
108 impl { return IMPL; }
111 loop { return LOOP; }
112 macro { return MACRO; }
113 match { return MATCH; }
115 move { return MOVE; }
117 offsetof { return OFFSETOF; }
118 override { return OVERRIDE; }
119 priv { return PRIV; }
120 proc { return PROC; }
121 pure { return PURE; }
124 return { return RETURN; }
125 self { return SELF; }
126 sizeof { return SIZEOF; }
127 static { return STATIC; }
128 struct { return STRUCT; }
129 super { return SUPER; }
130 trait { return TRAIT; }
131 true { return TRUE; }
132 type { return TYPE; }
133 typeof { return TYPEOF; }
134 union { return UNION; }
135 unsafe { return UNSAFE; }
136 unsized { return UNSIZED; }
138 virtual { return VIRTUAL; }
139 where { return WHERE; }
140 while { return WHILE; }
141 yield { return YIELD; }
143 {ident} { return IDENT; }
145 0x[0-9a-fA-F_]+ { BEGIN(suffix); return LIT_INTEGER; }
146 0o[0-7_]+ { BEGIN(suffix); return LIT_INTEGER; }
147 0b[01_]+ { BEGIN(suffix); return LIT_INTEGER; }
148 [0-9][0-9_]* { BEGIN(suffix); return LIT_INTEGER; }
149 [0-9][0-9_]*\.(\.|[a-zA-Z]) { yyless(yyleng - 2); BEGIN(suffix); return LIT_INTEGER; }
151 [0-9][0-9_]*\.[0-9_]*([eE][-\+]?[0-9_]+)? { BEGIN(suffix); return LIT_FLOAT; }
152 [0-9][0-9_]*(\.[0-9_]*)?[eE][-\+]?[0-9_]+ { BEGIN(suffix); return LIT_FLOAT; }
156 \.\.\. { return DOTDOTDOT; }
157 \.\. { return DOTDOT; }
166 # { BEGIN(pound); yymore(); }
167 <pound>\! { BEGIN(shebang_or_attr); yymore(); }
168 <shebang_or_attr>\[ {
173 <shebang_or_attr>[^\[\n]*\n {
174 // Since the \n was eaten as part of the token, yylineno will have
175 // been incremented to the value 2 if the shebang was on the first
176 // line. This yyless undoes that, setting yylineno back to 1.
178 if (yyget_lineno() == 1) {
187 <pound>. { BEGIN(INITIAL); yyless(1); return '#'; }
190 :: { return MOD_SEP; }
196 => { return FAT_ARROW; }
202 \<\<= { return SHLEQ; }
206 \>\>= { return SHREQ; }
209 \x27 { BEGIN(ltorchar); yymore(); }
210 <ltorchar>static { BEGIN(INITIAL); return STATIC_LIFETIME; }
211 <ltorchar>{ident} { BEGIN(INITIAL); return LIFETIME; }
212 <ltorchar>\\[nrt\\\x27\x220]\x27 { BEGIN(suffix); return LIT_CHAR; }
213 <ltorchar>\\x[0-9a-fA-F]{2}\x27 { BEGIN(suffix); return LIT_CHAR; }
214 <ltorchar>\\u\{([0-9a-fA-F]_*){1,6}\}\x27 { BEGIN(suffix); return LIT_CHAR; }
215 <ltorchar>.\x27 { BEGIN(suffix); return LIT_CHAR; }
216 <ltorchar>[\x80-\xff]{2,4}\x27 { BEGIN(suffix); return LIT_CHAR; }
217 <ltorchar><<EOF>> { BEGIN(INITIAL); return -1; }
219 b\x22 { BEGIN(bytestr); yymore(); }
220 <bytestr>\x22 { BEGIN(suffix); return LIT_BYTE_STR; }
222 <bytestr><<EOF>> { return -1; }
223 <bytestr>\\[n\nrt\\\x27\x220] { yymore(); }
224 <bytestr>\\x[0-9a-fA-F]{2} { yymore(); }
225 <bytestr>\\u\{([0-9a-fA-F]_*){1,6}\} { yymore(); }
226 <bytestr>\\[^n\nrt\\\x27\x220] { return -1; }
227 <bytestr>(.|\n) { yymore(); }
229 br\x22 { BEGIN(rawbytestr_nohash); yymore(); }
230 <rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; }
231 <rawbytestr_nohash>(.|\n) { yymore(); }
232 <rawbytestr_nohash><<EOF>> { return -1; }
244 } else if (end_hashes != 0) {
246 if (end_hashes == num_hashes) {
248 return LIT_BYTE_STR_RAW;
255 if (end_hashes == num_hashes) {
257 return LIT_BYTE_STR_RAW;
265 if (end_hashes != 0) {
270 <rawbytestr><<EOF>> { return -1; }
272 b\x27 { BEGIN(byte); yymore(); }
273 <byte>\\[nrt\\\x27\x220]\x27 { BEGIN(INITIAL); return LIT_BYTE; }
274 <byte>\\x[0-9a-fA-F]{2}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
275 <byte>\\u([0-9a-fA-F]_*){4}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
276 <byte>\\U([0-9a-fA-F]_*){8}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
277 <byte>.\x27 { BEGIN(INITIAL); return LIT_BYTE; }
278 <byte><<EOF>> { BEGIN(INITIAL); return -1; }
280 r\x22 { BEGIN(rawstr); yymore(); }
281 <rawstr>\x22 { BEGIN(suffix); return LIT_STR_RAW; }
282 <rawstr>(.|\n) { yymore(); }
283 <rawstr><<EOF>> { return -1; }
286 BEGIN(rawstr_esc_begin);
293 <rawstr_esc_begin># {
297 <rawstr_esc_begin>\x22 {
298 BEGIN(rawstr_esc_body);
301 <rawstr_esc_begin>(.|\n) { return -1; }
303 <rawstr_esc_body>\x22/# {
304 BEGIN(rawstr_esc_end);
307 <rawstr_esc_body>(.|\n) {
313 if (end_hashes == num_hashes) {
319 <rawstr_esc_end>[^#] {
321 BEGIN(rawstr_esc_body);
325 <rawstr_esc_begin,rawstr_esc_body,rawstr_esc_end><<EOF>> { return -1; }
327 \x22 { BEGIN(str); yymore(); }
328 <str>\x22 { BEGIN(suffix); return LIT_STR; }
330 <str><<EOF>> { return -1; }
331 <str>\\[n\nr\rt\\\x27\x220] { yymore(); }
332 <str>\\x[0-9a-fA-F]{2} { yymore(); }
333 <str>\\u\{([0-9a-fA-F]_*){1,6}\} { yymore(); }
334 <str>\\[^n\nrt\\\x27\x220] { return -1; }
335 <str>(.|\n) { yymore(); }
337 \<- { return LARROW; }
338 -\> { return RARROW; }
340 -= { return MINUSEQ; }
341 && { return ANDAND; }
344 \|\| { return OROR; }
348 \+= { return PLUSEQ; }
350 \*= { return STAREQ; }
352 \/= { return SLASHEQ; }
354 \^= { return CARETEQ; }
356 %= { return PERCENTEQ; }
358 <<EOF>> { return 0; }