simplify handler

Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
Michael Pollind 2025-05-05 19:46:06 -07:00 committed by Guillaume Gomez
parent ef489b60f6
commit b328a96ca4
2 changed files with 7 additions and 6 deletions

View File

@ -87,7 +87,7 @@ struct Generator<'a, 'h> {
/// Set of called macros we are currently in. Used to prevent (indirect) recursions.
seen_macros: Vec<(&'a Macro<'a>, Option<FileInfo<'a>>)>,
/// Set of callers to forward into the macro.
seen_callers: Vec<&'a Call<'a>>,
current_caller: Option<&'a Call<'a>>,
}
impl<'a, 'h> Generator<'a, 'h> {
@ -113,7 +113,7 @@ impl<'a, 'h> Generator<'a, 'h> {
},
is_in_filter_block,
seen_macros: Vec::new(),
seen_callers: Vec::new(),
current_caller: None,
}
}

View File

@ -649,7 +649,7 @@ impl<'a> Generator<'a, '_> {
} else {
self.seen_macros.push((def, ctx.file_info_of(call.span())));
}
self.seen_callers.push(call);
self.current_caller = Some(call);
self.flush_ws(ws1); // Cannot handle_ws() here: whitespace from macro definition comes first
let size_hint = self.push_locals(|this| {
macro_call_ensure_arg_count(call, def, ctx)?;
@ -773,7 +773,7 @@ impl<'a> Generator<'a, '_> {
})?;
self.prepare_ws(ws1);
self.seen_macros.pop();
self.seen_callers.pop();
self.current_caller = None;
Ok(size_hint)
}
@ -1119,9 +1119,10 @@ impl<'a> Generator<'a, '_> {
if ***path == Expr::Var("super") {
return self.write_block(ctx, buf, None, ws, s.span());
} else if ***path == Expr::Var("caller") {
let def = self.seen_callers.pop().ok_or_else(|| {
let def = self.current_caller.ok_or_else(|| {
ctx.generate_error(format_args!("block is not defined for caller"), s.span())
})?;
self.current_caller = None;
self.handle_ws(ws);
let size_hint = self.push_locals(|this| {
this.write_buf_writable(ctx, buf)?;
@ -1188,7 +1189,7 @@ impl<'a> Generator<'a, '_> {
buf.write('}');
Ok(size_hint)
})?;
self.seen_callers.push(def);
self.current_caller = Some(def);
return Ok(size_hint);
}
}