aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-23 19:09:48 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-23 19:09:48 +0000
commite3b6b5d27ec5976ba0d2390829a29185bcd71eba (patch)
tree6167216e6ac713186437e2bc7e32a674069bfda8 /crates/ra_syntax
parent302508d5bbcc261f8fe403714a7a7e1f5382879b (diff)
parent2ffea72f7481eafb564a0910c4b3a8ccae4a5c27 (diff)
Merge #619
619: More correct raw ident handling r=matklad a=jrobsonchase Also added the suggested test from #616. It passed before the change to `scan_ident`, but at least now it should ensure that the behavior stays the same. Co-authored-by: Josh Robson Chase <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/lexer.rs13
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.rs1
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0041_raw_keywords.txt49
3 files changed, 58 insertions, 5 deletions
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 {
190} 190}
191 191
192fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind { 192fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind {
193 match (c, ptr.current()) { 193 let is_raw = match (c, ptr.current()) {
194 ('r', Some('#')) => { 194 ('r', Some('#')) => {
195 ptr.bump(); 195 ptr.bump();
196 true
196 } 197 }
197 ('_', Some(c)) if !is_ident_continue(c) => return UNDERSCORE, 198 ('_', Some(c)) if !is_ident_continue(c) => return UNDERSCORE,
198 _ => {} 199 _ => false,
199 } 200 };
200 ptr.bump_while(is_ident_continue); 201 ptr.bump_while(is_ident_continue);
201 if let Some(kind) = SyntaxKind::from_keyword(ptr.current_token_text()) { 202 if !is_raw {
202 return kind; 203 if let Some(kind) = SyntaxKind::from_keyword(ptr.current_token_text()) {
204 return kind;
205 }
203 } 206 }
204 IDENT 207 IDENT
205} 208}
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 @@
1SOURCE_FILE@[0; 59)
2 FN_DEF@[0; 59)
3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3)
5 NAME@[3; 6)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 8)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK@[9; 59)
12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 11)
14 LET_STMT@[11; 29)
15 LET_KW@[11; 14)
16 WHITESPACE@[14; 15)
17 BIND_PAT@[15; 23)
18 NAME@[15; 23)
19 IDENT@[15; 23) "r#struct"
20 WHITESPACE@[23; 24)
21 EQ@[24; 25)
22 WHITESPACE@[25; 26)
23 LITERAL@[26; 28)
24 INT_NUMBER@[26; 28) "92"
25 SEMI@[28; 29)
26 WHITESPACE@[29; 30)
27 LET_STMT@[30; 57)
28 LET_KW@[30; 33)
29 WHITESPACE@[33; 34)
30 BIND_PAT@[34; 41)
31 NAME@[34; 41)
32 IDENT@[34; 41) "r#trait"
33 WHITESPACE@[41; 42)
34 EQ@[42; 43)
35 WHITESPACE@[43; 44)
36 BIN_EXPR@[44; 56)
37 PATH_EXPR@[44; 52)
38 PATH@[44; 52)
39 PATH_SEGMENT@[44; 52)
40 NAME_REF@[44; 52)
41 IDENT@[44; 52) "r#struct"
42 WHITESPACE@[52; 53)
43 STAR@[53; 54)
44 WHITESPACE@[54; 55)
45 LITERAL@[55; 56)
46 INT_NUMBER@[55; 56) "2"
47 SEMI@[56; 57)
48 WHITESPACE@[57; 58)
49 R_CURLY@[58; 59)