mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Make vis
matcher optional and fix typo
This commit is contained in:
parent
b0e7022afe
commit
35c4633150
3 changed files with 28 additions and 5 deletions
|
@ -206,8 +206,24 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
"vis" => {
|
"vis" => {
|
||||||
let vis = input.eat_vis().ok_or(ExpandError::UnexpectedToken)?.clone();
|
// `vis` is optional
|
||||||
res.inner.insert(text.clone(), Binding::Simple(vis.into()));
|
if let Some(vis) = input.try_eat_vis() {
|
||||||
|
let vis = vis.clone();
|
||||||
|
res.inner.insert(text.clone(), Binding::Simple(vis.into()));
|
||||||
|
} else {
|
||||||
|
// FIXME: Do we have a better way to represent an empty token ?
|
||||||
|
// Insert an empty subtree for empty token
|
||||||
|
res.inner.insert(
|
||||||
|
text.clone(),
|
||||||
|
Binding::Simple(
|
||||||
|
tt::Subtree {
|
||||||
|
delimiter: tt::Delimiter::None,
|
||||||
|
token_trees: vec![],
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(ExpandError::UnexpectedToken),
|
_ => return Err(ExpandError::UnexpectedToken),
|
||||||
|
|
|
@ -319,7 +319,7 @@ fn convert_ident(ident: &tt::Ident) -> TtToken {
|
||||||
|
|
||||||
fn convert_punct(p: &tt::Punct) -> TtToken {
|
fn convert_punct(p: &tt::Punct) -> TtToken {
|
||||||
let kind = match p.char {
|
let kind = match p.char {
|
||||||
// lexer may produce combpund tokens for these ones
|
// lexer may produce compound tokens for these ones
|
||||||
'.' => DOT,
|
'.' => DOT,
|
||||||
':' => COLON,
|
':' => COLON,
|
||||||
'=' => EQ,
|
'=' => EQ,
|
||||||
|
|
|
@ -149,9 +149,16 @@ impl<'a> TtCursor<'a> {
|
||||||
self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into())
|
self.eat_ident().cloned().map(|ident| tt::Leaf::from(ident).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_vis(&mut self) -> Option<tt::TokenTree> {
|
pub(crate) fn try_eat_vis(&mut self) -> Option<tt::TokenTree> {
|
||||||
|
// `vis` matcher is optional
|
||||||
|
let old_pos = self.pos;
|
||||||
let parser = Parser::new(&mut self.pos, self.subtree);
|
let parser = Parser::new(&mut self.pos, self.subtree);
|
||||||
parser.parse_vis()
|
|
||||||
|
let res = parser.parse_vis();
|
||||||
|
if res.is_none() {
|
||||||
|
self.pos = old_pos;
|
||||||
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> {
|
pub(crate) fn expect_char(&mut self, char: char) -> Result<(), ParseError> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue