From 8092b6487f301bf9219c55fc714744fa2616fb9a Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 18:30:43 +0800 Subject: Add block matcher --- 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 e1762633e..7bae0bc7b 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -95,6 +95,10 @@ pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { expressions::stmt(p, with_semi) } +pub(crate) fn block(p: &mut Parser) { + expressions::block(p); +} + pub(crate) fn item(p: &mut Parser) { items::item_or_macro(p, true, items::ItemFlavor::Mod) } diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 0ea942b6e..1e6a00642 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 a block +pub fn parse_block(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, grammar::block); +} + /// 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); -- cgit v1.2.3 From 762819864fd78f2e8904a6bde6181b80895db360 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 19:33:29 +0800 Subject: add block matcher --- crates/ra_parser/src/grammar.rs | 27 +++++++++++++++++++++++++++ crates/ra_parser/src/lib.rs | 4 ++++ 2 files changed, 31 insertions(+) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 7bae0bc7b..13c50c79c 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -99,6 +99,33 @@ pub(crate) fn block(p: &mut Parser) { expressions::block(p); } +// Parse a meta item , which excluded [], e.g : #[ MetaItem ] +pub(crate) fn meta_item(p: &mut Parser) { + fn is_delimiter(p: &mut Parser) -> bool { + match p.current() { + L_CURLY | L_PAREN | L_BRACK => true, + _ => false, + } + } + + if is_delimiter(p) { + items::token_tree(p); + return; + } + + let m = p.start(); + while !p.at(EOF) { + if is_delimiter(p) { + items::token_tree(p); + break; + } else { + p.bump(); + } + } + + m.complete(p, TOKEN_TREE); +} + pub(crate) fn item(p: &mut Parser) { items::item_or_macro(p, true, items::ItemFlavor::Mod) } diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 1e6a00642..4787b5b9e 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -98,6 +98,10 @@ pub fn parse_block(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) parse_from_tokens(token_source, tree_sink, grammar::block); } +pub fn parse_meta(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, grammar::meta_item); +} + /// 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); -- cgit v1.2.3 From 87ff908135a28115593f8cf895d176aef331347c Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 19 Apr 2019 21:38:26 +0800 Subject: Add vis matcher --- crates/ra_parser/src/grammar.rs | 2 +- crates/ra_parser/src/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 13c50c79c..67eae749d 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -167,7 +167,7 @@ impl BlockLike { } } -fn opt_visibility(p: &mut Parser) -> bool { +pub(crate) fn opt_visibility(p: &mut Parser) -> bool { match p.current() { PUB_KW => { let m = p.start(); diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 4787b5b9e..970d699c0 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs @@ -107,6 +107,13 @@ pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) parse_from_tokens(token_source, tree_sink, grammar::item); } +/// Parse given tokens into the given sink as an visibility qualifier +pub fn parse_vis(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { + parse_from_tokens(token_source, tree_sink, |p| { + grammar::opt_visibility(p); + }); +} + pub fn parse_macro_items(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { parse_from_tokens(token_source, tree_sink, grammar::macro_items); } -- cgit v1.2.3