diff options
author | csmoe <[email protected]> | 2019-06-18 16:50:57 +0100 |
---|---|---|
committer | csmoe <[email protected]> | 2019-06-19 07:28:50 +0100 |
commit | d6533994e461dac502672c77ff27c6ca08fdc092 (patch) | |
tree | 70c83566743f087a987f09f0d64f293ac6fda0d6 /crates | |
parent | 5999733ca60e37c54d761b0a669e154b97b121b1 (diff) |
fix: box_pattern
Change-Id: I45a856d74fb616d3bce33050f9e69d327186bd59
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 5 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 15 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 3 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt | 41 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs (renamed from crates/ra_syntax/tests/data/parser/inline/ok/0132_box_syntax.rs) | 0 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt | 31 |
9 files changed, 94 insertions, 11 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 2ae05521c..795dccea1 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -583,8 +583,3 @@ pub(crate) fn named_field_list(p: &mut Parser) { | |||
583 | p.expect(T!['}']); | 583 | p.expect(T!['}']); |
584 | m.complete(p, NAMED_FIELD_LIST); | 584 | m.complete(p, NAMED_FIELD_LIST); |
585 | } | 585 | } |
586 | |||
587 | // test box_syntax | ||
588 | // fn foo() { | ||
589 | // let x = box 1i32; | ||
590 | // } | ||
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 725fb99f6..41be283d0 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -74,6 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
74 | T![if] => if_expr(p), | 74 | T![if] => if_expr(p), |
75 | 75 | ||
76 | T![loop] => loop_expr(p, None), | 76 | T![loop] => loop_expr(p, None), |
77 | T![box] => box_expr(p, None), | ||
77 | T![for] => for_expr(p, None), | 78 | T![for] => for_expr(p, None), |
78 | T![while] => while_expr(p, None), | 79 | T![while] => while_expr(p, None), |
79 | T![try] => try_block_expr(p, None), | 80 | T![try] => try_block_expr(p, None), |
@@ -507,3 +508,17 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
507 | block(p); | 508 | block(p); |
508 | m.complete(p, TRY_EXPR) | 509 | m.complete(p, TRY_EXPR) |
509 | } | 510 | } |
511 | |||
512 | // test box_expr | ||
513 | // fn foo() { | ||
514 | // let x = box 1i32; | ||
515 | // } | ||
516 | fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | ||
517 | assert!(p.at(T![box])); | ||
518 | let m = m.unwrap_or_else(|| p.start()); | ||
519 | p.bump(); | ||
520 | if p.at_ts(EXPR_FIRST) { | ||
521 | expr(p); | ||
522 | } | ||
523 | m.complete(p, BOX_EXPR) | ||
524 | } | ||
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 16ae9da63..46034942a 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | |||
60 | let la1 = p.nth(1); | 60 | let la1 = p.nth(1); |
61 | if la0 == T![ref] | 61 | if la0 == T![ref] |
62 | || la0 == T![mut] | 62 | || la0 == T![mut] |
63 | || la0 == T![box] | ||
63 | || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) | 64 | || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) |
64 | { | 65 | { |
65 | return Some(bind_pat(p, true)); | 66 | return Some(bind_pat(p, true)); |
@@ -260,9 +261,11 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) { | |||
260 | // let ref mut d = (); | 261 | // let ref mut d = (); |
261 | // let e @ _ = (); | 262 | // let e @ _ = (); |
262 | // let ref mut f @ g @ _ = (); | 263 | // let ref mut f @ g @ _ = (); |
264 | // let box i = Box::new(1i32); | ||
263 | // } | 265 | // } |
264 | fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { | 266 | fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { |
265 | let m = p.start(); | 267 | let m = p.start(); |
268 | p.eat(T![box]); | ||
266 | p.eat(T![ref]); | 269 | p.eat(T![ref]); |
267 | p.eat(T![mut]); | 270 | p.eat(T![mut]); |
268 | name(p); | 271 | name(p); |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 036415eac..374fd5aec 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -104,6 +104,7 @@ pub enum SyntaxKind { | |||
104 | MOVE_KW, | 104 | MOVE_KW, |
105 | RETURN_KW, | 105 | RETURN_KW, |
106 | TRY_KW, | 106 | TRY_KW, |
107 | BOX_KW, | ||
107 | AUTO_KW, | 108 | AUTO_KW, |
108 | DEFAULT_KW, | 109 | DEFAULT_KW, |
109 | EXISTENTIAL_KW, | 110 | EXISTENTIAL_KW, |
@@ -187,6 +188,7 @@ pub enum SyntaxKind { | |||
187 | NAMED_FIELD_LIST, | 188 | NAMED_FIELD_LIST, |
188 | NAMED_FIELD, | 189 | NAMED_FIELD, |
189 | TRY_BLOCK_EXPR, | 190 | TRY_BLOCK_EXPR, |
191 | BOX_EXPR, | ||
190 | CALL_EXPR, | 192 | CALL_EXPR, |
191 | INDEX_EXPR, | 193 | INDEX_EXPR, |
192 | METHOD_CALL_EXPR, | 194 | METHOD_CALL_EXPR, |
@@ -335,6 +337,7 @@ macro_rules! T { | |||
335 | (move) => { $crate::SyntaxKind::MOVE_KW }; | 337 | (move) => { $crate::SyntaxKind::MOVE_KW }; |
336 | (return) => { $crate::SyntaxKind::RETURN_KW }; | 338 | (return) => { $crate::SyntaxKind::RETURN_KW }; |
337 | (try) => { $crate::SyntaxKind::TRY_KW }; | 339 | (try) => { $crate::SyntaxKind::TRY_KW }; |
340 | (box) => { $crate::SyntaxKind::BOX_KW }; | ||
338 | (auto) => { $crate::SyntaxKind::AUTO_KW }; | 341 | (auto) => { $crate::SyntaxKind::AUTO_KW }; |
339 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; | 342 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; |
340 | (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; | 343 | (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; |
@@ -394,6 +397,7 @@ impl SyntaxKind { | |||
394 | | MOVE_KW | 397 | | MOVE_KW |
395 | | RETURN_KW | 398 | | RETURN_KW |
396 | | TRY_KW | 399 | | TRY_KW |
400 | | BOX_KW | ||
397 | | AUTO_KW | 401 | | AUTO_KW |
398 | | DEFAULT_KW | 402 | | DEFAULT_KW |
399 | | EXISTENTIAL_KW | 403 | | EXISTENTIAL_KW |
@@ -567,6 +571,7 @@ impl SyntaxKind { | |||
567 | MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, | 571 | MOVE_KW => &SyntaxInfo { name: "MOVE_KW" }, |
568 | RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, | 572 | RETURN_KW => &SyntaxInfo { name: "RETURN_KW" }, |
569 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, | 573 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, |
574 | BOX_KW => &SyntaxInfo { name: "BOX_KW" }, | ||
570 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, | 575 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, |
571 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, | 576 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, |
572 | EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, | 577 | EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, |
@@ -650,6 +655,7 @@ impl SyntaxKind { | |||
650 | NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, | 655 | NAMED_FIELD_LIST => &SyntaxInfo { name: "NAMED_FIELD_LIST" }, |
651 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 656 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
652 | TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, | 657 | TRY_BLOCK_EXPR => &SyntaxInfo { name: "TRY_BLOCK_EXPR" }, |
658 | BOX_EXPR => &SyntaxInfo { name: "BOX_EXPR" }, | ||
653 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, | 659 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, |
654 | INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, | 660 | INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, |
655 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, | 661 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, |
@@ -745,6 +751,7 @@ impl SyntaxKind { | |||
745 | "move" => MOVE_KW, | 751 | "move" => MOVE_KW, |
746 | "return" => RETURN_KW, | 752 | "return" => RETURN_KW, |
747 | "try" => TRY_KW, | 753 | "try" => TRY_KW, |
754 | "box" => BOX_KW, | ||
748 | _ => return None, | 755 | _ => return None, |
749 | }; | 756 | }; |
750 | Some(kw) | 757 | Some(kw) |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index eab55058b..6c075a700 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -96,6 +96,7 @@ Grammar( | |||
96 | "move", | 96 | "move", |
97 | "return", | 97 | "return", |
98 | "try", | 98 | "try", |
99 | "box", | ||
99 | ], | 100 | ], |
100 | contextual_keywords: [ | 101 | contextual_keywords: [ |
101 | "auto", | 102 | "auto", |
@@ -192,6 +193,7 @@ Grammar( | |||
192 | "NAMED_FIELD_LIST", | 193 | "NAMED_FIELD_LIST", |
193 | "NAMED_FIELD", | 194 | "NAMED_FIELD", |
194 | "TRY_BLOCK_EXPR", | 195 | "TRY_BLOCK_EXPR", |
196 | "BOX_EXPR", | ||
195 | 197 | ||
196 | // postfix | 198 | // postfix |
197 | "CALL_EXPR", | 199 | "CALL_EXPR", |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs index 820a9e72c..5a93469af 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.rs | |||
@@ -5,4 +5,5 @@ fn main() { | |||
5 | let ref mut d = (); | 5 | let ref mut d = (); |
6 | let e @ _ = (); | 6 | let e @ _ = (); |
7 | let ref mut f @ g @ _ = (); | 7 | let ref mut f @ g @ _ = (); |
8 | let box i = Box::new(1i32); | ||
8 | } | 9 | } |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt index ab0f88507..189254a19 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0112_bind_pat.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | SOURCE_FILE@[0; 146) | 1 | SOURCE_FILE@[0; 178) |
2 | FN_DEF@[0; 145) | 2 | FN_DEF@[0; 177) |
3 | FN_KW@[0; 2) "fn" | 3 | FN_KW@[0; 2) "fn" |
4 | WHITESPACE@[2; 3) " " | 4 | WHITESPACE@[2; 3) " " |
5 | NAME@[3; 7) | 5 | NAME@[3; 7) |
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 146) | |||
8 | L_PAREN@[7; 8) "(" | 8 | L_PAREN@[7; 8) "(" |
9 | R_PAREN@[8; 9) ")" | 9 | R_PAREN@[8; 9) ")" |
10 | WHITESPACE@[9; 10) " " | 10 | WHITESPACE@[9; 10) " " |
11 | BLOCK@[10; 145) | 11 | BLOCK@[10; 177) |
12 | L_CURLY@[10; 11) "{" | 12 | L_CURLY@[10; 11) "{" |
13 | WHITESPACE@[11; 16) "\n " | 13 | WHITESPACE@[11; 16) "\n " |
14 | LET_STMT@[16; 27) | 14 | LET_STMT@[16; 27) |
@@ -122,6 +122,35 @@ SOURCE_FILE@[0; 146) | |||
122 | L_PAREN@[140; 141) "(" | 122 | L_PAREN@[140; 141) "(" |
123 | R_PAREN@[141; 142) ")" | 123 | R_PAREN@[141; 142) ")" |
124 | SEMI@[142; 143) ";" | 124 | SEMI@[142; 143) ";" |
125 | WHITESPACE@[143; 144) "\n" | 125 | WHITESPACE@[143; 148) "\n " |
126 | R_CURLY@[144; 145) "}" | 126 | LET_STMT@[148; 175) |
127 | WHITESPACE@[145; 146) "\n" | 127 | LET_KW@[148; 151) "let" |
128 | WHITESPACE@[151; 152) " " | ||
129 | BIND_PAT@[152; 157) | ||
130 | BOX_KW@[152; 155) "box" | ||
131 | WHITESPACE@[155; 156) " " | ||
132 | NAME@[156; 157) | ||
133 | IDENT@[156; 157) "i" | ||
134 | WHITESPACE@[157; 158) " " | ||
135 | EQ@[158; 159) "=" | ||
136 | WHITESPACE@[159; 160) " " | ||
137 | CALL_EXPR@[160; 174) | ||
138 | PATH_EXPR@[160; 168) | ||
139 | PATH@[160; 168) | ||
140 | PATH@[160; 163) | ||
141 | PATH_SEGMENT@[160; 163) | ||
142 | NAME_REF@[160; 163) | ||
143 | IDENT@[160; 163) "Box" | ||
144 | COLONCOLON@[163; 165) "::" | ||
145 | PATH_SEGMENT@[165; 168) | ||
146 | NAME_REF@[165; 168) | ||
147 | IDENT@[165; 168) "new" | ||
148 | ARG_LIST@[168; 174) | ||
149 | L_PAREN@[168; 169) "(" | ||
150 | LITERAL@[169; 173) | ||
151 | INT_NUMBER@[169; 173) "1i32" | ||
152 | R_PAREN@[173; 174) ")" | ||
153 | SEMI@[174; 175) ";" | ||
154 | WHITESPACE@[175; 176) "\n" | ||
155 | R_CURLY@[176; 177) "}" | ||
156 | WHITESPACE@[177; 178) "\n" | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_syntax.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs index e69c81e22..e69c81e22 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_syntax.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.rs | |||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt new file mode 100644 index 000000000..f4eeb7e24 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0132_box_expr.txt | |||
@@ -0,0 +1,31 @@ | |||
1 | SOURCE_FILE@[0; 35) | ||
2 | FN_DEF@[0; 34) | ||
3 | FN_KW@[0; 2) "fn" | ||
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; 34) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 15) "\n " | ||
14 | LET_STMT@[15; 32) | ||
15 | LET_KW@[15; 18) "let" | ||
16 | WHITESPACE@[18; 19) " " | ||
17 | BIND_PAT@[19; 20) | ||
18 | NAME@[19; 20) | ||
19 | IDENT@[19; 20) "x" | ||
20 | WHITESPACE@[20; 21) " " | ||
21 | EQ@[21; 22) "=" | ||
22 | WHITESPACE@[22; 23) " " | ||
23 | BOX_EXPR@[23; 31) | ||
24 | BOX_KW@[23; 26) "box" | ||
25 | WHITESPACE@[26; 27) " " | ||
26 | LITERAL@[27; 31) | ||
27 | INT_NUMBER@[27; 31) "1i32" | ||
28 | SEMI@[31; 32) ";" | ||
29 | WHITESPACE@[32; 33) "\n" | ||
30 | R_CURLY@[33; 34) "}" | ||
31 | WHITESPACE@[34; 35) "\n" | ||