%{ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #include #include static int num_hashes; static int end_hashes; static int saw_non_hash; %} %option stack %option yylineno %x str %x rawstr %x rawstr_esc_begin %x rawstr_esc_body %x rawstr_esc_end %x byte %x bytestr %x rawbytestr %x rawbytestr_nohash %x pound %x shebang_or_attr %x ltorchar %x linecomment %x doc_line %x blockcomment %x doc_block %x suffix ident [a-zA-Z\x80-\xff_][a-zA-Z0-9\x80-\xff_]* %% {ident} { BEGIN(INITIAL); } (.|\n) { yyless(0); BEGIN(INITIAL); } [ \n\t\r] { } \xef\xbb\xbf { // UTF-8 byte order mark (BOM), ignore if in line 1, error otherwise if (yyget_lineno() != 1) { return -1; } } \/\/(\/|\!) { BEGIN(doc_line); yymore(); } \n { BEGIN(INITIAL); yyleng--; yytext[yyleng] = 0; return ((yytext[2] == '!') ? INNER_DOC_COMMENT : OUTER_DOC_COMMENT); } [^\n]* { yymore(); } \/\/|\/\/\/\/ { BEGIN(linecomment); } \n { BEGIN(INITIAL); } [^\n]* { } \/\*(\*|\!)[^*] { yy_push_state(INITIAL); yy_push_state(doc_block); yymore(); } \/\* { yy_push_state(doc_block); yymore(); } \*\/ { yy_pop_state(); if (yy_top_state() == doc_block) { yymore(); } else { return ((yytext[2] == '!') ? INNER_DOC_COMMENT : OUTER_DOC_COMMENT); } } (.|\n) { yymore(); } \/\* { yy_push_state(blockcomment); } \/\* { yy_push_state(blockcomment); } \*\/ { yy_pop_state(); } (.|\n) { } _ { return UNDERSCORE; } as { return AS; } box { return BOX; } break { return BREAK; } const { return CONST; } continue { return CONTINUE; } crate { return CRATE; } else { return ELSE; } enum { return ENUM; } extern { return EXTERN; } false { return FALSE; } fn { return FN; } for { return FOR; } if { return IF; } impl { return IMPL; } in { return IN; } let { return LET; } loop { return LOOP; } match { return MATCH; } mod { return MOD; } move { return MOVE; } mut { return MUT; } priv { return PRIV; } proc { return PROC; } pub { return PUB; } ref { return REF; } return { return RETURN; } self { return SELF; } static { return STATIC; } struct { return STRUCT; } trait { return TRAIT; } true { return TRUE; } type { return TYPE; } typeof { return TYPEOF; } unsafe { return UNSAFE; } use { return USE; } where { return WHERE; } while { return WHILE; } {ident} { return IDENT; } 0x[0-9a-fA-F_]+ { BEGIN(suffix); return LIT_INTEGER; } 0o[0-8_]+ { BEGIN(suffix); return LIT_INTEGER; } 0b[01_]+ { BEGIN(suffix); return LIT_INTEGER; } [0-9][0-9_]* { BEGIN(suffix); return LIT_INTEGER; } [0-9][0-9_]*\.(\.|[a-zA-Z]) { yyless(yyleng - 2); BEGIN(suffix); return LIT_INTEGER; } [0-9][0-9_]*\.[0-9_]*([eE][-\+]?[0-9_]+)? { BEGIN(suffix); return LIT_FLOAT; } [0-9][0-9_]*(\.[0-9_]*)?[eE][-\+]?[0-9_]+ { BEGIN(suffix); return LIT_FLOAT; } ; { return ';'; } , { return ','; } \.\.\. { return DOTDOTDOT; } \.\. { return DOTDOT; } \. { return '.'; } \( { return '('; } \) { return ')'; } \{ { return '{'; } \} { return '}'; } \[ { return '['; } \] { return ']'; } @ { return '@'; } # { BEGIN(pound); yymore(); } \! { BEGIN(shebang_or_attr); yymore(); } \[ { BEGIN(INITIAL); yyless(2); return SHEBANG; } [^\[\n]*\n { // Since the \n was eaten as part of the token, yylineno will have // been incremented to the value 2 if the shebang was on the first // line. This yyless undoes that, setting yylineno back to 1. yyless(yyleng - 1); if (yyget_lineno() == 1) { BEGIN(INITIAL); return SHEBANG_LINE; } else { BEGIN(INITIAL); yyless(2); return SHEBANG; } } . { BEGIN(INITIAL); yyless(1); return '#'; } \~ { return '~'; } :: { return MOD_SEP; } : { return ':'; } \$ { return '$'; } \? { return '?'; } == { return EQEQ; } => { return FAT_ARROW; } = { return '='; } \!= { return NE; } \! { return '!'; } \<= { return LE; } \<\< { return SHL; } \<\<= { return SHLEQ; } \< { return '<'; } \>= { return GE; } \>\> { return SHR; } \>\>= { return SHREQ; } \> { return '>'; } \x27 { BEGIN(ltorchar); yymore(); } static { BEGIN(INITIAL); return STATIC_LIFETIME; } {ident} { BEGIN(INITIAL); return LIFETIME; } \\[nrt\\\x27\x220]\x27 { BEGIN(suffix); return LIT_CHAR; } \\x[0-9a-fA-F]{2}\x27 { BEGIN(suffix); return LIT_CHAR; } \\u\{[0-9a-fA-F]?{6}\}\x27 { BEGIN(suffix); return LIT_CHAR; } .\x27 { BEGIN(suffix); return LIT_CHAR; } [\x80-\xff]{2,4}\x27 { BEGIN(suffix); return LIT_CHAR; } <> { BEGIN(INITIAL); return -1; } b\x22 { BEGIN(bytestr); yymore(); } \x22 { BEGIN(suffix); return LIT_BINARY; } <> { return -1; } \\[n\nrt\\\x27\x220] { yymore(); } \\x[0-9a-fA-F]{2} { yymore(); } \\u\{[0-9a-fA-F]?{6}\} { yymore(); } \\[^n\nrt\\\x27\x220] { return -1; } (.|\n) { yymore(); } br\x22 { BEGIN(rawbytestr_nohash); yymore(); } \x22 { BEGIN(suffix); return LIT_BINARY_RAW; } (.|\n) { yymore(); } <> { return -1; } br/# { BEGIN(rawbytestr); yymore(); num_hashes = 0; saw_non_hash = 0; end_hashes = 0; } # { if (!saw_non_hash) { num_hashes++; } else if (end_hashes != 0) { end_hashes++; if (end_hashes == num_hashes) { BEGIN(INITIAL); return LIT_BINARY_RAW; } } yymore(); } \x22# { end_hashes = 1; if (end_hashes == num_hashes) { BEGIN(INITIAL); return LIT_BINARY_RAW; } yymore(); } (.|\n) { if (!saw_non_hash) { saw_non_hash = 1; } if (end_hashes != 0) { end_hashes = 0; } yymore(); } <> { return -1; } b\x27 { BEGIN(byte); yymore(); } \\[nrt\\\x27\x220]\x27 { BEGIN(INITIAL); return LIT_BYTE; } \\x[0-9a-fA-F]{2}\x27 { BEGIN(INITIAL); return LIT_BYTE; } \\u[0-9a-fA-F]{4}\x27 { BEGIN(INITIAL); return LIT_BYTE; } \\U[0-9a-fA-F]{8}\x27 { BEGIN(INITIAL); return LIT_BYTE; } .\x27 { BEGIN(INITIAL); return LIT_BYTE; } <> { BEGIN(INITIAL); return -1; } r\x22 { BEGIN(rawstr); yymore(); } \x22 { BEGIN(suffix); return LIT_STR_RAW; } (.|\n) { yymore(); } <> { return -1; } r/# { BEGIN(rawstr_esc_begin); yymore(); num_hashes = 0; saw_non_hash = 0; end_hashes = 0; } # { num_hashes++; yymore(); } \x22 { BEGIN(rawstr_esc_body); yymore(); } (.|\n) { return -1; } \x22/# { BEGIN(rawstr_esc_end); yymore(); } (.|\n) { yymore(); } # { end_hashes++; if (end_hashes == num_hashes) { BEGIN(INITIAL); return LIT_STR_RAW; } yymore(); } [^#] { end_hashes = 0; BEGIN(rawstr_esc_body); yymore(); } <> { return -1; } \x22 { BEGIN(str); yymore(); } \x22 { BEGIN(suffix); return LIT_STR; } <> { return -1; } \\[n\nr\rt\\\x27\x220] { yymore(); } \\x[0-9a-fA-F]{2} { yymore(); } \\u\{[0-9a-fA-F]?{6}\} { yymore(); } \\[^n\nrt\\\x27\x220] { return -1; } (.|\n) { yymore(); } -\> { return RARROW; } - { return '-'; } -= { return MINUSEQ; } && { return ANDAND; } & { return '&'; } &= { return ANDEQ; } \|\| { return OROR; } \| { return '|'; } \|= { return OREQ; } \+ { return '+'; } \+= { return PLUSEQ; } \* { return '*'; } \*= { return STAREQ; } \/ { return '/'; } \/= { return SLASHEQ; } \^ { return '^'; } \^= { return CARETEQ; } % { return '%'; } %= { return PERCENTEQ; } <> { return 0; } %%