From 2ffea72f7481eafb564a0910c4b3a8ccae4a5c27 Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Wed, 23 Jan 2019 13:55:31 -0500 Subject: More correct raw ident handling --- crates/ra_syntax/src/lexer.rs | 13 +++--- .../tests/data/parser/ok/0041_raw_keywords.rs | 1 + .../tests/data/parser/ok/0041_raw_keywords.txt | 49 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.rs create mode 100644 crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.txt diff --git a/crates/ra_syntax/src/lexer.rs b/crates/ra_syntax/src/lexer.rs index 0c3847120..f9362120e 100644 --- a/crates/ra_syntax/src/lexer.rs +++ b/crates/ra_syntax/src/lexer.rs @@ -190,16 +190,19 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { } fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind { - match (c, ptr.current()) { + let is_raw = match (c, ptr.current()) { ('r', Some('#')) => { ptr.bump(); + true } ('_', Some(c)) if !is_ident_continue(c) => return UNDERSCORE, - _ => {} - } + _ => false, + }; ptr.bump_while(is_ident_continue); - if let Some(kind) = SyntaxKind::from_keyword(ptr.current_token_text()) { - return kind; + if !is_raw { + if let Some(kind) = SyntaxKind::from_keyword(ptr.current_token_text()) { + return kind; + } } IDENT } diff --git a/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.rs b/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.rs new file mode 100644 index 000000000..d59a6d347 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.rs @@ -0,0 +1 @@ +fn foo() { let r#struct = 92; let r#trait = r#struct * 2; } \ No newline at end of file diff --git a/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.txt b/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.txt new file mode 100644 index 000000000..f03ed17f5 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.txt @@ -0,0 +1,49 @@ +SOURCE_FILE@[0; 59) + FN_DEF@[0; 59) + FN_KW@[0; 2) + WHITESPACE@[2; 3) + NAME@[3; 6) + IDENT@[3; 6) "foo" + PARAM_LIST@[6; 8) + L_PAREN@[6; 7) + R_PAREN@[7; 8) + WHITESPACE@[8; 9) + BLOCK@[9; 59) + L_CURLY@[9; 10) + WHITESPACE@[10; 11) + LET_STMT@[11; 29) + LET_KW@[11; 14) + WHITESPACE@[14; 15) + BIND_PAT@[15; 23) + NAME@[15; 23) + IDENT@[15; 23) "r#struct" + WHITESPACE@[23; 24) + EQ@[24; 25) + WHITESPACE@[25; 26) + LITERAL@[26; 28) + INT_NUMBER@[26; 28) "92" + SEMI@[28; 29) + WHITESPACE@[29; 30) + LET_STMT@[30; 57) + LET_KW@[30; 33) + WHITESPACE@[33; 34) + BIND_PAT@[34; 41) + NAME@[34; 41) + IDENT@[34; 41) "r#trait" + WHITESPACE@[41; 42) + EQ@[42; 43) + WHITESPACE@[43; 44) + BIN_EXPR@[44; 56) + PATH_EXPR@[44; 52) + PATH@[44; 52) + PATH_SEGMENT@[44; 52) + NAME_REF@[44; 52) + IDENT@[44; 52) "r#struct" + WHITESPACE@[52; 53) + STAR@[53; 54) + WHITESPACE@[54; 55) + LITERAL@[55; 56) + INT_NUMBER@[55; 56) "2" + SEMI@[56; 57) + WHITESPACE@[57; 58) + R_CURLY@[58; 59) -- cgit v1.2.3