aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 14:54:34 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-19 14:54:34 +0100
commitd15abaa06fe65a01072c74db55786e97d17365b4 (patch)
tree68024131d628d333ffd4e6dcba453b335bfafbae /crates/ra_parser/src
parent153db2467f691aaf5ff6d87044342ddae4ee9ae6 (diff)
parent1afde29adbb6c9094babe117f7972f7157d16cc1 (diff)
Merge #1168
1168: Add all remaining mbe matchers r=matklad a=edwin0cheng This PR adds following mbe matchers: * block * meta * tt * literal * vis Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r--crates/ra_parser/src/grammar.rs33
-rw-r--r--crates/ra_parser/src/lib.rs16
2 files changed, 48 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index e1762633e..67eae749d 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -95,6 +95,37 @@ pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
95 expressions::stmt(p, with_semi) 95 expressions::stmt(p, with_semi)
96} 96}
97 97
98pub(crate) fn block(p: &mut Parser) {
99 expressions::block(p);
100}
101
102// Parse a meta item , which excluded [], e.g : #[ MetaItem ]
103pub(crate) fn meta_item(p: &mut Parser) {
104 fn is_delimiter(p: &mut Parser) -> bool {
105 match p.current() {
106 L_CURLY | L_PAREN | L_BRACK => true,
107 _ => false,
108 }
109 }
110
111 if is_delimiter(p) {
112 items::token_tree(p);
113 return;
114 }
115
116 let m = p.start();
117 while !p.at(EOF) {
118 if is_delimiter(p) {
119 items::token_tree(p);
120 break;
121 } else {
122 p.bump();
123 }
124 }
125
126 m.complete(p, TOKEN_TREE);
127}
128
98pub(crate) fn item(p: &mut Parser) { 129pub(crate) fn item(p: &mut Parser) {
99 items::item_or_macro(p, true, items::ItemFlavor::Mod) 130 items::item_or_macro(p, true, items::ItemFlavor::Mod)
100} 131}
@@ -136,7 +167,7 @@ impl BlockLike {
136 } 167 }
137} 168}
138 169
139fn opt_visibility(p: &mut Parser) -> bool { 170pub(crate) fn opt_visibility(p: &mut Parser) -> bool {
140 match p.current() { 171 match p.current() {
141 PUB_KW => { 172 PUB_KW => {
142 let m = p.start(); 173 let m = p.start();
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs
index 0ea942b6e..970d699c0 100644
--- a/crates/ra_parser/src/lib.rs
+++ b/crates/ra_parser/src/lib.rs
@@ -93,11 +93,27 @@ pub fn parse_stmt(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink,
93 parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi)); 93 parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi));
94} 94}
95 95
96/// Parse given tokens into the given sink as a block
97pub fn parse_block(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) {
98 parse_from_tokens(token_source, tree_sink, grammar::block);
99}
100
101pub fn parse_meta(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) {
102 parse_from_tokens(token_source, tree_sink, grammar::meta_item);
103}
104
96/// Parse given tokens into the given sink as an item 105/// Parse given tokens into the given sink as an item
97pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { 106pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) {
98 parse_from_tokens(token_source, tree_sink, grammar::item); 107 parse_from_tokens(token_source, tree_sink, grammar::item);
99} 108}
100 109
110/// Parse given tokens into the given sink as an visibility qualifier
111pub fn parse_vis(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) {
112 parse_from_tokens(token_source, tree_sink, |p| {
113 grammar::opt_visibility(p);
114 });
115}
116
101pub fn parse_macro_items(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { 117pub fn parse_macro_items(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) {
102 parse_from_tokens(token_source, tree_sink, grammar::macro_items); 118 parse_from_tokens(token_source, tree_sink, grammar::macro_items);
103} 119}