mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Parse do yeet
expressions
This commit is contained in:
parent
3033c3ddbf
commit
4a16afa264
7 changed files with 73 additions and 5 deletions
|
@ -48,6 +48,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
|
|||
T![unsafe],
|
||||
T![return],
|
||||
T![yield],
|
||||
T![do],
|
||||
T![break],
|
||||
T![continue],
|
||||
T![async],
|
||||
|
@ -93,6 +94,7 @@ pub(super) fn atom_expr(
|
|||
T![match] => match_expr(p),
|
||||
T![return] => return_expr(p),
|
||||
T![yield] => yield_expr(p),
|
||||
T![do] if p.nth_at_contextual_kw(1, T![yeet]) => yeet_expr(p),
|
||||
T![continue] => continue_expr(p),
|
||||
T![break] => break_expr(p, r),
|
||||
|
||||
|
@ -533,6 +535,7 @@ fn return_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
|||
}
|
||||
m.complete(p, RETURN_EXPR)
|
||||
}
|
||||
|
||||
// test yield_expr
|
||||
// fn foo() {
|
||||
// yield;
|
||||
|
@ -548,6 +551,23 @@ fn yield_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
|||
m.complete(p, YIELD_EXPR)
|
||||
}
|
||||
|
||||
// test yeet_expr
|
||||
// fn foo() {
|
||||
// do yeet;
|
||||
// do yeet 1
|
||||
// }
|
||||
fn yeet_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
||||
assert!(p.at(T![do]));
|
||||
assert!(p.nth_at_contextual_kw(1, T![yeet]));
|
||||
let m = p.start();
|
||||
p.bump(T![do]);
|
||||
p.bump_remap(T![yeet]);
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
}
|
||||
m.complete(p, YEET_EXPR)
|
||||
}
|
||||
|
||||
// test continue_expr
|
||||
// fn foo() {
|
||||
// loop {
|
||||
|
|
|
@ -148,11 +148,16 @@ impl<'t> Parser<'t> {
|
|||
kinds.contains(self.current())
|
||||
}
|
||||
|
||||
/// Checks if the current token is contextual keyword with text `t`.
|
||||
/// Checks if the current token is contextual keyword `kw`.
|
||||
pub(crate) fn at_contextual_kw(&self, kw: SyntaxKind) -> bool {
|
||||
self.inp.contextual_kind(self.pos) == kw
|
||||
}
|
||||
|
||||
/// Checks if the nth token is contextual keyword `kw`.
|
||||
pub(crate) fn nth_at_contextual_kw(&self, n: usize, kw: SyntaxKind) -> bool {
|
||||
self.inp.contextual_kind(self.pos + n) == kw
|
||||
}
|
||||
|
||||
/// Starts a new node in the syntax tree. All nodes and tokens
|
||||
/// consumed between the `start` and the corresponding `Marker::complete`
|
||||
/// belong to the same node.
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue