add nested snapshot for suffixed expr

This commit is contained in:
Luke Boswell 2024-03-14 15:12:58 +11:00
parent 8bbbd768ec
commit e2557067c8
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
7 changed files with 65 additions and 4 deletions

View file

@ -513,7 +513,10 @@ impl<'a> Formattable for Expr<'a> {
MultipleRecordBuilders { .. } => {}
UnappliedRecordBuilder { .. } => {}
IngestedFile(_, _) => {}
Suffixed(sub_expr) => sub_expr.format_with_options(buf, parens, newlines, indent),
Suffixed(sub_expr) => {
sub_expr.format_with_options(buf, parens, newlines, indent);
buf.push('!');
}
}
}
}

View file

@ -311,8 +311,20 @@ fn expr_start<'a>(options: ExprParseOptions) -> impl Parser<'a, Loc<Expr<'a>>, E
fn expr_operator_chain<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
line_min_indent(move |arena, state: State<'a>, min_indent: u32| {
let (_, expr, state) =
loc_possibly_negative_or_negated_term(options).parse(arena, state, min_indent)?;
let (_, expr, state) = loc_possibly_negative_or_negated_term(options)
.parse(arena, state, min_indent)
.map(|(progress, expr, state)| {
// If the next thing after the expression is a `!`, then it's Suffixed
if state.bytes().starts_with(b"!") {
(
progress,
Loc::at(expr.region, Expr::Suffixed(arena.alloc(expr.value))),
state.advance(1),
)
} else {
(progress, expr, state)
}
})?;
let initial_state = state.clone();
let end = state.pos();

View file

@ -1 +1 @@
Stdout.line
Stdout.line!

View file

@ -0,0 +1 @@
foo! (bar! baz) (blah stuff)

View file

@ -0,0 +1,43 @@
Apply(
@0-3 Suffixed(
Var {
module_name: "",
ident: "foo",
},
),
[
@9-17 ParensAround(
Apply(
@9-12 Suffixed(
Var {
module_name: "",
ident: "bar",
},
),
[
@14-17 Var {
module_name: "",
ident: "baz",
},
],
Space,
),
),
@22-32 ParensAround(
Apply(
@22-26 Var {
module_name: "",
ident: "blah",
},
[
@27-32 Var {
module_name: "",
ident: "stuff",
},
],
Space,
),
),
],
Space,
)

View file

@ -0,0 +1 @@
foo! ( bar! baz) ( blah stuff)

View file

@ -442,6 +442,7 @@ mod test_snapshots {
pass/sub_var_with_spaces.expr,
pass/sub_with_spaces.expr,
pass/suffixed.expr,
pass/suffixed_nested.expr,
pass/tag_pattern.expr,
pass/ten_times_eleven.expr,
pass/three_arg_closure.expr,