Unnamed repository; edit this file 'description' to name the repository.
Merge #10265
10265: internal: parser cleanups r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
39 files changed, 543 insertions, 496 deletions
diff --git a/crates/parser/src/grammar/attributes.rs b/crates/parser/src/grammar/attributes.rs index a44c5e4841..80d7b09b3e 100644 --- a/crates/parser/src/grammar/attributes.rs +++ b/crates/parser/src/grammar/attributes.rs @@ -12,31 +12,13 @@ pub(super) fn outer_attrs(p: &mut Parser) { } } -pub(super) fn meta(p: &mut Parser) { - let meta = p.start(); - paths::use_path(p); - - match p.current() { - T![=] => { - p.bump(T![=]); - if expressions::expr(p).0.is_none() { - p.error("expected expression"); - } - } - T!['('] | T!['['] | T!['{'] => items::token_tree(p), - _ => {} - } - - meta.complete(p, META); -} - fn attr(p: &mut Parser, inner: bool) { - let attr = p.start(); assert!(p.at(T![#])); + + let attr = p.start(); p.bump(T![#]); if inner { - assert!(p.at(T![!])); p.bump(T![!]); } @@ -51,3 +33,21 @@ fn attr(p: &mut Parser, inner: bool) { } attr.complete(p, ATTR); } + +pub(super) fn meta(p: &mut Parser) { + let meta = p.start(); + paths::use_path(p); + + match p.current() { + T![=] => { + p.bump(T![=]); + if expressions::expr(p).0.is_none() { + p.error("expected expression"); + } + } + T!['('] | T!['['] | T!['{'] => items::token_tree(p), + _ => {} + } + + meta.complete(p, META); +} diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index 001be099e6..12e62cddbc 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -71,7 +71,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) { // test block_items // fn a() { fn b() {} } - let m = match items::maybe_item(p, m) { + let m = match items::opt_item(p, m) { Ok(()) => return, Err(m) => m, }; diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 3421078bba..e0b740a815 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -44,7 +44,8 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { let m = p.start(); attributes::outer_attrs(p); - let m = match maybe_item(p, m) { + + let m = match opt_item(p, m) { Ok(()) => { if p.at(T![;]) { p.err_and_bump( @@ -56,6 +57,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { } Err(m) => m, }; + if paths::is_use_path_start(p) { match macro_call(p) { BlockLike::Block => (), @@ -64,30 +66,30 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { } } m.complete(p, MACRO_CALL); - } else { - m.abandon(p); - if p.at(T!['{']) { - error_block(p, "expected an item"); - } else if p.at(T!['}']) && !stop_on_r_curly { + return; + } + + m.abandon(p); + match p.current() { + T!['{'] => error_block(p, "expected an item"), + T!['}'] if !stop_on_r_curly => { let e = p.start(); p.error("unmatched `}`"); p.bump(T!['}']); e.complete(p, ERROR); - } else if !p.at(EOF) && !p.at(T!['}']) { - p.err_and_bump("expected an item"); - } else { - p.error("expected an item"); } + EOF | T!['}'] => p.error("expected an item"), + _ => p.err_and_bump("expected an item"), } } /// Try to parse an item, completing `m` in case of success. -pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { +pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { // test_err pub_expr // fn foo() { pub 92; } let has_visibility = opt_visibility(p); - let m = match items_without_modifiers(p, m) { + let m = match opt_item_without_modifiers(p, m) { Ok(()) => return Ok(()), Err(m) => m, }; @@ -235,48 +237,20 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { Ok(()) } -fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { +fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { let la = p.nth(1); match p.current() { - // test extern_crate - // extern crate foo; T![extern] if la == T![crate] => extern_crate(p, m), T![use] => use_item::use_(p, m), T![mod] => mod_item(p, m), T![type] => type_alias(p, m), - - T![struct] => { - // test struct_items - // struct Foo; - // struct Foo {} - // struct Foo(); - // struct Foo(String, usize); - // struct Foo { - // a: i32, - // b: f32, - // } - adt::strukt(p, m); - } + T![struct] => adt::strukt(p, m), T![enum] => adt::enum_(p, m), - IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { - // test union_items - // union Foo {} - // union Foo { - // a: i32, - // b: f32, - // } - adt::union(p, m); - } + IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => adt::union(p, m), - // test pub_macro_def - // pub macro m($:ident) {} - T![macro] => { - macro_def(p, m); - } - IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => { - macro_rules(p, m); - } + T![macro] => macro_def(p, m), + IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), T![static] => consts::static_(p, m), @@ -286,14 +260,15 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { Ok(()) } +// test extern_crate +// extern crate foo; fn extern_crate(p: &mut Parser, m: Marker) { - assert!(p.at(T![extern])); p.bump(T![extern]); - - assert!(p.at(T![crate])); p.bump(T![crate]); if p.at(T![self]) { + // test extern_crate_self + // extern crate self; let m = p.start(); p.bump(T![self]); m.complete(p, NAME_REF); @@ -301,11 +276,62 @@ fn extern_crate(p: &mut Parser, m: Marker) { name_ref(p); } + // test extern_crate_rename + // extern crate foo as bar; opt_rename(p); p.expect(T![;]); m.complete(p, EXTERN_CRATE); } +// test mod_item +// mod a; +pub(crate) fn mod_item(p: &mut Parser, m: Marker) { + p.bump(T![mod]); + name(p); + if p.at(T!['{']) { + // test mod_item_curly + // mod b { } + item_list(p); + } else if !p.eat(T![;]) { + p.error("expected `;` or `{`"); + } + m.complete(p, MODULE); +} + +// test type_alias +// type Foo = Bar; +fn type_alias(p: &mut Parser, m: Marker) { + p.bump(T![type]); + + name(p); + + // test type_item_type_params + // type Result<T> = (); + type_params::opt_generic_param_list(p); + + if p.at(T![:]) { + type_params::bounds(p); + } + + // test type_item_where_clause + // type Foo where Foo: Copy = (); + type_params::opt_where_clause(p); + if p.eat(T![=]) { + types::type_(p); + } + p.expect(T![;]); + m.complete(p, TYPE_ALIAS); +} + +pub(crate) fn item_list(p: &mut Parser) { + assert!(p.at(T!['{'])); + let m = p.start(); + p.bump(T!['{']); + mod_contents(p, true); + p.expect(T!['}']); + m.complete(p, ITEM_LIST); +} + pub(crate) fn extern_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); @@ -347,54 +373,6 @@ fn fn_(p: &mut Parser) { } } -// test type_item -// type Foo = Bar; -fn type_alias(p: &mut Parser, m: Marker) { - assert!(p.at(T![type])); - p.bump(T![type]); - - name(p); - - // test type_item_type_params - // type Result<T> = (); - type_params::opt_generic_param_list(p); - - if p.at(T![:]) { - type_params::bounds(p); - } - - // test type_item_where_clause - // type Foo where Foo: Copy = (); - type_params::opt_where_clause(p); - if p.eat(T![=]) { - types::type_(p); - } - p.expect(T![;]); - m.complete(p, TYPE_ALIAS); -} - -pub(crate) fn mod_item(p: &mut Parser, m: Marker) { - assert!(p.at(T![mod])); - p.bump(T![mod]); - - name(p); - if p.at(T!['{']) { - item_list(p); - } else if !p.eat(T![;]) { - p.error("expected `;` or `{`"); - } - m.complete(p, MODULE); -} - -pub(crate) fn item_list(p: &mut Parser) { - assert!(p.at(T!['{'])); - let m = p.start(); - p.bump(T!['{']); - mod_contents(p, true); - p.expect(T!['}']); - m.complete(p, ITEM_LIST); -} - fn macro_rules(p: &mut Parser, m: Marker) { assert!(p.at_contextual_kw("macro_rules")); p.bump_remap(T![macro_rules]); @@ -429,16 +407,15 @@ fn macro_rules(p: &mut Parser, m: Marker) { } // test macro_def -// macro m { ($i:ident) => {} } // macro m($i:ident) {} fn macro_def(p: &mut Parser, m: Marker) { p.expect(T![macro]); name_r(p, ITEM_RECOVERY_SET); if p.at(T!['{']) { + // test macro_def_curly + // macro m { ($i:ident) => {} } token_tree(p); - } else if !p.at(T!['(']) { - p.error("unmatched `(`"); - } else { + } else if p.at(T!['(']) { let m = p.start(); token_tree(p); match p.current() { @@ -446,6 +423,8 @@ fn macro_def(p: &mut Parser, m: Marker) { _ => p.error("expected `{`, `[`, `(`"), } m.complete(p, TOKEN_TREE); + } else { + p.error("unmatched `(`"); } m.complete(p, MACRO_DEF); diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs index 386d3806c3..eaf16bc1a1 100644 --- a/crates/parser/src/grammar/items/adt.rs +++ b/crates/parser/src/grammar/items/adt.rs @@ -1,18 +1,21 @@ use super::*; +// test struct_item +// struct S {} pub(super) fn strukt(p: &mut Parser, m: Marker) { - assert!(p.at(T![struct])); p.bump(T![struct]); - struct_or_union(p, m, T![struct], STRUCT); + struct_or_union(p, m, true); } +// test union_item +// struct U { i: i32, f: f32 } pub(super) fn union(p: &mut Parser, m: Marker) { assert!(p.at_contextual_kw("union")); p.bump_remap(T![union]); - struct_or_union(p, m, T![union], UNION); + struct_or_union(p, m, false); } -fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { +fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { name_r(p, ITEM_RECOVERY_SET); type_params::opt_generic_param_list(p); match p.current() { @@ -29,26 +32,24 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { } } } - T![;] if kw == T![struct] => { + T!['{'] => record_field_list(p), + // test unit_struct + // struct S; + T![;] if is_struct => { p.bump(T![;]); } - T!['{'] => record_field_list(p), - T!['('] if kw == T![struct] => { + // test tuple_struct + // struct S(String, usize); + T!['('] if is_struct => { tuple_field_list(p); // test tuple_struct_where - // struct Test<T>(T) where T: Clone; - // struct Test<T>(T); + // struct S<T>(T) where T: Clone; type_params::opt_where_clause(p); p.expect(T![;]); } - _ if kw == T![struct] => { - p.error("expected `;`, `{`, or `(`"); - } - _ => { - p.error("expected `{`"); - } + _ => p.error(if is_struct { "expected `;`, `{`, or `(`" } else { "expected `{`" }), } - m.complete(p, def); + m.complete(p, if is_struct { STRUCT } else { UNION }); } pub(super) fn enum_(p: &mut Parser, m: Marker) { @@ -102,6 +103,8 @@ pub(crate) fn variant_list(p: &mut Parser) { m.complete(p, VARIANT_LIST); } +// test record_field_list +// struct S { a: i32, b: f32 } pub(crate) fn record_field_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); diff --git a/crates/syntax/test_data/parser/inline/ok/0068_union_items.rast b/crates/syntax/test_data/parser/inline/ok/0068_union_items.rast deleted file mode 100644 index 6589e47951..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0068_union_items.rast +++ /dev/null @@ -1,46 +0,0 @@ - [email protected] "union" - [email protected] " " - [email protected] "Foo" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "union" - [email protected] " " - [email protected] "Foo" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "a" - [email protected] ":" - [email protected] " " - [email protected] "i32" - [email protected] "," - [email protected] "\n " - [email protected] "b" - [email protected] ":" - [email protected] " " - [email protected] "f32" - [email protected] "," - [email protected] "\n" - [email protected] "}" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0068_union_items.rs b/crates/syntax/test_data/parser/inline/ok/0068_union_items.rs deleted file mode 100644 index b7dd610d80..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0068_union_items.rs +++ /dev/null @@ -1,5 +0,0 @@ -union Foo {} -union Foo { - a: i32, - b: f32, -} diff --git a/crates/syntax/test_data/parser/inline/ok/0078_type_item.rast b/crates/syntax/test_data/parser/inline/ok/0078_type_alias.rast index 2befc8388e..2befc8388e 100644 --- a/crates/syntax/test_data/parser/inline/ok/0078_type_item.rast +++ b/crates/syntax/test_data/parser/inline/ok/0078_type_alias.rast diff --git a/crates/syntax/test_data/parser/inline/ok/0078_type_item.rs b/crates/syntax/test_data/parser/inline/ok/0078_type_alias.rs index 04c0344fa3..04c0344fa3 100644 --- a/crates/syntax/test_data/parser/inline/ok/0078_type_item.rs +++ b/crates/syntax/test_data/parser/inline/ok/0078_type_alias.rs diff --git a/crates/syntax/test_data/parser/inline/ok/0083_struct_items.rs b/crates/syntax/test_data/parser/inline/ok/0083_struct_items.rs deleted file mode 100644 index 693e3f3ee1..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0083_struct_items.rs +++ /dev/null @@ -1,8 +0,0 @@ -struct Foo; -struct Foo {} -struct Foo(); -struct Foo(String, usize); -struct Foo { - a: i32, - b: f32, -} diff --git a/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast b/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast index 0e1594dc48..3196111363 100644 --- a/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast +++ b/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast @@ -1,64 +1,42 @@ [email protected] "struct" - [email protected] "Test" - [email protected] "<" - [email protected] "T" - [email protected] ">" - [email protected] "(" - [email protected] "T" - [email protected] ")" - [email protected] " " - [email protected] "where" - [email protected] " " - [email protected] "T" - [email protected] ":" - [email protected] " " - [email protected] "Clone" - [email protected] ";" - [email protected] "\n" - [email protected] "struct" - [email protected] " " - [email protected] "Test" - [email protected] "<" - [email protected] "T" - [email protected] ">" - [email protected] "(" - [email protected] "T" - [email protected] ")" - [email protected] ";" - [email protected] "\n" + [email protected] "S" + [email protected] "<" + [email protected] "T" + [email protected] ">" + [email protected] "(" + [email protected] "T" + [email protected] ")" + [email protected] " " + [email protected] "where" + [email protected] " " + [email protected] "T" + [email protected] ":" + [email protected] " " + [email protected] "Clone" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rs b/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rs index ddd59016dc..a602e00182 100644 --- a/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rs +++ b/crates/syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rs @@ -1,2 +1 @@ -struct Test<T>(T) where T: Clone; -struct Test<T>(T); +struct S<T>(T) where T: Clone; diff --git a/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rast b/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rast index 6655aeab13..4d7b78d5ca 100644 --- a/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rast +++ b/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rast @@ -1,45 +1,19 @@ [email protected] "macro" - [email protected] " " - [email protected] "{" - [email protected] " " - [email protected] "(" - [email protected] "$" - [email protected] "i" - [email protected] ":" - [email protected] "ident" - [email protected] ")" - [email protected] " " - [email protected] "=" - [email protected] ">" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] " " - [email protected] "}" - [email protected] "\n" - [email protected] "macro" - [email protected] " " - [email protected] "m" - [email protected] "(" - [email protected] "$" - [email protected] "i" - [email protected] ":" - [email protected] "ident" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" + [email protected] "(" + [email protected] "$" + [email protected] "i" + [email protected] ":" + [email protected] "ident" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rs b/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rs index 319a4e2aad..a014ae5464 100644 --- a/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rs +++ b/crates/syntax/test_data/parser/inline/ok/0147_macro_def.rs @@ -1,2 +1 @@ -macro m { ($i:ident) => {} } macro m($i:ident) {} diff --git a/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rast b/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rast deleted file mode 100644 index 1c527f60b9..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rast +++ /dev/null @@ -1,21 +0,0 @@ - [email protected] "pub" - [email protected] " " - [email protected] "macro" - [email protected] " " - [email protected] "m" - [email protected] "(" - [email protected] "$" - [email protected] ":" - [email protected] "ident" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rs b/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rs deleted file mode 100644 index 3b2be597fd..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0148_pub_macro_def.rs +++ /dev/null @@ -1 +0,0 @@ -pub macro m($:ident) {} diff --git a/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rast b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rast new file mode 100644 index 0000000000..87516e9fc4 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rast @@ -0,0 +1,16 @@ + [email protected] "extern" + [email protected] " " + [email protected] "crate" + [email protected] " " + [email protected] "foo" + [email protected] " " + [email protected] "as" + [email protected] " " + [email protected] "bar" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rs b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rs new file mode 100644 index 0000000000..fc76e17dda --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_rename.rs @@ -0,0 +1 @@ +extern crate foo as bar; diff --git a/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rast b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rast new file mode 100644 index 0000000000..26b4c0f195 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rast @@ -0,0 +1,10 @@ + [email protected] "extern" + [email protected] " " + [email protected] "crate" + [email protected] " " + [email protected] "self" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rs b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rs new file mode 100644 index 0000000000..c969ed1093 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0168_extern_crate_self.rs @@ -0,0 +1 @@ +extern crate self; diff --git a/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rast b/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rast new file mode 100644 index 0000000000..423eacf92e --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rast @@ -0,0 +1,8 @@ + [email protected] "mod" + [email protected] " " + [email protected] "a" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rs b/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rs new file mode 100644 index 0000000000..f21af614da --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0169_mod_item.rs @@ -0,0 +1 @@ +mod a; diff --git a/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rast b/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rast new file mode 100644 index 0000000000..33ad9c44f5 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rast @@ -0,0 +1,12 @@ + [email protected] "mod" + [email protected] " " + [email protected] "b" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rs b/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rs new file mode 100644 index 0000000000..16b1b43e87 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0170_mod_item_curly.rs @@ -0,0 +1 @@ +mod b { } diff --git a/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rast b/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rast new file mode 100644 index 0000000000..935fd6e07b --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rast @@ -0,0 +1,25 @@ + [email protected] "struct" + [email protected] " " + [email protected] "S" + [email protected] "(" + [email protected] "String" + [email protected] "," + [email protected] " " + [email protected] "usize" + [email protected] ")" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rs b/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rs new file mode 100644 index 0000000000..b4e05717ed --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0170_tuple_struct.rs @@ -0,0 +1 @@ +struct S(String, usize); diff --git a/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rast b/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rast new file mode 100644 index 0000000000..3134482f0d --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rast @@ -0,0 +1,11 @@ + [email protected] "struct" + [email protected] " " + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rs b/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rs new file mode 100644 index 0000000000..5f1a34f49b --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0171_struct_item.rs @@ -0,0 +1 @@ +struct S {} diff --git a/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rast b/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rast new file mode 100644 index 0000000000..ce1135c597 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rast @@ -0,0 +1,35 @@ + [email protected] "struct" + [email protected] " " + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "a" + [email protected] ":" + [email protected] " " + [email protected] "i32" + [email protected] "," + [email protected] " " + [email protected] "b" + [email protected] ":" + [email protected] " " + [email protected] "f32" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rs b/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rs new file mode 100644 index 0000000000..a3bd7787db --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0172_record_field_list.rs @@ -0,0 +1 @@ +struct S { a: i32, b: f32 } diff --git a/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rast b/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rast new file mode 100644 index 0000000000..3ec00bf55a --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rast @@ -0,0 +1,27 @@ + [email protected] "macro" + [email protected] " " + [email protected] "m" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "(" + [email protected] "$" + [email protected] "i" + [email protected] ":" + [email protected] "ident" + [email protected] ")" + [email protected] " " + [email protected] "=" + [email protected] ">" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rs b/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rs new file mode 100644 index 0000000000..5ed0c777dc --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_macro_def_curly.rs @@ -0,0 +1 @@ +macro m { ($i:ident) => {} } diff --git a/crates/syntax/test_data/parser/inline/ok/0173_union_item.rast b/crates/syntax/test_data/parser/inline/ok/0173_union_item.rast new file mode 100644 index 0000000000..5d5c0d69bc --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_union_item.rast @@ -0,0 +1,35 @@ + [email protected] "struct" + [email protected] " " + [email protected] "U" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "i" + [email protected] ":" + [email protected] " " + [email protected] "i32" + [email protected] "," + [email protected] " " + [email protected] "f" + [email protected] ":" + [email protected] " " + [email protected] "f32" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0173_union_item.rs b/crates/syntax/test_data/parser/inline/ok/0173_union_item.rs new file mode 100644 index 0000000000..5edf50de3b --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_union_item.rs @@ -0,0 +1 @@ +struct U { i: i32, f: f32 } diff --git a/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rast b/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rast new file mode 100644 index 0000000000..b20235889f --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rast @@ -0,0 +1,8 @@ + [email protected] "struct" + [email protected] " " + [email protected] "S" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rs b/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rs new file mode 100644 index 0000000000..28377c2760 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_unit_struct.rs @@ -0,0 +1 @@ +struct S; diff --git a/crates/syntax/test_data/parser/ok/0008_mod_item.rast b/crates/syntax/test_data/parser/ok/0008_mod_item.rast index 8b1e0a52da..712e153462 100644 --- a/crates/syntax/test_data/parser/ok/0008_mod_item.rast +++ b/crates/syntax/test_data/parser/ok/0008_mod_item.rast @@ -1,93 +1,76 @@ [email protected] "mod" - [email protected] "a" - [email protected] ";" - [email protected] "\n\n" - [email protected] "mod" - [email protected] " " - [email protected] "b" - [email protected] " " - [email protected] "{" - [email protected] "\n" - [email protected] "}" - [email protected] "\n\n" - [email protected] "mod" - [email protected] " " - [email protected] "c" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "fn" - [email protected] " " - [email protected] "foo" - [email protected] "(" - [email protected] ")" + [email protected] "c" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "fn" + [email protected] " " + [email protected] "foo" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "}" + [email protected] "\n " + [email protected] "struct" - [email protected] "{" - [email protected] "\n " - [email protected] "}" - [email protected] "\n " - [email protected] "struct" - [email protected] " " - [email protected] "S" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "}" - [email protected] "\n\n" - [email protected] "mod" - [email protected] " " - [email protected] "d" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "#" - [email protected] "!" - [email protected] "[" - [email protected] "attr" - [email protected] "]" - [email protected] "\n " - [email protected] "mod" - [email protected] " " - [email protected] "e" - [email protected] ";" - [email protected] "\n " - [email protected] "mod" - [email protected] " " - [email protected] "f" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "}" - [email protected] "\n" - [email protected] "}" + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" + [email protected] "}" + [email protected] "\n\n" + [email protected] "mod" + [email protected] " " + [email protected] "d" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "#" + [email protected] "!" + [email protected] "[" + [email protected] "attr" + [email protected] "]" + [email protected] "\n " + [email protected] "mod" + [email protected] " " + [email protected] "e" + [email protected] ";" + [email protected] "\n " + [email protected] "mod" + [email protected] " " + [email protected] "f" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "}" + [email protected] "\n" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/ok/0008_mod_item.rs b/crates/syntax/test_data/parser/ok/0008_mod_item.rs index d22993bc15..4ff0d9795c 100644 --- a/crates/syntax/test_data/parser/ok/0008_mod_item.rs +++ b/crates/syntax/test_data/parser/ok/0008_mod_item.rs @@ -1,8 +1,3 @@ -mod a; - -mod b { -} - mod c { fn foo() { } @@ -14,4 +9,4 @@ mod d { mod e; mod f { } -}
\ No newline at end of file +} diff --git a/crates/syntax/test_data/parser/ok/0012_visibility.rast b/crates/syntax/test_data/parser/ok/0012_visibility.rast index c5dbfb702a..79dc9001a2 100644 --- a/crates/syntax/test_data/parser/ok/0012_visibility.rast +++ b/crates/syntax/test_data/parser/ok/0012_visibility.rast @@ -1,4 +1,4 @@ [email protected] "fn" @@ -28,81 +28,101 @@ [email protected] [email protected] "\n" [email protected] "pub" - [email protected] "(" - [email protected] "crate" - [email protected] ")" - [email protected] " " - [email protected] "fn" - [email protected] " " - [email protected] "c" - [email protected] "(" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "pub" - [email protected] "(" - [email protected] "super" - [email protected] ")" - [email protected] " " - [email protected] "fn" + [email protected] " " + [email protected] "macro" + [email protected] " " + [email protected] "m" + [email protected] "(" + [email protected] "$" + [email protected] ":" + [email protected] "ident" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" + [email protected] "pub" + [email protected] "(" + [email protected] "crate" + [email protected] ")" - [email protected] "d" - [email protected] "(" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "pub" - [email protected] "(" - [email protected] "in" - [email protected] " " - [email protected] "foo" - [email protected] "::" - [email protected] "bar" - [email protected] "::" - [email protected] "baz" - [email protected] ")" - [email protected] " " - [email protected] "fn" - [email protected] " " - [email protected] "e" - [email protected] "(" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" + [email protected] "fn" + [email protected] " " + [email protected] "c" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" + [email protected] "pub" + [email protected] "(" + [email protected] "super" + [email protected] ")" + [email protected] " " + [email protected] "fn" + [email protected] " " + [email protected] "d" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" + [email protected] "pub" + [email protected] "(" + [email protected] "in" + [email protected] " " + [email protected] "foo" + [email protected] "::" + [email protected] "bar" + [email protected] "::" + [email protected] "baz" + [email protected] ")" + [email protected] " " + [email protected] "fn" + [email protected] " " + [email protected] "e" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/ok/0012_visibility.rs b/crates/syntax/test_data/parser/ok/0012_visibility.rs index 75b1db1213..129d486fae 100644 --- a/crates/syntax/test_data/parser/ok/0012_visibility.rs +++ b/crates/syntax/test_data/parser/ok/0012_visibility.rs @@ -1,5 +1,6 @@ fn a() {} pub fn b() {} +pub macro m($:ident) {} pub(crate) fn c() {} pub(super) fn d() {} pub(in foo::bar::baz) fn e() {} |