From e944fd059de93f305d6a8c40cfac5ebe84548771 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 18 Apr 2019 10:21:36 +0800 Subject: Add `item` matcher in mbe --- crates/ra_parser/src/grammar.rs | 4 ++++ crates/ra_parser/src/lib.rs | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 2c2f785d0..f8ed1299a 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -69,6 +69,10 @@ pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { expressions::stmt(p, with_semi) } +pub(crate) fn item(p: &mut Parser) { + items::item_or_macro(p, true, items::ItemFlavor::Mod) +} + pub(crate) fn reparser( node: SyntaxKind, first_child: Option, diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 9133c1b8a..11b5b9a75 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -93,6 +93,11 @@ pub fn parse_stmt(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink, parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi)); } +/// Parse given tokens into the given sink as an item +pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, grammar::item); +} + /// A parsing function for a specific braced-block. pub struct Reparser(fn(&mut parser::Parser)); -- cgit v1.2.3