mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Parse do yeet
expressions
This commit is contained in:
parent
3033c3ddbf
commit
4a16afa264
@ -646,7 +646,7 @@ pub fn add_one(x: i32) -> i32 {
|
|||||||
x + 1
|
x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do() {
|
pub fn r#do() {
|
||||||
add_one($0
|
add_one($0
|
||||||
}"#,
|
}"#,
|
||||||
expect![[r##"
|
expect![[r##"
|
||||||
|
@ -48,6 +48,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
|
|||||||
T![unsafe],
|
T![unsafe],
|
||||||
T![return],
|
T![return],
|
||||||
T![yield],
|
T![yield],
|
||||||
|
T![do],
|
||||||
T![break],
|
T![break],
|
||||||
T![continue],
|
T![continue],
|
||||||
T![async],
|
T![async],
|
||||||
@ -93,6 +94,7 @@ pub(super) fn atom_expr(
|
|||||||
T![match] => match_expr(p),
|
T![match] => match_expr(p),
|
||||||
T![return] => return_expr(p),
|
T![return] => return_expr(p),
|
||||||
T![yield] => yield_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![continue] => continue_expr(p),
|
||||||
T![break] => break_expr(p, r),
|
T![break] => break_expr(p, r),
|
||||||
|
|
||||||
@ -533,6 +535,7 @@ fn return_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
|||||||
}
|
}
|
||||||
m.complete(p, RETURN_EXPR)
|
m.complete(p, RETURN_EXPR)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test yield_expr
|
// test yield_expr
|
||||||
// fn foo() {
|
// fn foo() {
|
||||||
// yield;
|
// yield;
|
||||||
@ -548,6 +551,23 @@ fn yield_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
|||||||
m.complete(p, YIELD_EXPR)
|
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
|
// test continue_expr
|
||||||
// fn foo() {
|
// fn foo() {
|
||||||
// loop {
|
// loop {
|
||||||
|
@ -148,11 +148,16 @@ impl<'t> Parser<'t> {
|
|||||||
kinds.contains(self.current())
|
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 {
|
pub(crate) fn at_contextual_kw(&self, kw: SyntaxKind) -> bool {
|
||||||
self.inp.contextual_kind(self.pos) == kw
|
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
|
/// Starts a new node in the syntax tree. All nodes and tokens
|
||||||
/// consumed between the `start` and the corresponding `Marker::complete`
|
/// consumed between the `start` and the corresponding `Marker::complete`
|
||||||
/// belong to the same node.
|
/// belong to the same node.
|
||||||
|
File diff suppressed because one or more lines are too long
31
crates/parser/test_data/parser/inline/ok/0204_yeet_expr.rast
Normal file
31
crates/parser/test_data/parser/inline/ok/0204_yeet_expr.rast
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
SOURCE_FILE
|
||||||
|
FN
|
||||||
|
FN_KW "fn"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "foo"
|
||||||
|
PARAM_LIST
|
||||||
|
L_PAREN "("
|
||||||
|
R_PAREN ")"
|
||||||
|
WHITESPACE " "
|
||||||
|
BLOCK_EXPR
|
||||||
|
STMT_LIST
|
||||||
|
L_CURLY "{"
|
||||||
|
WHITESPACE "\n "
|
||||||
|
EXPR_STMT
|
||||||
|
YEET_EXPR
|
||||||
|
DO_KW "do"
|
||||||
|
WHITESPACE " "
|
||||||
|
YEET_KW "yeet"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n "
|
||||||
|
YEET_EXPR
|
||||||
|
DO_KW "do"
|
||||||
|
WHITESPACE " "
|
||||||
|
YEET_KW "yeet"
|
||||||
|
WHITESPACE " "
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "1"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
R_CURLY "}"
|
||||||
|
WHITESPACE "\n"
|
@ -0,0 +1,4 @@
|
|||||||
|
fn foo() {
|
||||||
|
do yeet;
|
||||||
|
do yeet 1
|
||||||
|
}
|
@ -65,12 +65,12 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
|
|||||||
(">>=", "SHREQ"),
|
(">>=", "SHREQ"),
|
||||||
],
|
],
|
||||||
keywords: &[
|
keywords: &[
|
||||||
"as", "async", "await", "box", "break", "const", "continue", "crate", "dyn", "else",
|
"as", "async", "await", "box", "break", "const", "continue", "crate", "do", "dyn", "else",
|
||||||
"enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
|
"enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
|
||||||
"match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct",
|
"match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct",
|
||||||
"super", "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
|
"super", "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
|
||||||
],
|
],
|
||||||
contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules"],
|
contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules", "yeet"],
|
||||||
literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
|
literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
|
||||||
tokens: &["ERROR", "IDENT", "WHITESPACE", "LIFETIME_IDENT", "COMMENT", "SHEBANG"],
|
tokens: &["ERROR", "IDENT", "WHITESPACE", "LIFETIME_IDENT", "COMMENT", "SHEBANG"],
|
||||||
nodes: &[
|
nodes: &[
|
||||||
@ -142,6 +142,7 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
|
|||||||
"STMT_LIST",
|
"STMT_LIST",
|
||||||
"RETURN_EXPR",
|
"RETURN_EXPR",
|
||||||
"YIELD_EXPR",
|
"YIELD_EXPR",
|
||||||
|
"YEET_EXPR",
|
||||||
"LET_EXPR",
|
"LET_EXPR",
|
||||||
"UNDERSCORE_EXPR",
|
"UNDERSCORE_EXPR",
|
||||||
"MACRO_EXPR",
|
"MACRO_EXPR",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user