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; }
90 break { return BREAK; }
91 const { return CONST; }
92 continue { return CONTINUE; }
93 crate { return CRATE; }
96 extern { return EXTERN; }
97 false { return FALSE; }
101 impl { return IMPL; }
104 loop { return LOOP; }
105 match { return MATCH; }
107 move { return MOVE; }
109 priv { return PRIV; }
110 proc { return PROC; }
113 return { return RETURN; }
114 self { return SELF; }
115 static { return STATIC; }
116 struct { return STRUCT; }
117 trait { return TRAIT; }
118 true { return TRUE; }
119 type { return TYPE; }
120 typeof { return TYPEOF; }
121 unsafe { return UNSAFE; }
123 where { return WHERE; }
124 while { return WHILE; }
126 {ident} { return IDENT; }
128 0x[0-9a-fA-F_]+ { BEGIN(suffix); return LIT_INTEGER; }
129 0o[0-7_]+ { BEGIN(suffix); return LIT_INTEGER; }
130 0b[01_]+ { BEGIN(suffix); return LIT_INTEGER; }
131 [0-9][0-9_]* { BEGIN(suffix); return LIT_INTEGER; }
132 [0-9][0-9_]*\.(\.|[a-zA-Z]) { yyless(yyleng - 2); BEGIN(suffix); return LIT_INTEGER; }
134 [0-9][0-9_]*\.[0-9_]*([eE][-\+]?[0-9_]+)? { BEGIN(suffix); return LIT_FLOAT; }
135 [0-9][0-9_]*(\.[0-9_]*)?[eE][-\+]?[0-9_]+ { BEGIN(suffix); return LIT_FLOAT; }
139 \.\.\. { return DOTDOTDOT; }
140 \.\. { return DOTDOT; }
149 # { BEGIN(pound); yymore(); }
150 <pound>\! { BEGIN(shebang_or_attr); yymore(); }
151 <shebang_or_attr>\[ {
156 <shebang_or_attr>[^\[\n]*\n {
157 // Since the \n was eaten as part of the token, yylineno will have
158 // been incremented to the value 2 if the shebang was on the first
159 // line. This yyless undoes that, setting yylineno back to 1.
161 if (yyget_lineno() == 1) {
170 <pound>. { BEGIN(INITIAL); yyless(1); return '#'; }
173 :: { return MOD_SEP; }
179 => { return FAT_ARROW; }
185 \<\<= { return SHLEQ; }
189 \>\>= { return SHREQ; }
192 \x27 { BEGIN(ltorchar); yymore(); }
193 <ltorchar>static { BEGIN(INITIAL); return STATIC_LIFETIME; }
194 <ltorchar>{ident} { BEGIN(INITIAL); return LIFETIME; }
195 <ltorchar>\\[nrt\\\x27\x220]\x27 { BEGIN(suffix); return LIT_CHAR; }
196 <ltorchar>\\x[0-9a-fA-F]{2}\x27 { BEGIN(suffix); return LIT_CHAR; }
197 <ltorchar>\\u\{[0-9a-fA-F]?{6}\}\x27 { BEGIN(suffix); return LIT_CHAR; }
198 <ltorchar>.\x27 { BEGIN(suffix); return LIT_CHAR; }
199 <ltorchar>[\x80-\xff]{2,4}\x27 { BEGIN(suffix); return LIT_CHAR; }
200 <ltorchar><<EOF>> { BEGIN(INITIAL); return -1; }
202 b\x22 { BEGIN(bytestr); yymore(); }
203 <bytestr>\x22 { BEGIN(suffix); return LIT_BYTE_STR; }
205 <bytestr><<EOF>> { return -1; }
206 <bytestr>\\[n\nrt\\\x27\x220] { yymore(); }
207 <bytestr>\\x[0-9a-fA-F]{2} { yymore(); }
208 <bytestr>\\u\{[0-9a-fA-F]?{6}\} { yymore(); }
209 <bytestr>\\[^n\nrt\\\x27\x220] { return -1; }
210 <bytestr>(.|\n) { yymore(); }
212 br\x22 { BEGIN(rawbytestr_nohash); yymore(); }
213 <rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; }
214 <rawbytestr_nohash>(.|\n) { yymore(); }
215 <rawbytestr_nohash><<EOF>> { return -1; }
227 } else if (end_hashes != 0) {
229 if (end_hashes == num_hashes) {
231 return LIT_BYTE_STR_RAW;
238 if (end_hashes == num_hashes) {
240 return LIT_BYTE_STR_RAW;
248 if (end_hashes != 0) {
253 <rawbytestr><<EOF>> { return -1; }
255 b\x27 { BEGIN(byte); yymore(); }
256 <byte>\\[nrt\\\x27\x220]\x27 { BEGIN(INITIAL); return LIT_BYTE; }
257 <byte>\\x[0-9a-fA-F]{2}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
258 <byte>\\u[0-9a-fA-F]{4}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
259 <byte>\\U[0-9a-fA-F]{8}\x27 { BEGIN(INITIAL); return LIT_BYTE; }
260 <byte>.\x27 { BEGIN(INITIAL); return LIT_BYTE; }
261 <byte><<EOF>> { BEGIN(INITIAL); return -1; }
263 r\x22 { BEGIN(rawstr); yymore(); }
264 <rawstr>\x22 { BEGIN(suffix); return LIT_STR_RAW; }
265 <rawstr>(.|\n) { yymore(); }
266 <rawstr><<EOF>> { return -1; }
269 BEGIN(rawstr_esc_begin);
276 <rawstr_esc_begin># {
280 <rawstr_esc_begin>\x22 {
281 BEGIN(rawstr_esc_body);
284 <rawstr_esc_begin>(.|\n) { return -1; }
286 <rawstr_esc_body>\x22/# {
287 BEGIN(rawstr_esc_end);
290 <rawstr_esc_body>(.|\n) {
296 if (end_hashes == num_hashes) {
302 <rawstr_esc_end>[^#] {
304 BEGIN(rawstr_esc_body);
308 <rawstr_esc_begin,rawstr_esc_body,rawstr_esc_end><<EOF>> { return -1; }
310 \x22 { BEGIN(str); yymore(); }
311 <str>\x22 { BEGIN(suffix); return LIT_STR; }
313 <str><<EOF>> { return -1; }
314 <str>\\[n\nr\rt\\\x27\x220] { yymore(); }
315 <str>\\x[0-9a-fA-F]{2} { yymore(); }
316 <str>\\u\{[0-9a-fA-F]?{6}\} { yymore(); }
317 <str>\\[^n\nrt\\\x27\x220] { return -1; }
318 <str>(.|\n) { yymore(); }
320 \<- { return LARROW; }
321 -\> { return RARROW; }
323 -= { return MINUSEQ; }
324 && { return ANDAND; }
327 \|\| { return OROR; }
331 \+= { return PLUSEQ; }
333 \*= { return STAREQ; }
335 \/= { return SLASHEQ; }
337 \^= { return CARETEQ; }
339 %= { return PERCENTEQ; }
341 <<EOF>> { return 0; }