mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: move block to prefix entry point
This commit is contained in:
parent
350d5dc152
commit
519ee21bcb
3 changed files with 12 additions and 6 deletions
|
@ -695,7 +695,11 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
|
||||||
"ty" => ParserEntryPoint::Type,
|
"ty" => ParserEntryPoint::Type,
|
||||||
"pat" | "pat_param" => ParserEntryPoint::Pattern, // FIXME: edition2021
|
"pat" | "pat_param" => ParserEntryPoint::Pattern, // FIXME: edition2021
|
||||||
"stmt" => ParserEntryPoint::Statement,
|
"stmt" => ParserEntryPoint::Statement,
|
||||||
"block" => ParserEntryPoint::Block,
|
"block" => {
|
||||||
|
return input
|
||||||
|
.expect_fragment2(parser::PrefixEntryPoint::Block)
|
||||||
|
.map(|tt| tt.map(Fragment::Tokens));
|
||||||
|
}
|
||||||
"meta" => ParserEntryPoint::MetaItem,
|
"meta" => ParserEntryPoint::MetaItem,
|
||||||
"item" => ParserEntryPoint::Item,
|
"item" => ParserEntryPoint::Item,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -725,7 +729,7 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
|
||||||
.map_err(|()| err!())
|
.map_err(|()| err!())
|
||||||
}
|
}
|
||||||
// `vis` is optional
|
// `vis` is optional
|
||||||
"vis" => Ok(input.eat_vis()),
|
"vis" => Ok(input.expect_fragment2(parser::PrefixEntryPoint::Vis).value),
|
||||||
_ => Err(ExpandError::UnexpectedToken),
|
_ => Err(ExpandError::UnexpectedToken),
|
||||||
};
|
};
|
||||||
return tt_result.map(|it| it.map(Fragment::Tokens)).into();
|
return tt_result.map(|it| it.map(Fragment::Tokens)).into();
|
||||||
|
@ -894,10 +898,6 @@ impl<'a> TtIter<'a> {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_vis(&mut self) -> Option<tt::TokenTree> {
|
|
||||||
self.expect_fragment2(parser::PrefixEntryPoint::Vis).value
|
|
||||||
}
|
|
||||||
|
|
||||||
fn eat_char(&mut self, c: char) -> Option<tt::TokenTree> {
|
fn eat_char(&mut self, c: char) -> Option<tt::TokenTree> {
|
||||||
let mut fork = self.clone();
|
let mut fork = self.clone();
|
||||||
match fork.expect_char(c) {
|
match fork.expect_char(c) {
|
||||||
|
|
|
@ -53,6 +53,10 @@ pub(crate) mod entry {
|
||||||
pub(crate) fn vis(p: &mut Parser) {
|
pub(crate) fn vis(p: &mut Parser) {
|
||||||
let _ = opt_visibility(p, false);
|
let _ = opt_visibility(p, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn block(p: &mut Parser) {
|
||||||
|
expressions::block_expr(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,14 @@ pub use crate::{
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PrefixEntryPoint {
|
pub enum PrefixEntryPoint {
|
||||||
Vis,
|
Vis,
|
||||||
|
Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixEntryPoint {
|
impl PrefixEntryPoint {
|
||||||
pub fn parse(&self, input: &Input) -> Output {
|
pub fn parse(&self, input: &Input) -> Output {
|
||||||
let entry_point: fn(&'_ mut parser::Parser) = match self {
|
let entry_point: fn(&'_ mut parser::Parser) = match self {
|
||||||
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
||||||
|
PrefixEntryPoint::Block => grammar::entry::prefix::block,
|
||||||
};
|
};
|
||||||
let mut p = parser::Parser::new(input);
|
let mut p = parser::Parser::new(input);
|
||||||
entry_point(&mut p);
|
entry_point(&mut p);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue