mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
simplify
This commit is contained in:
parent
32bebfaf0e
commit
c89abd4262
6 changed files with 115 additions and 212 deletions
|
@ -61,11 +61,8 @@ pub(crate) mod fragments {
|
|||
let _ = expressions::expr(p);
|
||||
}
|
||||
|
||||
pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
|
||||
let with_semi =
|
||||
if with_semi { expressions::StmtWithSemi::Yes } else { expressions::StmtWithSemi::No };
|
||||
|
||||
expressions::stmt(p, with_semi)
|
||||
pub(crate) fn stmt(p: &mut Parser) {
|
||||
expressions::stmt(p, expressions::StmtWithSemi::No)
|
||||
}
|
||||
|
||||
pub(crate) fn opt_visibility(p: &mut Parser) {
|
||||
|
|
|
@ -83,60 +83,42 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
|||
parse_from_tokens(token_source, tree_sink, grammar::root);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a path
|
||||
pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::path);
|
||||
pub enum FragmentKind {
|
||||
Path,
|
||||
Expr,
|
||||
Statement,
|
||||
Type,
|
||||
Pattern,
|
||||
Item,
|
||||
Block,
|
||||
Visibility,
|
||||
MetaItem,
|
||||
|
||||
// These kinds are used when parsing the result of expansion
|
||||
// FIXME: use separate fragment kinds for macro inputs and outputs?
|
||||
Items,
|
||||
Statements,
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a expression
|
||||
pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::expr);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a ty
|
||||
pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::type_);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a pattern
|
||||
pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::pattern);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a statement
|
||||
pub fn parse_stmt(
|
||||
pub fn parse_fragment(
|
||||
token_source: &mut dyn TokenSource,
|
||||
tree_sink: &mut dyn TreeSink,
|
||||
with_semi: bool,
|
||||
fragment_kind: FragmentKind,
|
||||
) {
|
||||
parse_from_tokens(token_source, tree_sink, |p| grammar::fragments::stmt(p, with_semi));
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as a block
|
||||
pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::block);
|
||||
}
|
||||
|
||||
pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::meta_item);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as an item
|
||||
pub fn parse_item(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::item);
|
||||
}
|
||||
|
||||
/// Parse given tokens into the given sink as an visibility qualifier
|
||||
pub fn parse_vis(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::opt_visibility);
|
||||
}
|
||||
|
||||
pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_items);
|
||||
}
|
||||
|
||||
pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||
parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_stmts);
|
||||
let parser: fn(&'_ mut parser::Parser) = match fragment_kind {
|
||||
FragmentKind::Path => grammar::fragments::path,
|
||||
FragmentKind::Expr => grammar::fragments::expr,
|
||||
FragmentKind::Type => grammar::fragments::type_,
|
||||
FragmentKind::Pattern => grammar::fragments::pattern,
|
||||
FragmentKind::Item => grammar::fragments::item,
|
||||
FragmentKind::Block => grammar::fragments::block,
|
||||
FragmentKind::Visibility => grammar::fragments::opt_visibility,
|
||||
FragmentKind::MetaItem => grammar::fragments::meta_item,
|
||||
FragmentKind::Statement => grammar::fragments::stmt,
|
||||
FragmentKind::Items => grammar::fragments::macro_items,
|
||||
FragmentKind::Statements => grammar::fragments::macro_stmts,
|
||||
};
|
||||
parse_from_tokens(token_source, tree_sink, parser)
|
||||
}
|
||||
|
||||
/// A parsing function for a specific braced-block.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue