diff options
author | Edwin Cheng <[email protected]> | 2019-04-19 12:33:29 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-04-19 12:33:29 +0100 |
commit | 762819864fd78f2e8904a6bde6181b80895db360 (patch) | |
tree | 1cade2d6eb97a52785a91258cfd3f03c57fba027 /crates/ra_parser | |
parent | 8092b6487f301bf9219c55fc714744fa2616fb9a (diff) |
add block matcher
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 27 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 4 |
2 files changed, 31 insertions, 0 deletions
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) { | |||
99 | expressions::block(p); | 99 | expressions::block(p); |
100 | } | 100 | } |
101 | 101 | ||
102 | // Parse a meta item , which excluded [], e.g : #[ MetaItem ] | ||
103 | pub(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 | |||
102 | pub(crate) fn item(p: &mut Parser) { | 129 | pub(crate) fn item(p: &mut Parser) { |
103 | items::item_or_macro(p, true, items::ItemFlavor::Mod) | 130 | items::item_or_macro(p, true, items::ItemFlavor::Mod) |
104 | } | 131 | } |
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) | |||
98 | parse_from_tokens(token_source, tree_sink, grammar::block); | 98 | parse_from_tokens(token_source, tree_sink, grammar::block); |
99 | } | 99 | } |
100 | 100 | ||
101 | pub 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 | |||
101 | /// Parse given tokens into the given sink as an item | 105 | /// Parse given tokens into the given sink as an item |
102 | pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 106 | pub fn parse_item(token_source: &dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
103 | parse_from_tokens(token_source, tree_sink, grammar::item); | 107 | parse_from_tokens(token_source, tree_sink, grammar::item); |