diff options
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 7 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 84 |
2 files changed, 35 insertions, 56 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 2bcbb4184..d0f0dd4ac 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -61,11 +61,8 @@ pub(crate) mod fragments { | |||
61 | let _ = expressions::expr(p); | 61 | let _ = expressions::expr(p); |
62 | } | 62 | } |
63 | 63 | ||
64 | pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { | 64 | pub(crate) fn stmt(p: &mut Parser) { |
65 | let with_semi = | 65 | expressions::stmt(p, expressions::StmtWithSemi::No) |
66 | if with_semi { expressions::StmtWithSemi::Yes } else { expressions::StmtWithSemi::No }; | ||
67 | |||
68 | expressions::stmt(p, with_semi) | ||
69 | } | 66 | } |
70 | 67 | ||
71 | pub(crate) fn opt_visibility(p: &mut Parser) { | 68 | pub(crate) fn opt_visibility(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index e494fc480..45241e566 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -83,60 +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::fragments::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::fragments::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::fragments::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::fragments::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::fragments::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::fragments::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::fragments::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::fragments::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, grammar::fragments::opt_visibility); | ||
132 | } | ||
133 | |||
134 | pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | ||
135 | parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_items); | ||
136 | } | ||
137 | |||
138 | pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | ||
139 | parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_stmts); | ||
140 | } | 122 | } |
141 | 123 | ||
142 | /// A parsing function for a specific braced-block. | 124 | /// A parsing function for a specific braced-block. |