mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
cleanup dollar handling in expressions
This commit is contained in:
parent
1140a83c1b
commit
b9d9db83d1
3 changed files with 51 additions and 96 deletions
|
@ -69,6 +69,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
|
|||
let done = match p.current() {
|
||||
T!['('] => tuple_expr(p),
|
||||
T!['['] => array_expr(p),
|
||||
L_DOLLAR => meta_var_expr(p),
|
||||
T![|] => lambda_expr(p),
|
||||
T![move] if la == T![|] => lambda_expr(p),
|
||||
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => lambda_expr(p),
|
||||
|
@ -554,3 +555,27 @@ fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
|||
}
|
||||
m.complete(p, BOX_EXPR)
|
||||
}
|
||||
|
||||
/// Expression from `$var` macro expansion, wrapped in dollars
|
||||
fn meta_var_expr(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(p.at(L_DOLLAR));
|
||||
let m = p.start();
|
||||
p.bump(L_DOLLAR);
|
||||
let (completed, _is_block) =
|
||||
expr_bp(p, Restrictions { forbid_structs: false, prefer_stmt: false }, 1);
|
||||
|
||||
match (completed, p.current()) {
|
||||
(Some(it), R_DOLLAR) => {
|
||||
p.bump(R_DOLLAR);
|
||||
m.abandon(p);
|
||||
it
|
||||
}
|
||||
_ => {
|
||||
while !p.at(R_DOLLAR) {
|
||||
p.bump_any()
|
||||
}
|
||||
p.bump(R_DOLLAR);
|
||||
m.complete(p, ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue