aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorEvgenii P <[email protected]>2019-08-09 09:38:52 +0100
committerEvgenii P <[email protected]>2019-08-09 09:38:52 +0100
commit957b5ed23a4860fe3c9b80687a801b5d7870fe00 (patch)
tree2aee1c7a0bd9a0160182a7525ef036c2c111f187 /crates
parent2fbec23d9990147e09a3b819c37dc1467a5e95d4 (diff)
Parse tuple struct field initialization
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_parser/src/grammar.rs2
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.txt33
4 files changed, 31 insertions, 8 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index 658034097..00fb1bac9 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -274,7 +274,7 @@ fn name(p: &mut Parser) {
274} 274}
275 275
276fn name_ref(p: &mut Parser) { 276fn name_ref(p: &mut Parser) {
277 if p.at(IDENT) { 277 if p.at(IDENT) || p.at(INT_NUMBER) {
278 let m = p.start(); 278 let m = p.start();
279 p.bump(); 279 p.bump();
280 m.complete(p, NAME_REF); 280 m.complete(p, NAME_REF);
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 3e49e70c7..50c938a23 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -572,6 +572,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
572// S {}; 572// S {};
573// S { x, y: 32, }; 573// S { x, y: 32, };
574// S { x, y: 32, ..Default::default() }; 574// S { x, y: 32, ..Default::default() };
575// TupleStruct { 0: 1 };
575// } 576// }
576pub(crate) fn named_field_list(p: &mut Parser) { 577pub(crate) fn named_field_list(p: &mut Parser) {
577 assert!(p.at(T!['{'])); 578 assert!(p.at(T!['{']));
@@ -583,7 +584,7 @@ pub(crate) fn named_field_list(p: &mut Parser) {
583 // fn main() { 584 // fn main() {
584 // S { #[cfg(test)] field: 1 } 585 // S { #[cfg(test)] field: 1 }
585 // } 586 // }
586 IDENT | T![#] => { 587 IDENT | INT_NUMBER | T![#] => {
587 let m = p.start(); 588 let m = p.start();
588 attributes::outer_attributes(p); 589 attributes::outer_attributes(p);
589 name_ref(p); 590 name_ref(p);
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.rs b/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.rs
index eb711f68a..6285e5549 100644
--- a/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.rs
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.rs
@@ -2,4 +2,5 @@ fn foo() {
2 S {}; 2 S {};
3 S { x, y: 32, }; 3 S { x, y: 32, };
4 S { x, y: 32, ..Default::default() }; 4 S { x, y: 32, ..Default::default() };
5 TupleStruct { 0: 1 };
5} 6}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.txt b/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.txt
index 94d1bfe2e..d06594cae 100644
--- a/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.txt
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0061_struct_lit.txt
@@ -1,5 +1,5 @@
1SOURCE_FILE@[0; 86) 1SOURCE_FILE@[0; 112)
2 FN_DEF@[0; 85) 2 FN_DEF@[0; 111)
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,7 +8,7 @@ SOURCE_FILE@[0; 86)
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@[9; 85) 11 BLOCK@[9; 111)
12 L_CURLY@[9; 10) "{" 12 L_CURLY@[9; 10) "{"
13 WHITESPACE@[10; 15) "\n " 13 WHITESPACE@[10; 15) "\n "
14 EXPR_STMT@[15; 20) 14 EXPR_STMT@[15; 20)
@@ -92,6 +92,27 @@ SOURCE_FILE@[0; 86)
92 WHITESPACE@[80; 81) " " 92 WHITESPACE@[80; 81) " "
93 R_CURLY@[81; 82) "}" 93 R_CURLY@[81; 82) "}"
94 SEMI@[82; 83) ";" 94 SEMI@[82; 83) ";"
95 WHITESPACE@[83; 84) "\n" 95 WHITESPACE@[83; 88) "\n "
96 R_CURLY@[84; 85) "}" 96 EXPR_STMT@[88; 109)
97 WHITESPACE@[85; 86) "\n" 97 STRUCT_LIT@[88; 108)
98 PATH@[88; 99)
99 PATH_SEGMENT@[88; 99)
100 NAME_REF@[88; 99)
101 IDENT@[88; 99) "TupleStruct"
102 WHITESPACE@[99; 100) " "
103 NAMED_FIELD_LIST@[100; 108)
104 L_CURLY@[100; 101) "{"
105 WHITESPACE@[101; 102) " "
106 NAMED_FIELD@[102; 106)
107 NAME_REF@[102; 103)
108 INT_NUMBER@[102; 103) "0"
109 COLON@[103; 104) ":"
110 WHITESPACE@[104; 105) " "
111 LITERAL@[105; 106)
112 INT_NUMBER@[105; 106) "1"
113 WHITESPACE@[106; 107) " "
114 R_CURLY@[107; 108) "}"
115 SEMI@[108; 109) ";"
116 WHITESPACE@[109; 110) "\n"
117 R_CURLY@[110; 111) "}"
118 WHITESPACE@[111; 112) "\n"