diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2023-09-05 19:06:15 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-09-05 19:19:46 +0200 |
| commit | abe8f1ece416e5627fa1e5cd30b86110f3f7d91b (patch) | |
| tree | 99cd80fd4964915ce85664075e9cf0b2576523fb /crates/parser/src | |
| parent | 3431d586e5c61c8387e07972a4a19781ac785223 (diff) | |
| download | rust-abe8f1ece416e5627fa1e5cd30b86110f3f7d91b.tar.gz rust-abe8f1ece416e5627fa1e5cd30b86110f3f7d91b.zip | |
Implement builtin#format_args, using rustc's format_args parser
Diffstat (limited to 'crates/parser/src')
| -rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 20 | ||||
| -rw-r--r-- | crates/parser/src/syntax_kind/generated.rs | 1 |
2 files changed, 20 insertions, 1 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index e13284d1b7a..4197f248e0a 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -219,7 +219,7 @@ fn tuple_expr(p: &mut Parser<'_>) -> CompletedMarker { // test builtin_expr // fn foo() { // builtin#asm(0); -// builtin#format_args(0); +// builtin#format_args("", 0, 1, a = 2 + 3, a + b); // builtin#offset_of(Foo, bar.baz.0); // } fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> { @@ -249,6 +249,24 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> { p.bump_remap(T![format_args]); p.expect(T!['(']); expr(p); + if p.eat(T![,]) { + while !p.at(EOF) && !p.at(T![')']) { + let m = p.start(); + if p.at(IDENT) && p.nth_at(1, T![=]) { + name(p); + p.bump(T![=]); + } + if expr(p).is_none() { + m.abandon(p); + break; + } + m.complete(p, FORMAT_ARGS_ARG); + + if !p.at(T![')']) { + p.expect(T![,]); + } + } + } p.expect(T![')']); Some(m.complete(p, FORMAT_ARGS_EXPR)) } else if p.at_contextual_kw(T![asm]) { diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs index 3e31e4628bd..db5278f89d5 100644 --- a/crates/parser/src/syntax_kind/generated.rs +++ b/crates/parser/src/syntax_kind/generated.rs @@ -210,6 +210,7 @@ pub enum SyntaxKind { OFFSET_OF_EXPR, ASM_EXPR, FORMAT_ARGS_EXPR, + FORMAT_ARGS_ARG, CALL_EXPR, INDEX_EXPR, METHOD_CALL_EXPR, |
