mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Parse builtin# syntax
This commit is contained in:
parent
db4684ef6c
commit
9b8eb807a3
17 changed files with 264 additions and 88 deletions
|
@ -1,3 +1,5 @@
|
|||
use crate::grammar::types::type_;
|
||||
|
||||
use super::*;
|
||||
|
||||
// test expr_literals
|
||||
|
@ -73,6 +75,9 @@ pub(super) fn atom_expr(
|
|||
if let Some(m) = literal(p) {
|
||||
return Some((m, BlockLike::NotBlock));
|
||||
}
|
||||
if p.at_contextual_kw(T![builtin]) && p.nth_at(1, T![#]) {
|
||||
return Some((builtin_expr(p)?, BlockLike::NotBlock));
|
||||
}
|
||||
if paths::is_path_start(p) {
|
||||
return Some(path_expr(p, r));
|
||||
}
|
||||
|
@ -93,7 +98,6 @@ pub(super) fn atom_expr(
|
|||
m.complete(p, UNDERSCORE_EXPR)
|
||||
}
|
||||
T![loop] => loop_expr(p, None),
|
||||
T![box] => box_expr(p, None),
|
||||
T![while] => while_expr(p, None),
|
||||
T![try] => try_block_expr(p, None),
|
||||
T![match] => match_expr(p),
|
||||
|
@ -212,6 +216,38 @@ fn tuple_expr(p: &mut Parser<'_>) -> CompletedMarker {
|
|||
m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR })
|
||||
}
|
||||
|
||||
// test builtin_expr
|
||||
// fn foo() {
|
||||
// builtin#asm(0);
|
||||
// builtin#format_args(0);
|
||||
// builtin#builtin(0);
|
||||
// }
|
||||
fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
||||
let m = p.start();
|
||||
p.bump_remap(T![builtin]);
|
||||
p.bump(T![#]);
|
||||
if p.at_contextual_kw(T![offset_of]) {
|
||||
p.expect(T!['(']);
|
||||
type_(p);
|
||||
p.bump(T![,]);
|
||||
p.expect(T![')']);
|
||||
Some(m.complete(p, OFFSET_OF_EXPR))
|
||||
} else if p.at_contextual_kw(T![format_args]) {
|
||||
p.expect(T!['(']);
|
||||
expr(p);
|
||||
p.expect(T![')']);
|
||||
Some(m.complete(p, FORMAT_ARGS_EXPR))
|
||||
} else if p.at_contextual_kw(T![asm]) {
|
||||
p.expect(T!['(']);
|
||||
expr(p);
|
||||
p.expect(T![')']);
|
||||
Some(m.complete(p, ASM_EXPR))
|
||||
} else {
|
||||
m.abandon(p);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// test array_expr
|
||||
// fn foo() {
|
||||
// [];
|
||||
|
@ -662,19 +698,3 @@ fn try_block_expr(p: &mut Parser<'_>, m: Option<Marker>) -> CompletedMarker {
|
|||
}
|
||||
m.complete(p, BLOCK_EXPR)
|
||||
}
|
||||
|
||||
// test box_expr
|
||||
// fn foo() {
|
||||
// let x = box 1i32;
|
||||
// let y = (box 1i32, box 2i32);
|
||||
// let z = Foo(box 1i32, box 2i32);
|
||||
// }
|
||||
fn box_expr(p: &mut Parser<'_>, m: Option<Marker>) -> CompletedMarker {
|
||||
assert!(p.at(T![box]));
|
||||
let m = m.unwrap_or_else(|| p.start());
|
||||
p.bump(T![box]);
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
}
|
||||
m.complete(p, BOX_EXPR)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue