mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
cleanup
This commit is contained in:
parent
f39f72db57
commit
32bebfaf0e
5 changed files with 90 additions and 94 deletions
|
@ -49,41 +49,16 @@ pub(crate) fn root(p: &mut Parser) {
|
||||||
m.complete(p, SOURCE_FILE);
|
m.complete(p, SOURCE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn macro_items(p: &mut Parser) {
|
/// Various pieces of syntax that can be parsed by macros by example
|
||||||
let m = p.start();
|
pub(crate) mod fragments {
|
||||||
items::mod_contents(p, false);
|
use super::*;
|
||||||
m.complete(p, MACRO_ITEMS);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn macro_stmts(p: &mut Parser) {
|
pub(crate) use super::{
|
||||||
let m = p.start();
|
expressions::block, paths::type_path as path, patterns::pattern, types::type_,
|
||||||
|
};
|
||||||
while !p.at(EOF) {
|
|
||||||
if p.current() == T![;] {
|
|
||||||
p.bump();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
expressions::stmt(p, expressions::StmtWithSemi::Optional);
|
|
||||||
}
|
|
||||||
|
|
||||||
m.complete(p, MACRO_STMTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn path(p: &mut Parser) {
|
|
||||||
paths::type_path(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn expr(p: &mut Parser) {
|
pub(crate) fn expr(p: &mut Parser) {
|
||||||
expressions::expr(p);
|
let _ = expressions::expr(p);
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn type_(p: &mut Parser) {
|
|
||||||
types::type_(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn pattern(p: &mut Parser) {
|
|
||||||
patterns::pattern(p)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
|
pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
|
||||||
|
@ -93,8 +68,8 @@ pub(crate) fn stmt(p: &mut Parser, with_semi: bool) {
|
||||||
expressions::stmt(p, with_semi)
|
expressions::stmt(p, with_semi)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn block(p: &mut Parser) {
|
pub(crate) fn opt_visibility(p: &mut Parser) {
|
||||||
expressions::block(p);
|
let _ = super::opt_visibility(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a meta item , which excluded [], e.g : #[ MetaItem ]
|
// Parse a meta item , which excluded [], e.g : #[ MetaItem ]
|
||||||
|
@ -143,6 +118,29 @@ pub(crate) fn item(p: &mut Parser) {
|
||||||
items::item_or_macro(p, true, items::ItemFlavor::Mod)
|
items::item_or_macro(p, true, items::ItemFlavor::Mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn macro_items(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
items::mod_contents(p, false);
|
||||||
|
m.complete(p, MACRO_ITEMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn macro_stmts(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
|
||||||
|
while !p.at(EOF) {
|
||||||
|
if p.current() == T![;] {
|
||||||
|
p.bump();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
expressions::stmt(p, expressions::StmtWithSemi::Optional);
|
||||||
|
}
|
||||||
|
|
||||||
|
m.complete(p, MACRO_STMTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn reparser(
|
pub(crate) fn reparser(
|
||||||
node: SyntaxKind,
|
node: SyntaxKind,
|
||||||
first_child: Option<SyntaxKind>,
|
first_child: Option<SyntaxKind>,
|
||||||
|
@ -180,7 +178,7 @@ impl BlockLike {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn opt_visibility(p: &mut Parser) -> bool {
|
fn opt_visibility(p: &mut Parser) -> bool {
|
||||||
match p.current() {
|
match p.current() {
|
||||||
T![pub] => {
|
T![pub] => {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub(super) fn use_path(p: &mut Parser) {
|
||||||
path(p, Mode::Use)
|
path(p, Mode::Use)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn type_path(p: &mut Parser) {
|
pub(crate) fn type_path(p: &mut Parser) {
|
||||||
path(p, Mode::Type)
|
path(p, Mode::Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST
|
||||||
.union(paths::PATH_FIRST)
|
.union(paths::PATH_FIRST)
|
||||||
.union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]);
|
.union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]);
|
||||||
|
|
||||||
pub(super) fn pattern(p: &mut Parser) {
|
pub(crate) fn pattern(p: &mut Parser) {
|
||||||
pattern_r(p, PAT_RECOVERY_SET);
|
pattern_r(p, PAT_RECOVERY_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![
|
||||||
|
|
||||||
const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA];
|
const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA];
|
||||||
|
|
||||||
pub(super) fn type_(p: &mut Parser) {
|
pub(crate) fn type_(p: &mut Parser) {
|
||||||
type_with_bounds_cond(p, true);
|
type_with_bounds_cond(p, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,22 +85,22 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a path
|
/// Parse given tokens into the given sink as a path
|
||||||
pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::path);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a expression
|
/// Parse given tokens into the given sink as a expression
|
||||||
pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::expr);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a ty
|
/// Parse given tokens into the given sink as a ty
|
||||||
pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::type_);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a pattern
|
/// Parse given tokens into the given sink as a pattern
|
||||||
pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::pattern);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a statement
|
/// Parse given tokens into the given sink as a statement
|
||||||
|
@ -109,36 +109,34 @@ pub fn parse_stmt(
|
||||||
tree_sink: &mut dyn TreeSink,
|
tree_sink: &mut dyn TreeSink,
|
||||||
with_semi: bool,
|
with_semi: bool,
|
||||||
) {
|
) {
|
||||||
parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi));
|
parse_from_tokens(token_source, tree_sink, |p| grammar::fragments::stmt(p, with_semi));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as a block
|
/// Parse given tokens into the given sink as a block
|
||||||
pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::block);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::block);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::meta_item);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::meta_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as an 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) {
|
pub fn parse_item(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::item);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse given tokens into the given sink as an visibility qualifier
|
/// 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) {
|
pub fn parse_vis(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, |p| {
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::opt_visibility);
|
||||||
grammar::opt_visibility(p);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::macro_items);
|
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) {
|
pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::macro_stmts);
|
parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_stmts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A parsing function for a specific braced-block.
|
/// A parsing function for a specific braced-block.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue