diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs index 8335c700f8..f01df56bc6 100644 --- a/crates/libsyntax2/src/grammar/expressions/atom.rs +++ b/crates/libsyntax2/src/grammar/expressions/atom.rs @@ -287,7 +287,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker { m.complete(p, MATCH_EXPR) } -fn match_arm_list(p: &mut Parser) { +pub(crate) fn match_arm_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.eat(L_CURLY); diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs index d5ee91ad84..20e0fa3289 100644 --- a/crates/libsyntax2/src/grammar/expressions/mod.rs +++ b/crates/libsyntax2/src/grammar/expressions/mod.rs @@ -2,6 +2,7 @@ mod atom; use super::*; pub(super) use self::atom::{literal, LITERAL_FIRST}; +pub(crate) use self::atom::match_arm_list; const EXPR_FIRST: TokenSet = LHS_FIRST; @@ -419,7 +420,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { // S { x, y: 32, }; // S { x, y: 32, ..Default::default() }; // } -fn named_field_list(p: &mut Parser) { +pub(crate) fn named_field_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index 85d7fe7704..8c19aa1795 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs @@ -5,7 +5,12 @@ mod traits; mod use_item; use super::*; -pub(crate) use self::nominal::named_field_def_list; +pub(crate) use self::{ + expressions::{named_field_list, match_arm_list}, + nominal::{enum_variant_list, named_field_def_list}, + traits::{trait_item_list, impl_item_list}, + use_item::use_tree_list, +}; // test mod_contents // fn foo() {} @@ -223,7 +228,7 @@ fn extern_crate_item(p: &mut Parser) { p.expect(SEMI); } -fn extern_item_list(p: &mut Parser) { +pub(crate) fn extern_item_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); @@ -295,7 +300,7 @@ fn type_def(p: &mut Parser) { p.expect(SEMI); } -fn mod_item(p: &mut Parser) { +pub(crate) fn mod_item(p: &mut Parser) { assert!(p.at(MOD_KW)); p.bump(); @@ -307,7 +312,7 @@ fn mod_item(p: &mut Parser) { } } -fn mod_item_list(p: &mut Parser) { +pub(crate) fn mod_item_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); @@ -343,7 +348,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { flavor } -pub(super) fn token_tree(p: &mut Parser) { +pub(crate) fn token_tree(p: &mut Parser) { let closing_paren_kind = match p.current() { L_CURLY => R_CURLY, L_PAREN => R_PAREN, diff --git a/crates/libsyntax2/src/grammar/items/nominal.rs b/crates/libsyntax2/src/grammar/items/nominal.rs index 3db5b24afd..11c43e371e 100644 --- a/crates/libsyntax2/src/grammar/items/nominal.rs +++ b/crates/libsyntax2/src/grammar/items/nominal.rs @@ -51,7 +51,7 @@ pub(super) fn enum_def(p: &mut Parser) { } } -fn enum_variant_list(p: &mut Parser) { +pub(crate) fn enum_variant_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); diff --git a/crates/libsyntax2/src/grammar/items/traits.rs b/crates/libsyntax2/src/grammar/items/traits.rs index 9d21d4d364..c21cfb1a9b 100644 --- a/crates/libsyntax2/src/grammar/items/traits.rs +++ b/crates/libsyntax2/src/grammar/items/traits.rs @@ -25,7 +25,7 @@ pub(super) fn trait_def(p: &mut Parser) { // fn foo() {} // fn bar(&self); // } -fn trait_item_list(p: &mut Parser) { +pub(crate) fn trait_item_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); @@ -74,7 +74,7 @@ pub(super) fn impl_item(p: &mut Parser) { // fn foo() {} // fn bar(&self) {} // } -fn impl_item_list(p: &mut Parser) { +pub(crate) fn impl_item_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); diff --git a/crates/libsyntax2/src/grammar/items/use_item.rs b/crates/libsyntax2/src/grammar/items/use_item.rs index 2fbf2234af..1ee4349fda 100644 --- a/crates/libsyntax2/src/grammar/items/use_item.rs +++ b/crates/libsyntax2/src/grammar/items/use_item.rs @@ -53,7 +53,7 @@ fn use_tree(p: &mut Parser) { m.complete(p, USE_TREE); } -fn use_tree_list(p: &mut Parser) { +pub(crate) fn use_tree_list(p: &mut Parser) { assert!(p.at(L_CURLY)); let m = p.start(); p.bump(); diff --git a/crates/libsyntax2/src/grammar/mod.rs b/crates/libsyntax2/src/grammar/mod.rs index e19805b9d3..2cb11dc1e3 100644 --- a/crates/libsyntax2/src/grammar/mod.rs +++ b/crates/libsyntax2/src/grammar/mod.rs @@ -37,8 +37,21 @@ use { SyntaxKind::{self, *}, }; pub(crate) use self::{ - expressions::block, - items::named_field_def_list, + expressions::{ + block, + }, + items::{ + enum_variant_list, + extern_item_list, + impl_item_list, + match_arm_list, + mod_item_list, + named_field_def_list, + named_field_list, + token_tree, + trait_item_list, + use_tree_list, + }, }; pub(crate) fn root(p: &mut Parser) { diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index d955c01e72..74e8e73387 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -144,6 +144,21 @@ fn find_reparsable_node(node: SyntaxNodeRef, range: TextRange) -> Option<(Syntax let res = match node.kind() { BLOCK => grammar::block, NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, + NAMED_FIELD_LIST => grammar::named_field_list, + ENUM_VARIANT_LIST => grammar::enum_variant_list, + MATCH_ARM_LIST => grammar::match_arm_list, + USE_TREE_LIST => grammar::use_tree_list, + EXTERN_ITEM_LIST => grammar::extern_item_list, + TOKEN_TREE => grammar::token_tree, + ITEM_LIST => { + let parent = node.parent().unwrap(); + match parent.kind() { + IMPL_ITEM => grammar::impl_item_list, + TRAIT_DEF => grammar::trait_item_list, + MODULE => grammar::mod_item_list, + _ => return None, + } + }, _ => return None, }; Some(res) diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 014faa2c6b..24058efa9d 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -23,21 +23,6 @@ fn lexer_tests() { }) } -#[test] -fn parser_tests() { - dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { - let file = File::parse(text); - dump_tree(file.syntax()) - }) -} - -#[test] -fn parser_fuzz_tests() { - for (_, text) in collect_tests(&["parser/fuzz-failures"]) { - check_fuzz_invariants(&text) - } -} - #[test] fn reparse_test() { fn do_check(before: &str, replace_with: &str) { @@ -73,6 +58,52 @@ fn foo { <|>92<|>; } ", "62"); + do_check(r" +mod foo { + fn <|><|> +} +", "bar"); + do_check(r" +trait Foo { + type <|>Foo<|>; +} +", "Output"); + do_check(r" +impl IntoIterator for Foo { + f<|><|> +} +", "n next("); + do_check(r" +use a::b::{foo,<|>,bar<|>}; + ", "baz"); + do_check(r" +pub enum A { + Foo<|><|> +} +", "\nBar;\n"); + do_check(r" +foo!{a, b<|><|> d} +", ", c[3]"); + do_check(r" +extern { + fn<|>;<|> +} +", " exit(code: c_int)"); +} + +#[test] +fn parser_tests() { + dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { + let file = File::parse(text); + dump_tree(file.syntax()) + }) +} + +#[test] +fn parser_fuzz_tests() { + for (_, text) in collect_tests(&["parser/fuzz-failures"]) { + check_fuzz_invariants(&text) + } }