Expand deferred TeX input without recursive dispatch frames
This commit is contained in:
1 parent
ebbc9e2c17
commit
6d54af5350
3 files changed
+67
-20
No files matched your search
@@ -694,36 +694,54 @@ impl Executor {
|
||||
return self.fail("native expansion nesting limit exceeded");
|
||||
}
|
||||
self.expansion_depth += 1;
|
||||
let result = if input.frozen {
|
||||
Ok(Some(input))
|
||||
} else {
|
||||
match self.meaning(&input.token) {
|
||||
Meaning::Primitive(Primitive::Expandafter) => {
|
||||
self.expand_after(&input.token, files)
|
||||
}
|
||||
meaning => self.expand_one_inner(input, meaning, files, definition_context),
|
||||
}
|
||||
};
|
||||
let result = self.expand_with_pending_tokens(input, files, definition_context);
|
||||
self.expansion_depth -= 1;
|
||||
result
|
||||
}
|
||||
// Keep the recursive path outside the expansion dispatch frame.
|
||||
fn expand_after(
|
||||
|
||||
fn expand_with_pending_tokens(
|
||||
&mut self,
|
||||
token: &Token,
|
||||
mut input: InputToken,
|
||||
files: &mut impl SourceProvider,
|
||||
mut definition_context: bool,
|
||||
) -> Result<Option<InputToken>, Error> {
|
||||
if self.read_parameter(Parameter::Tracingcommands).width() > 1 {
|
||||
self.trace_command(token, files)?;
|
||||
}
|
||||
let first = self.required_raw(files)?;
|
||||
let second = self.required_raw(files)?;
|
||||
if let Some(second) = self.expand_one(second, files, false)? {
|
||||
let mut pending = Vec::new();
|
||||
let mut first = None;
|
||||
let result = loop {
|
||||
if input.frozen {
|
||||
break Some(input);
|
||||
}
|
||||
let meaning = self.meaning(&input.token);
|
||||
if !matches!(meaning, Meaning::Primitive(Primitive::Expandafter)) {
|
||||
break self.expand_one_inner(input, meaning, files, definition_context)?;
|
||||
}
|
||||
if self.read_parameter(Parameter::Tracingcommands).width() > 1 {
|
||||
self.trace_command(&input.token, files)?;
|
||||
}
|
||||
// Expanding the second token is the same dispatch with deferred
|
||||
// input. Only a re-entry from a scanner needs a new expansion frame.
|
||||
if let Some(outer) = first.replace(self.required_raw(files)?) {
|
||||
if pending.len() >= self.limits.input_depth {
|
||||
return self.fail("native input stack limit exceeded");
|
||||
}
|
||||
pending.push(outer);
|
||||
}
|
||||
input = self.required_raw(files)?;
|
||||
definition_context = false;
|
||||
};
|
||||
let Some(first) = first else {
|
||||
return Ok(result);
|
||||
};
|
||||
if let Some(second) = result {
|
||||
self.unread(second)?;
|
||||
}
|
||||
self.unread(first)?;
|
||||
for token in pending.into_iter().rev() {
|
||||
self.unread(token)?;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn expand_one_inner(
|
||||
&mut self,
|
||||
input: InputToken,
|
||||
|
||||
Reference in new issue
Block a user