diff options
Diffstat (limited to 'crates')
5 files changed, 153 insertions, 45 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 413ecb278..448b87505 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -250,6 +250,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) { | |||
250 | T![!] if p.at(T![!=]) => (5, T![!=]), | 250 | T![!] if p.at(T![!=]) => (5, T![!=]), |
251 | T![-] if p.at(T![-=]) => (1, T![-=]), | 251 | T![-] if p.at(T![-=]) => (1, T![-=]), |
252 | T![-] => (10, T![-]), | 252 | T![-] => (10, T![-]), |
253 | T![as] => (12, T![as]), | ||
253 | 254 | ||
254 | _ => NOT_AN_OP | 255 | _ => NOT_AN_OP |
255 | } | 256 | } |
@@ -278,6 +279,10 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>, | |||
278 | if op_bp < bp { | 279 | if op_bp < bp { |
279 | break; | 280 | break; |
280 | } | 281 | } |
282 | if p.at(T![as]) { | ||
283 | lhs = cast_expr(p, lhs); | ||
284 | continue; | ||
285 | } | ||
281 | let m = lhs.precede(p); | 286 | let m = lhs.precede(p); |
282 | p.bump(op); | 287 | p.bump(op); |
283 | 288 | ||
@@ -296,6 +301,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> | |||
296 | // fn foo() { | 301 | // fn foo() { |
297 | // let _ = &1; | 302 | // let _ = &1; |
298 | // let _ = &mut &f(); | 303 | // let _ = &mut &f(); |
304 | // let _ = &1 as *const i32; | ||
299 | // } | 305 | // } |
300 | T![&] => { | 306 | T![&] => { |
301 | m = p.start(); | 307 | m = p.start(); |
@@ -305,9 +311,13 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> | |||
305 | } | 311 | } |
306 | // test unary_expr | 312 | // test unary_expr |
307 | // fn foo() { | 313 | // fn foo() { |
308 | // **&1; | 314 | // **&1 + 1; |
309 | // !!true; | 315 | // !!true; |
310 | // --1; | 316 | // --1; |
317 | // *&1 as u64; | ||
318 | // *x(1); | ||
319 | // &x[1]; | ||
320 | // -1..2; | ||
311 | // } | 321 | // } |
312 | T![*] | T![!] | T![-] => { | 322 | T![*] | T![!] | T![-] => { |
313 | m = p.start(); | 323 | m = p.start(); |
@@ -338,6 +348,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> | |||
338 | return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block()))); | 348 | return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block()))); |
339 | } | 349 | } |
340 | }; | 350 | }; |
351 | // parse the interior of the unary expression | ||
341 | expr_bp(p, r, 255); | 352 | expr_bp(p, r, 255); |
342 | Some((m.complete(p, kind), BlockLike::NotBlock)) | 353 | Some((m.complete(p, kind), BlockLike::NotBlock)) |
343 | } | 354 | } |
@@ -371,7 +382,6 @@ fn postfix_expr( | |||
371 | } | 382 | } |
372 | }, | 383 | }, |
373 | T![?] => try_expr(p, lhs), | 384 | T![?] => try_expr(p, lhs), |
374 | T![as] => cast_expr(p, lhs), | ||
375 | _ => break, | 385 | _ => break, |
376 | }; | 386 | }; |
377 | allow_calls = true; | 387 | allow_calls = true; |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rs b/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rs index f1c3f7118..1080b48a1 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rs | |||
@@ -1,5 +1,9 @@ | |||
1 | fn foo() { | 1 | fn foo() { |
2 | **&1; | 2 | **&1 + 1; |
3 | !!true; | 3 | !!true; |
4 | --1; | 4 | --1; |
5 | *&1 as u64; | ||
6 | *x(1); | ||
7 | &x[1]; | ||
8 | -1..2; | ||
5 | } | 9 | } |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.txt b/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.txt index 2d71efd86..e2b60d99f 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 44) | 1 | SOURCE_FILE@[0; 97) |
2 | FN_DEF@[0; 43) | 2 | FN_DEF@[0; 96) |
3 | FN_KW@[0; 2) "fn" | 3 | FN_KW@[0; 2) "fn" |
4 | WHITESPACE@[2; 3) " " | 4 | WHITESPACE@[2; 3) " " |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,38 +8,104 @@ SOURCE_FILE@[0; 44) | |||
8 | L_PAREN@[6; 7) "(" | 8 | L_PAREN@[6; 7) "(" |
9 | R_PAREN@[7; 8) ")" | 9 | R_PAREN@[7; 8) ")" |
10 | WHITESPACE@[8; 9) " " | 10 | WHITESPACE@[8; 9) " " |
11 | BLOCK_EXPR@[9; 43) | 11 | BLOCK_EXPR@[9; 96) |
12 | BLOCK@[9; 43) | 12 | BLOCK@[9; 96) |
13 | L_CURLY@[9; 10) "{" | 13 | L_CURLY@[9; 10) "{" |
14 | WHITESPACE@[10; 15) "\n " | 14 | WHITESPACE@[10; 15) "\n " |
15 | EXPR_STMT@[15; 20) | 15 | EXPR_STMT@[15; 24) |
16 | PREFIX_EXPR@[15; 19) | 16 | BIN_EXPR@[15; 23) |
17 | STAR@[15; 16) "*" | 17 | PREFIX_EXPR@[15; 19) |
18 | PREFIX_EXPR@[16; 19) | 18 | STAR@[15; 16) "*" |
19 | STAR@[16; 17) "*" | 19 | PREFIX_EXPR@[16; 19) |
20 | REF_EXPR@[17; 19) | 20 | STAR@[16; 17) "*" |
21 | AMP@[17; 18) "&" | 21 | REF_EXPR@[17; 19) |
22 | LITERAL@[18; 19) | 22 | AMP@[17; 18) "&" |
23 | INT_NUMBER@[18; 19) "1" | 23 | LITERAL@[18; 19) |
24 | SEMI@[19; 20) ";" | 24 | INT_NUMBER@[18; 19) "1" |
25 | WHITESPACE@[20; 25) "\n " | 25 | WHITESPACE@[19; 20) " " |
26 | EXPR_STMT@[25; 32) | 26 | PLUS@[20; 21) "+" |
27 | PREFIX_EXPR@[25; 31) | 27 | WHITESPACE@[21; 22) " " |
28 | EXCL@[25; 26) "!" | 28 | LITERAL@[22; 23) |
29 | PREFIX_EXPR@[26; 31) | 29 | INT_NUMBER@[22; 23) "1" |
30 | EXCL@[26; 27) "!" | 30 | SEMI@[23; 24) ";" |
31 | LITERAL@[27; 31) | 31 | WHITESPACE@[24; 29) "\n " |
32 | TRUE_KW@[27; 31) "true" | 32 | EXPR_STMT@[29; 36) |
33 | SEMI@[31; 32) ";" | 33 | PREFIX_EXPR@[29; 35) |
34 | WHITESPACE@[32; 37) "\n " | 34 | EXCL@[29; 30) "!" |
35 | EXPR_STMT@[37; 41) | 35 | PREFIX_EXPR@[30; 35) |
36 | PREFIX_EXPR@[37; 40) | 36 | EXCL@[30; 31) "!" |
37 | MINUS@[37; 38) "-" | 37 | LITERAL@[31; 35) |
38 | PREFIX_EXPR@[38; 40) | 38 | TRUE_KW@[31; 35) "true" |
39 | MINUS@[38; 39) "-" | 39 | SEMI@[35; 36) ";" |
40 | LITERAL@[39; 40) | 40 | WHITESPACE@[36; 41) "\n " |
41 | INT_NUMBER@[39; 40) "1" | 41 | EXPR_STMT@[41; 45) |
42 | SEMI@[40; 41) ";" | 42 | PREFIX_EXPR@[41; 44) |
43 | WHITESPACE@[41; 42) "\n" | 43 | MINUS@[41; 42) "-" |
44 | R_CURLY@[42; 43) "}" | 44 | PREFIX_EXPR@[42; 44) |
45 | WHITESPACE@[43; 44) "\n" | 45 | MINUS@[42; 43) "-" |
46 | LITERAL@[43; 44) | ||
47 | INT_NUMBER@[43; 44) "1" | ||
48 | SEMI@[44; 45) ";" | ||
49 | WHITESPACE@[45; 50) "\n " | ||
50 | EXPR_STMT@[50; 61) | ||
51 | CAST_EXPR@[50; 60) | ||
52 | PREFIX_EXPR@[50; 53) | ||
53 | STAR@[50; 51) "*" | ||
54 | REF_EXPR@[51; 53) | ||
55 | AMP@[51; 52) "&" | ||
56 | LITERAL@[52; 53) | ||
57 | INT_NUMBER@[52; 53) "1" | ||
58 | WHITESPACE@[53; 54) " " | ||
59 | AS_KW@[54; 56) "as" | ||
60 | WHITESPACE@[56; 57) " " | ||
61 | PATH_TYPE@[57; 60) | ||
62 | PATH@[57; 60) | ||
63 | PATH_SEGMENT@[57; 60) | ||
64 | NAME_REF@[57; 60) | ||
65 | IDENT@[57; 60) "u64" | ||
66 | SEMI@[60; 61) ";" | ||
67 | WHITESPACE@[61; 66) "\n " | ||
68 | EXPR_STMT@[66; 72) | ||
69 | PREFIX_EXPR@[66; 71) | ||
70 | STAR@[66; 67) "*" | ||
71 | CALL_EXPR@[67; 71) | ||
72 | PATH_EXPR@[67; 68) | ||
73 | PATH@[67; 68) | ||
74 | PATH_SEGMENT@[67; 68) | ||
75 | NAME_REF@[67; 68) | ||
76 | IDENT@[67; 68) "x" | ||
77 | ARG_LIST@[68; 71) | ||
78 | L_PAREN@[68; 69) "(" | ||
79 | LITERAL@[69; 70) | ||
80 | INT_NUMBER@[69; 70) "1" | ||
81 | R_PAREN@[70; 71) ")" | ||
82 | SEMI@[71; 72) ";" | ||
83 | WHITESPACE@[72; 77) "\n " | ||
84 | EXPR_STMT@[77; 83) | ||
85 | REF_EXPR@[77; 82) | ||
86 | AMP@[77; 78) "&" | ||
87 | INDEX_EXPR@[78; 82) | ||
88 | PATH_EXPR@[78; 79) | ||
89 | PATH@[78; 79) | ||
90 | PATH_SEGMENT@[78; 79) | ||
91 | NAME_REF@[78; 79) | ||
92 | IDENT@[78; 79) "x" | ||
93 | L_BRACK@[79; 80) "[" | ||
94 | LITERAL@[80; 81) | ||
95 | INT_NUMBER@[80; 81) "1" | ||
96 | R_BRACK@[81; 82) "]" | ||
97 | SEMI@[82; 83) ";" | ||
98 | WHITESPACE@[83; 88) "\n " | ||
99 | EXPR_STMT@[88; 94) | ||
100 | RANGE_EXPR@[88; 93) | ||
101 | PREFIX_EXPR@[88; 90) | ||
102 | MINUS@[88; 89) "-" | ||
103 | LITERAL@[89; 90) | ||
104 | INT_NUMBER@[89; 90) "1" | ||
105 | DOTDOT@[90; 92) ".." | ||
106 | LITERAL@[92; 93) | ||
107 | INT_NUMBER@[92; 93) "2" | ||
108 | SEMI@[93; 94) ";" | ||
109 | WHITESPACE@[94; 95) "\n" | ||
110 | R_CURLY@[95; 96) "}" | ||
111 | WHITESPACE@[96; 97) "\n" | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rs b/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rs index 2dac6be95..050638f56 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | fn foo() { | 1 | fn foo() { |
2 | let _ = &1; | 2 | let _ = &1; |
3 | let _ = &mut &f(); | 3 | let _ = &mut &f(); |
4 | let _ = &1 as *const i32; | ||
4 | } | 5 | } |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.txt b/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.txt index 8f34afe76..d6334e55b 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 52) | 1 | SOURCE_FILE@[0; 82) |
2 | FN_DEF@[0; 51) | 2 | FN_DEF@[0; 81) |
3 | FN_KW@[0; 2) "fn" | 3 | FN_KW@[0; 2) "fn" |
4 | WHITESPACE@[2; 3) " " | 4 | WHITESPACE@[2; 3) " " |
5 | NAME@[3; 6) | 5 | NAME@[3; 6) |
@@ -8,8 +8,8 @@ SOURCE_FILE@[0; 52) | |||
8 | L_PAREN@[6; 7) "(" | 8 | L_PAREN@[6; 7) "(" |
9 | R_PAREN@[7; 8) ")" | 9 | R_PAREN@[7; 8) ")" |
10 | WHITESPACE@[8; 9) " " | 10 | WHITESPACE@[8; 9) " " |
11 | BLOCK_EXPR@[9; 51) | 11 | BLOCK_EXPR@[9; 81) |
12 | BLOCK@[9; 51) | 12 | BLOCK@[9; 81) |
13 | L_CURLY@[9; 10) "{" | 13 | L_CURLY@[9; 10) "{" |
14 | WHITESPACE@[10; 15) "\n " | 14 | WHITESPACE@[10; 15) "\n " |
15 | LET_STMT@[15; 26) | 15 | LET_STMT@[15; 26) |
@@ -50,6 +50,33 @@ SOURCE_FILE@[0; 52) | |||
50 | L_PAREN@[46; 47) "(" | 50 | L_PAREN@[46; 47) "(" |
51 | R_PAREN@[47; 48) ")" | 51 | R_PAREN@[47; 48) ")" |
52 | SEMI@[48; 49) ";" | 52 | SEMI@[48; 49) ";" |
53 | WHITESPACE@[49; 50) "\n" | 53 | WHITESPACE@[49; 54) "\n " |
54 | R_CURLY@[50; 51) "}" | 54 | LET_STMT@[54; 79) |
55 | WHITESPACE@[51; 52) "\n" | 55 | LET_KW@[54; 57) "let" |
56 | WHITESPACE@[57; 58) " " | ||
57 | PLACEHOLDER_PAT@[58; 59) | ||
58 | UNDERSCORE@[58; 59) "_" | ||
59 | WHITESPACE@[59; 60) " " | ||
60 | EQ@[60; 61) "=" | ||
61 | WHITESPACE@[61; 62) " " | ||
62 | CAST_EXPR@[62; 78) | ||
63 | REF_EXPR@[62; 64) | ||
64 | AMP@[62; 63) "&" | ||
65 | LITERAL@[63; 64) | ||
66 | INT_NUMBER@[63; 64) "1" | ||
67 | WHITESPACE@[64; 65) " " | ||
68 | AS_KW@[65; 67) "as" | ||
69 | WHITESPACE@[67; 68) " " | ||
70 | POINTER_TYPE@[68; 78) | ||
71 | STAR@[68; 69) "*" | ||
72 | CONST_KW@[69; 74) "const" | ||
73 | WHITESPACE@[74; 75) " " | ||
74 | PATH_TYPE@[75; 78) | ||
75 | PATH@[75; 78) | ||
76 | PATH_SEGMENT@[75; 78) | ||
77 | NAME_REF@[75; 78) | ||
78 | IDENT@[75; 78) "i32" | ||
79 | SEMI@[78; 79) ";" | ||
80 | WHITESPACE@[79; 80) "\n" | ||
81 | R_CURLY@[80; 81) "}" | ||
82 | WHITESPACE@[81; 82) "\n" | ||