diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-02 16:58:47 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-02 16:58:47 +0100 |
commit | 4417a97bc519d8cf658dbd2d09e1d34c8b8f1f23 (patch) | |
tree | f6ab78e03a559cde48ff7525cccce6b144da862d /crates/ra_parser/src/lib.rs | |
parent | f39f72db57a78b7f92f99377be0e05ec3db6dc98 (diff) | |
parent | c89abd42621daff2d652566be4e9e4789599268c (diff) |
Merge #1749
1749: simplify r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/lib.rs')
-rw-r--r-- | crates/ra_parser/src/lib.rs | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 3d88be642..45241e566 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -83,62 +83,42 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | |||
83 | parse_from_tokens(token_source, tree_sink, grammar::root); | 83 | parse_from_tokens(token_source, tree_sink, grammar::root); |
84 | } | 84 | } |
85 | 85 | ||
86 | /// Parse given tokens into the given sink as a path | 86 | pub enum FragmentKind { |
87 | pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 87 | Path, |
88 | parse_from_tokens(token_source, tree_sink, grammar::path); | 88 | Expr, |
89 | } | 89 | Statement, |
90 | 90 | Type, | |
91 | /// Parse given tokens into the given sink as a expression | 91 | Pattern, |
92 | pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 92 | Item, |
93 | parse_from_tokens(token_source, tree_sink, grammar::expr); | 93 | Block, |
94 | } | 94 | Visibility, |
95 | 95 | MetaItem, | |
96 | /// Parse given tokens into the given sink as a ty | 96 | |
97 | pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 97 | // These kinds are used when parsing the result of expansion |
98 | parse_from_tokens(token_source, tree_sink, grammar::type_); | 98 | // FIXME: use separate fragment kinds for macro inputs and outputs? |
99 | } | 99 | Items, |
100 | 100 | Statements, | |
101 | /// Parse given tokens into the given sink as a pattern | 101 | } |
102 | pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 102 | |
103 | parse_from_tokens(token_source, tree_sink, grammar::pattern); | 103 | pub fn parse_fragment( |
104 | } | ||
105 | |||
106 | /// Parse given tokens into the given sink as a statement | ||
107 | pub fn parse_stmt( | ||
108 | token_source: &mut dyn TokenSource, | 104 | token_source: &mut dyn TokenSource, |
109 | tree_sink: &mut dyn TreeSink, | 105 | tree_sink: &mut dyn TreeSink, |
110 | with_semi: bool, | 106 | fragment_kind: FragmentKind, |
111 | ) { | 107 | ) { |
112 | parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi)); | 108 | let parser: fn(&'_ mut parser::Parser) = match fragment_kind { |
113 | } | 109 | FragmentKind::Path => grammar::fragments::path, |
114 | 110 | FragmentKind::Expr => grammar::fragments::expr, | |
115 | /// Parse given tokens into the given sink as a block | 111 | FragmentKind::Type => grammar::fragments::type_, |
116 | pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 112 | FragmentKind::Pattern => grammar::fragments::pattern, |
117 | parse_from_tokens(token_source, tree_sink, grammar::block); | 113 | FragmentKind::Item => grammar::fragments::item, |
118 | } | 114 | FragmentKind::Block => grammar::fragments::block, |
119 | 115 | FragmentKind::Visibility => grammar::fragments::opt_visibility, | |
120 | pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 116 | FragmentKind::MetaItem => grammar::fragments::meta_item, |
121 | parse_from_tokens(token_source, tree_sink, grammar::meta_item); | 117 | FragmentKind::Statement => grammar::fragments::stmt, |
122 | } | 118 | FragmentKind::Items => grammar::fragments::macro_items, |
123 | 119 | FragmentKind::Statements => grammar::fragments::macro_stmts, | |
124 | /// Parse given tokens into the given sink as an item | 120 | }; |
125 | pub fn parse_item(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 121 | parse_from_tokens(token_source, tree_sink, parser) |
126 | parse_from_tokens(token_source, tree_sink, grammar::item); | ||
127 | } | ||
128 | |||
129 | /// Parse given tokens into the given sink as an visibility qualifier | ||
130 | pub fn parse_vis(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | ||
131 | parse_from_tokens(token_source, tree_sink, |p| { | ||
132 | grammar::opt_visibility(p); | ||
133 | }); | ||
134 | } | ||
135 | |||
136 | pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | ||
137 | parse_from_tokens(token_source, tree_sink, grammar::macro_items); | ||
138 | } | ||
139 | |||
140 | pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | ||
141 | parse_from_tokens(token_source, tree_sink, grammar::macro_stmts); | ||
142 | } | 122 | } |
143 | 123 | ||
144 | /// A parsing function for a specific braced-block. | 124 | /// A parsing function for a specific braced-block. |