mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
move pat to prefix entry points
This commit is contained in:
parent
f10f51833c
commit
5636bef2ec
3 changed files with 17 additions and 5 deletions
|
@ -693,7 +693,14 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
|
||||||
"path" => ParserEntryPoint::Path,
|
"path" => ParserEntryPoint::Path,
|
||||||
"expr" => ParserEntryPoint::Expr,
|
"expr" => ParserEntryPoint::Expr,
|
||||||
"ty" => ParserEntryPoint::Type,
|
"ty" => ParserEntryPoint::Type,
|
||||||
"pat" | "pat_param" => ParserEntryPoint::Pattern, // FIXME: edition2021
|
// FIXME: These two should actually behave differently depending on the edition.
|
||||||
|
//
|
||||||
|
// https://doc.rust-lang.org/edition-guide/rust-2021/or-patterns-macro-rules.html
|
||||||
|
"pat" | "pat_param" => {
|
||||||
|
return input
|
||||||
|
.expect_fragment2(parser::PrefixEntryPoint::Pat)
|
||||||
|
.map(|tt| tt.map(Fragment::Tokens));
|
||||||
|
}
|
||||||
"stmt" => {
|
"stmt" => {
|
||||||
return input
|
return input
|
||||||
.expect_fragment2(parser::PrefixEntryPoint::Stmt)
|
.expect_fragment2(parser::PrefixEntryPoint::Stmt)
|
||||||
|
|
|
@ -61,6 +61,10 @@ pub(crate) mod entry {
|
||||||
pub(crate) fn stmt(p: &mut Parser) {
|
pub(crate) fn stmt(p: &mut Parser) {
|
||||||
expressions::stmt(p, expressions::StmtWithSemi::No, true);
|
expressions::stmt(p, expressions::StmtWithSemi::No, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn pat(p: &mut Parser) {
|
||||||
|
patterns::pattern_single(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +80,6 @@ pub(crate) mod entry_points {
|
||||||
|
|
||||||
pub(crate) use paths::type_path as path;
|
pub(crate) use paths::type_path as path;
|
||||||
|
|
||||||
pub(crate) use patterns::pattern_single as pattern;
|
|
||||||
|
|
||||||
pub(crate) use types::type_;
|
pub(crate) use types::type_;
|
||||||
|
|
||||||
pub(crate) fn expr(p: &mut Parser) {
|
pub(crate) fn expr(p: &mut Parser) {
|
||||||
|
|
|
@ -43,7 +43,8 @@ pub use crate::{
|
||||||
|
|
||||||
/// Parse a syntactic construct at the *start* of the input.
|
/// Parse a syntactic construct at the *start* of the input.
|
||||||
///
|
///
|
||||||
/// This is used by macro-by-example parser to implement things like `$i:item`.
|
/// This is used by macro-by-example parser to implement things like `$i:item`
|
||||||
|
/// and the naming of variants follows the naming of macro fragments.
|
||||||
///
|
///
|
||||||
/// Note that this is generally non-optional -- the result is intentionally not
|
/// Note that this is generally non-optional -- the result is intentionally not
|
||||||
/// `Option<Output>`. The way MBE work, by the time we *try* to parse `$e:expr`
|
/// `Option<Output>`. The way MBE work, by the time we *try* to parse `$e:expr`
|
||||||
|
@ -54,6 +55,7 @@ pub enum PrefixEntryPoint {
|
||||||
Vis,
|
Vis,
|
||||||
Block,
|
Block,
|
||||||
Stmt,
|
Stmt,
|
||||||
|
Pat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixEntryPoint {
|
impl PrefixEntryPoint {
|
||||||
|
@ -62,6 +64,7 @@ impl PrefixEntryPoint {
|
||||||
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
||||||
PrefixEntryPoint::Block => grammar::entry::prefix::block,
|
PrefixEntryPoint::Block => grammar::entry::prefix::block,
|
||||||
PrefixEntryPoint::Stmt => grammar::entry::prefix::stmt,
|
PrefixEntryPoint::Stmt => grammar::entry::prefix::stmt,
|
||||||
|
PrefixEntryPoint::Pat => grammar::entry::prefix::pat,
|
||||||
};
|
};
|
||||||
let mut p = parser::Parser::new(input);
|
let mut p = parser::Parser::new(input);
|
||||||
entry_point(&mut p);
|
entry_point(&mut p);
|
||||||
|
@ -108,7 +111,7 @@ pub fn parse(inp: &Input, entry_point: ParserEntryPoint) -> Output {
|
||||||
ParserEntryPoint::Path => grammar::entry_points::path,
|
ParserEntryPoint::Path => grammar::entry_points::path,
|
||||||
ParserEntryPoint::Expr => grammar::entry_points::expr,
|
ParserEntryPoint::Expr => grammar::entry_points::expr,
|
||||||
ParserEntryPoint::Type => grammar::entry_points::type_,
|
ParserEntryPoint::Type => grammar::entry_points::type_,
|
||||||
ParserEntryPoint::Pattern => grammar::entry_points::pattern,
|
ParserEntryPoint::Pattern => grammar::entry::prefix::pat,
|
||||||
ParserEntryPoint::Item => grammar::entry_points::item,
|
ParserEntryPoint::Item => grammar::entry_points::item,
|
||||||
ParserEntryPoint::MetaItem => grammar::entry_points::meta_item,
|
ParserEntryPoint::MetaItem => grammar::entry_points::meta_item,
|
||||||
ParserEntryPoint::StatementOptionalSemi => grammar::entry_points::stmt_optional_semi,
|
ParserEntryPoint::StatementOptionalSemi => grammar::entry_points::stmt_optional_semi,
|
||||||
|
|
Loading…
Reference in a new issue