Redirect native TeX diagnostics to real output streams
This commit is contained in:
1 parent
6ebcb75794
commit
6675ab639a
11 files changed
+540
-21
No files matched your search
@@ -95,7 +95,7 @@ fn leader_node(leader: &LeaderGlue) -> DiagnosticNode {
|
|||||||
pattern: Box::new(pattern),
|
pattern: Box::new(pattern),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn vertical_nodes(nodes: &[NativeVerticalNode]) -> Vec<DiagnosticNode> {
|
pub(super) fn vertical_nodes(nodes: &[NativeVerticalNode]) -> Vec<DiagnosticNode> {
|
||||||
nodes
|
nodes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|n| match n {
|
.map(|n| match n {
|
||||||
@@ -258,6 +258,7 @@ struct Printer<'a> {
|
|||||||
depth: i32,
|
depth: i32,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
overflow: bool,
|
overflow: bool,
|
||||||
|
wrap: bool,
|
||||||
reads: BTreeSet<Dependency>,
|
reads: BTreeSet<Dependency>,
|
||||||
}
|
}
|
||||||
impl Printer<'_> {
|
impl Printer<'_> {
|
||||||
@@ -272,7 +273,7 @@ impl Printer<'_> {
|
|||||||
} else {
|
} else {
|
||||||
self.tally += 1;
|
self.tally += 1;
|
||||||
self.column += 1;
|
self.column += 1;
|
||||||
if self.column == 79 {
|
if self.wrap && self.column == 79 {
|
||||||
self.out.push('\n');
|
self.out.push('\n');
|
||||||
self.column = 0;
|
self.column = 0;
|
||||||
}
|
}
|
||||||
@@ -750,6 +751,7 @@ pub(super) fn show_box(
|
|||||||
breadth: i32,
|
breadth: i32,
|
||||||
depth: i32,
|
depth: i32,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
|
wrap: bool,
|
||||||
) -> Result<(String, BTreeSet<Dependency>), String> {
|
) -> Result<(String, BTreeSet<Dependency>), String> {
|
||||||
let mut p = Printer {
|
let mut p = Printer {
|
||||||
state,
|
state,
|
||||||
@@ -760,6 +762,7 @@ pub(super) fn show_box(
|
|||||||
depth,
|
depth,
|
||||||
limit,
|
limit,
|
||||||
overflow: false,
|
overflow: false,
|
||||||
|
wrap,
|
||||||
reads: BTreeSet::new(),
|
reads: BTreeSet::new(),
|
||||||
};
|
};
|
||||||
p.literal(&format!("> \\box{index}="));
|
p.literal(&format!("> \\box{index}="));
|
||||||
@@ -797,6 +800,7 @@ pub(super) fn shipout_box(
|
|||||||
depth,
|
depth,
|
||||||
limit,
|
limit,
|
||||||
overflow: false,
|
overflow: false,
|
||||||
|
wrap: true,
|
||||||
reads: BTreeSet::new(),
|
reads: BTreeSet::new(),
|
||||||
};
|
};
|
||||||
if depth < 0 {
|
if depth < 0 {
|
||||||
@@ -811,3 +815,31 @@ pub(super) fn shipout_box(
|
|||||||
}
|
}
|
||||||
Ok((p.out, p.reads))
|
Ok((p.out, p.reads))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub(super) fn show_nodes(
|
||||||
|
state: &State,
|
||||||
|
nodes: &[DiagnosticNode],
|
||||||
|
breadth: i32,
|
||||||
|
depth: i32,
|
||||||
|
limit: usize,
|
||||||
|
wrap: bool,
|
||||||
|
) -> Result<(String, BTreeSet<Dependency>), String> {
|
||||||
|
let mut printer = Printer {
|
||||||
|
state,
|
||||||
|
out: String::new(),
|
||||||
|
column: 0,
|
||||||
|
tally: 0,
|
||||||
|
breadth: if breadth <= 0 { 5 } else { breadth as usize },
|
||||||
|
depth,
|
||||||
|
limit,
|
||||||
|
overflow: false,
|
||||||
|
wrap,
|
||||||
|
reads: BTreeSet::new(),
|
||||||
|
};
|
||||||
|
printer.nodes(nodes, "")?;
|
||||||
|
if printer.overflow {
|
||||||
|
return Err("native list diagnostic output capacity exceeded".into());
|
||||||
|
}
|
||||||
|
Ok((printer.out, printer.reads))
|
||||||
|
}
|
||||||
@@ -3659,6 +3659,7 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
Aftergroup => self.schedule_after_group(files)?,
|
Aftergroup => self.schedule_after_group(files)?,
|
||||||
Showbox => self.show_box(files)?,
|
Showbox => self.show_box(files)?,
|
||||||
|
Showlists | Showgroups | Showifs => self.show_activity(primitive, files)?,
|
||||||
Show | Showthe => self.show(
|
Show | Showthe => self.show(
|
||||||
primitive == Showthe,
|
primitive == Showthe,
|
||||||
token.invocation.unwrap_or(token.span),
|
token.invocation.unwrap_or(token.span),
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ pub(super) enum Destination {
|
|||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) struct BoxFrame {
|
pub(super) struct BoxFrame {
|
||||||
kind: BoxKind,
|
pub(super) kind: BoxKind,
|
||||||
spec: PackSpec,
|
pub(super) spec: PackSpec,
|
||||||
group: GroupKind,
|
group: GroupKind,
|
||||||
depth: usize,
|
pub(super) depth: usize,
|
||||||
destination: Destination,
|
pub(super) destination: Destination,
|
||||||
paragraph: Option<super::super::paragraph::Builder>,
|
pub(super) paragraph: Option<super::super::paragraph::Builder>,
|
||||||
vertical: VerticalBuilder,
|
pub(super) vertical: VerticalBuilder,
|
||||||
span: Span,
|
pub(super) span: Span,
|
||||||
discretionary: Option<DiscretionaryFrame>,
|
discretionary: Option<DiscretionaryFrame>,
|
||||||
math: Vec<super::super::math::MathBuilder>,
|
pub(super) math: Vec<super::super::math::MathBuilder>,
|
||||||
// An inner $...$ belongs to this box, even inside an outer display.
|
// An inner $...$ belongs to this box, even inside an outer display.
|
||||||
display: Option<super::display::DisplayFrame>,
|
display: Option<super::display::DisplayFrame>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use super::super::diagnostics::{DiagnosticNode, show_nodes, text_nodes, vertical_nodes};
|
||||||
use super::*;
|
use super::*;
|
||||||
impl Executor {
|
impl Executor {
|
||||||
pub(super) fn trace_conditional(
|
pub(super) fn trace_conditional(
|
||||||
@@ -211,6 +212,9 @@ impl Executor {
|
|||||||
context
|
context
|
||||||
}
|
}
|
||||||
pub(super) fn print_show_parts(&self, parts: &[&str]) -> Result<String, Error> {
|
pub(super) fn print_show_parts(&self, parts: &[&str]) -> Result<String, Error> {
|
||||||
|
self.format_show_parts(parts, true)
|
||||||
|
}
|
||||||
|
fn format_show_parts(&self, parts: &[&str], wrap: bool) -> Result<String, Error> {
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
let mut column = 0;
|
let mut column = 0;
|
||||||
let mut raw = |c: char| -> Result<(), Error> {
|
let mut raw = |c: char| -> Result<(), Error> {
|
||||||
@@ -222,7 +226,7 @@ impl Executor {
|
|||||||
column = 0;
|
column = 0;
|
||||||
} else {
|
} else {
|
||||||
column += 1;
|
column += 1;
|
||||||
if column == 79 {
|
if wrap && column == 79 {
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
column = 0;
|
column = 0;
|
||||||
}
|
}
|
||||||
@@ -245,13 +249,44 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
fn open_show_stream(&mut self) -> Option<u8> {
|
||||||
|
let stream = self.read_parameter(Parameter::Showstream).width();
|
||||||
|
if (0..16).contains(&stream) {
|
||||||
|
let stream = stream as u8;
|
||||||
|
self.reads.insert(Dependency::OutputStream(stream));
|
||||||
|
if self.io.outputs.contains(&stream) {
|
||||||
|
return Some(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_show(
|
||||||
|
&mut self,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
stream: u8,
|
||||||
|
text: String,
|
||||||
|
span: Span,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
self.diagnostic_bytes = self.diagnostic_bytes.saturating_add(text.len());
|
||||||
|
if self.diagnostic_bytes > self.limits.tokens {
|
||||||
|
return self.fail("native diagnostic output limit exceeded");
|
||||||
|
}
|
||||||
|
files
|
||||||
|
.write_out(stream, &text)
|
||||||
|
.map_err(|error| self.error(error, span))?;
|
||||||
|
self.events
|
||||||
|
.push(Event::ShowRedirected { stream, text, span });
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn show(
|
pub(super) fn show(
|
||||||
&mut self,
|
&mut self,
|
||||||
the: bool,
|
the: bool,
|
||||||
span: Span,
|
span: Span,
|
||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let text = if the {
|
let (mut head, mut tail) = if the {
|
||||||
let text = match self.the_value(files)? {
|
let text = match self.the_value(files)? {
|
||||||
TheValue::Text(text) => text,
|
TheValue::Text(text) => text,
|
||||||
TheValue::Tokens(tokens) => {
|
TheValue::Tokens(tokens) => {
|
||||||
@@ -266,7 +301,7 @@ impl Executor {
|
|||||||
text
|
text
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.print_show_parts(&[&format!("> {text}.")])?
|
(format!("> {text}"), None)
|
||||||
} else {
|
} else {
|
||||||
let t = self.required_raw(files)?.token;
|
let t = self.required_raw(files)?.token;
|
||||||
let macro_meaning = matches!(self.meaning(&t), Meaning::Macro(_));
|
let macro_meaning = matches!(self.meaning(&t), Meaning::Macro(_));
|
||||||
@@ -278,14 +313,26 @@ impl Executor {
|
|||||||
let meaning = self.meaning_string(&t)?;
|
let meaning = self.meaning_string(&t)?;
|
||||||
if macro_meaning {
|
if macro_meaning {
|
||||||
let split = meaning.find("macro:").unwrap() + "macro:".len();
|
let split = meaning.find("macro:").unwrap() + "macro:".len();
|
||||||
self.print_show_parts(&[
|
(
|
||||||
&format!("> {name}{}", &meaning[..split]),
|
format!("> {name}{}", &meaning[..split]),
|
||||||
&format!("{}.", &meaning[split..]),
|
Some(meaning[split..].to_owned()),
|
||||||
])?
|
)
|
||||||
} else {
|
} else {
|
||||||
self.print_show_parts(&[&format!("> {name}{meaning}.")])?
|
(format!("> {name}{meaning}"), None)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let stream = self.open_show_stream();
|
||||||
|
if stream.is_none() {
|
||||||
|
tail.as_mut().unwrap_or(&mut head).push('.');
|
||||||
|
}
|
||||||
|
self.reads.insert(Dependency::NewLineChar);
|
||||||
|
let text = match &tail {
|
||||||
|
Some(tail) => self.format_show_parts(&[&head, tail], stream.is_none())?,
|
||||||
|
None => self.format_show_parts(&[&head], stream.is_none())?,
|
||||||
|
};
|
||||||
|
if let Some(stream) = stream {
|
||||||
|
return self.write_show(files, stream, format!("\n{text}\n"), span);
|
||||||
|
}
|
||||||
if text.len() > self.limits.tokens {
|
if text.len() > self.limits.tokens {
|
||||||
return self.fail("native diagnostic output limit exceeded");
|
return self.fail("native diagnostic output limit exceeded");
|
||||||
}
|
}
|
||||||
@@ -321,6 +368,7 @@ impl Executor {
|
|||||||
let span = self.current;
|
let span = self.current;
|
||||||
self.finish_text(true)?;
|
self.finish_text(true)?;
|
||||||
let index = self.register_index(files)?;
|
let index = self.register_index(files)?;
|
||||||
|
let stream = self.open_show_stream();
|
||||||
self.reads.insert(Dependency::BoxRegister(index));
|
self.reads.insert(Dependency::BoxRegister(index));
|
||||||
self.reads.insert(Dependency::FontResources);
|
self.reads.insert(Dependency::FontResources);
|
||||||
self.reads.insert(Dependency::EscapeChar);
|
self.reads.insert(Dependency::EscapeChar);
|
||||||
@@ -339,9 +387,18 @@ impl Executor {
|
|||||||
breadth,
|
breadth,
|
||||||
depth,
|
depth,
|
||||||
self.limits.tokens,
|
self.limits.tokens,
|
||||||
|
stream.is_none(),
|
||||||
)
|
)
|
||||||
.map_err(|e| self.error(e, span))?;
|
.map_err(|e| self.error(e, span))?;
|
||||||
self.reads.extend(reads);
|
self.reads.extend(reads);
|
||||||
|
if let Some(stream) = stream {
|
||||||
|
let extra = if self.state.box_register(index).is_some() {
|
||||||
|
"\n"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
return self.write_show(files, stream, format!("\n{text}{extra}\n! OK\n"), span);
|
||||||
|
}
|
||||||
let context = self.diagnostic_context();
|
let context = self.diagnostic_context();
|
||||||
self.reserve_diagnostic(
|
self.reserve_diagnostic(
|
||||||
text.len() + context.text.len() + 2 * "! OK (see the transcript file).\n".len(),
|
text.len() + context.text.len() + 2 * "! OK (see the transcript file).\n".len(),
|
||||||
@@ -375,6 +432,373 @@ impl Executor {
|
|||||||
.map_err(|e| self.error(e, span))?;
|
.map_err(|e| self.error(e, span))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn show_activity(
|
||||||
|
&mut self,
|
||||||
|
command: Primitive,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let span = self.current;
|
||||||
|
if command == Primitive::Showlists {
|
||||||
|
self.finish_text(true)?;
|
||||||
|
}
|
||||||
|
let stream = self.open_show_stream();
|
||||||
|
let wrap = stream.is_none();
|
||||||
|
let body = match command {
|
||||||
|
Primitive::Showlists => {
|
||||||
|
let breadth = self.read_parameter(Parameter::Showboxbreadth).width();
|
||||||
|
let depth = self.read_parameter(Parameter::Showboxdepth).width();
|
||||||
|
let (body, dependencies) = self
|
||||||
|
.activity_lists(breadth, depth, wrap)
|
||||||
|
.map_err(|message| self.error(message, span))?;
|
||||||
|
self.reads.extend(dependencies);
|
||||||
|
body
|
||||||
|
}
|
||||||
|
Primitive::Showgroups => {
|
||||||
|
let lines = self.activity_groups();
|
||||||
|
self.format_show_parts(&lines.iter().map(String::as_str).collect::<Vec<_>>(), wrap)?
|
||||||
|
}
|
||||||
|
Primitive::Showifs => {
|
||||||
|
let lines = self.activity_conditionals();
|
||||||
|
self.format_show_parts(&lines.iter().map(String::as_str).collect::<Vec<_>>(), wrap)?
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
if let Some(stream) = stream {
|
||||||
|
return self.write_show(files, stream, format!("\n\n\n{body}\n\n\n! OK\n"), span);
|
||||||
|
}
|
||||||
|
let context = self.diagnostic_context();
|
||||||
|
let online = self.read_parameter(Parameter::Tracingonline).width() > 0;
|
||||||
|
let destination = if online {
|
||||||
|
WriteDestination::TerminalAndLog
|
||||||
|
} else {
|
||||||
|
WriteDestination::Log
|
||||||
|
};
|
||||||
|
let text = format!("\n{body}\n\n");
|
||||||
|
let log_output = format!("{}\n{}\n", self.external_print("! OK."), context.text);
|
||||||
|
let ok = if online {
|
||||||
|
"! OK."
|
||||||
|
} else {
|
||||||
|
"! OK (see the transcript file)."
|
||||||
|
};
|
||||||
|
let output = format!("{}\n{}", self.external_print(ok), context.text);
|
||||||
|
self.reserve_diagnostic(text.len() + log_output.len(), &context)?;
|
||||||
|
files
|
||||||
|
.observe_diagnostic(destination, &text)
|
||||||
|
.map_err(|error| self.error(error, span))?;
|
||||||
|
files
|
||||||
|
.observe_diagnostic_pair(&log_output, &output)
|
||||||
|
.map_err(|error| self.error(error, span))?;
|
||||||
|
self.events.push(Event::Show(ShowReport {
|
||||||
|
output,
|
||||||
|
log_output,
|
||||||
|
the: false,
|
||||||
|
text,
|
||||||
|
context,
|
||||||
|
span,
|
||||||
|
}));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn activity_conditionals(&mut self) -> Vec<String> {
|
||||||
|
self.reads.insert(Dependency::ConditionalState);
|
||||||
|
if self.conditionals.is_empty() {
|
||||||
|
return vec!["### no active conditionals".into()];
|
||||||
|
}
|
||||||
|
let frames = self.conditionals.clone();
|
||||||
|
frames
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.rev()
|
||||||
|
.map(|(index, frame)| {
|
||||||
|
let mut description = self.trace_primitive_name(frame.primitive, frame.inverted);
|
||||||
|
if frame.limit == ConditionalLimit::Fi {
|
||||||
|
description.push_str(&self.trace_primitive_name(Primitive::Else, false));
|
||||||
|
}
|
||||||
|
if let Some((source, line)) = frame.origin.filter(|(_, line)| *line != 0) {
|
||||||
|
self.reads.insert(Dependency::InputPosition(source));
|
||||||
|
description.push_str(&format!(" entered on line {line}"));
|
||||||
|
}
|
||||||
|
format!("### level {}: {description}", index + 1)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn activity_groups(&mut self) -> Vec<String> {
|
||||||
|
use super::super::boxes::PackSpec;
|
||||||
|
self.reads.insert(Dependency::GroupState);
|
||||||
|
self.reads.insert(Dependency::EscapeChar);
|
||||||
|
let escape = u8::try_from(self.state.escapechar)
|
||||||
|
.ok()
|
||||||
|
.map(|value| char::from(value).to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let mut lines = Vec::new();
|
||||||
|
for (index, (kind, origin)) in self.state.open_groups().enumerate().rev() {
|
||||||
|
let level = index + 1;
|
||||||
|
let mut text = format!(
|
||||||
|
"### {} group (level {level})",
|
||||||
|
super::scheduling::group_name(kind)
|
||||||
|
);
|
||||||
|
if let Some((source, line)) = origin.filter(|(_, line)| *line != 0) {
|
||||||
|
self.reads.insert(Dependency::InputPosition(source));
|
||||||
|
text.push_str(&format!(" entered at line {line}"));
|
||||||
|
}
|
||||||
|
let detail = if let Some(frame) =
|
||||||
|
self.box_frames.iter().find(|frame| frame.depth == level)
|
||||||
|
{
|
||||||
|
let name = match frame.kind {
|
||||||
|
BoxKind::Horizontal => "hbox",
|
||||||
|
BoxKind::Vtop => "vtop",
|
||||||
|
_ if kind == GroupKind::Vcenter => "vcenter",
|
||||||
|
_ => "vbox",
|
||||||
|
};
|
||||||
|
let placement = match frame.destination {
|
||||||
|
boxes::Destination::Append => String::new(),
|
||||||
|
boxes::Destination::Shipout => format!("{escape}shipout"),
|
||||||
|
boxes::Destination::Register(number, global) => {
|
||||||
|
let prefix = if global {
|
||||||
|
format!("{escape}global")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
format!("{prefix}{escape}setbox{number}=")
|
||||||
|
}
|
||||||
|
boxes::Destination::Shift(amount) => {
|
||||||
|
let command = match (frame.paragraph.is_some(), amount.is_negative()) {
|
||||||
|
(false, false) => "moveright",
|
||||||
|
(false, true) => "moveleft",
|
||||||
|
(true, false) => "lower",
|
||||||
|
(true, true) => "raise",
|
||||||
|
};
|
||||||
|
format!(
|
||||||
|
"{escape}{command}{}pt",
|
||||||
|
registers::print_scaled_wide(i64::from(amount).abs())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
boxes::Destination::Leaders(mode) => {
|
||||||
|
let command = match mode {
|
||||||
|
LeaderMode::Aligned => "leaders",
|
||||||
|
LeaderMode::Centered => "cleaders",
|
||||||
|
LeaderMode::Expanded => "xleaders",
|
||||||
|
};
|
||||||
|
format!("{escape}{command}")
|
||||||
|
}
|
||||||
|
boxes::Destination::Adjustment { .. } => format!("{escape}vadjust"),
|
||||||
|
boxes::Destination::Insertion { class } => format!("{escape}insert{class}"),
|
||||||
|
};
|
||||||
|
let size = match frame.spec {
|
||||||
|
PackSpec::To(value) if value != 0 => {
|
||||||
|
format!(" to{}pt", registers::print_scaled(value))
|
||||||
|
}
|
||||||
|
PackSpec::Spread(value) if value != 0 => {
|
||||||
|
format!(" spread{}pt", registers::print_scaled(value))
|
||||||
|
}
|
||||||
|
_ => String::new(),
|
||||||
|
};
|
||||||
|
if matches!(
|
||||||
|
frame.destination,
|
||||||
|
boxes::Destination::Adjustment { .. } | boxes::Destination::Insertion { .. }
|
||||||
|
) {
|
||||||
|
format!("{placement}{{")
|
||||||
|
} else {
|
||||||
|
format!("{placement}{escape}{name}{size}{{")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match kind {
|
||||||
|
GroupKind::Simple | GroupKind::MathGroup => "{".into(),
|
||||||
|
GroupKind::SemiSimple => format!("{escape}begingroup"),
|
||||||
|
GroupKind::Output => format!("{escape}output"),
|
||||||
|
GroupKind::NoAlign => format!("{escape}noalign{{"),
|
||||||
|
GroupKind::MathLeft => format!("{escape}left"),
|
||||||
|
GroupKind::MathShift if self.display.is_some() => "$$".into(),
|
||||||
|
GroupKind::MathShift => "$".into(),
|
||||||
|
GroupKind::MathChoice => format!("{escape}mathchoice{{"),
|
||||||
|
GroupKind::Discretionary => format!("{escape}discretionary{{"),
|
||||||
|
GroupKind::Align => "align entry".into(),
|
||||||
|
_ => String::new(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !detail.is_empty() {
|
||||||
|
text.push_str(&format!(" ({detail})"));
|
||||||
|
}
|
||||||
|
lines.push(text);
|
||||||
|
}
|
||||||
|
lines.push("### bottom level".into());
|
||||||
|
lines
|
||||||
|
}
|
||||||
|
|
||||||
|
fn activity_lists(
|
||||||
|
&self,
|
||||||
|
breadth: i32,
|
||||||
|
depth: i32,
|
||||||
|
wrap: bool,
|
||||||
|
) -> Result<(String, BTreeSet<Dependency>), String> {
|
||||||
|
if !self.math.is_empty()
|
||||||
|
|| self.box_frames.iter().any(|frame| !frame.math.is_empty())
|
||||||
|
|| !self.alignments.is_empty()
|
||||||
|
|| self.output_frame.is_some()
|
||||||
|
{
|
||||||
|
return Err(
|
||||||
|
"native showlists requires math, alignment or output nest diagnostics".into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let mut frames = Vec::new();
|
||||||
|
let mut enclosing_span = None;
|
||||||
|
for frame in &self.box_frames {
|
||||||
|
frames.push((frame.paragraph.as_ref(), &frame.vertical, enclosing_span));
|
||||||
|
enclosing_span = Some(frame.span);
|
||||||
|
}
|
||||||
|
frames.push((self.paragraph.as_ref(), &self.vertical, enclosing_span));
|
||||||
|
let mut text = String::new();
|
||||||
|
let mut reads = BTreeSet::from([
|
||||||
|
Dependency::ParagraphMode,
|
||||||
|
Dependency::VerticalState,
|
||||||
|
Dependency::PageState,
|
||||||
|
Dependency::FontResources,
|
||||||
|
Dependency::EscapeChar,
|
||||||
|
Dependency::NewLineChar,
|
||||||
|
]);
|
||||||
|
let mut line = |span: Span| {
|
||||||
|
reads.insert(Dependency::InputPosition(span.source));
|
||||||
|
let prefix = self
|
||||||
|
.sources
|
||||||
|
.get(span.source)
|
||||||
|
.and_then(|source| source.data.get(..span.start))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let eols = prefix
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|&(index, byte)| {
|
||||||
|
*byte == b'\r' || (*byte == b'\n' && (index == 0 || prefix[index - 1] != b'\r'))
|
||||||
|
})
|
||||||
|
.count();
|
||||||
|
eols + 1
|
||||||
|
};
|
||||||
|
let mut levels = Vec::new();
|
||||||
|
for (paragraph, vertical, span) in frames.into_iter().rev() {
|
||||||
|
levels.push((
|
||||||
|
paragraph.map(|p| (p, line(p.span))),
|
||||||
|
vertical,
|
||||||
|
span.map(&mut line),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let mut render = |text: &mut String, nodes: &[DiagnosticNode]| -> Result<(), String> {
|
||||||
|
let (part, used) =
|
||||||
|
show_nodes(&self.state, nodes, breadth, depth, self.limits.tokens, wrap)?;
|
||||||
|
if text.len().saturating_add(part.len()) > self.limits.tokens {
|
||||||
|
return Err("native list diagnostic output limit exceeded".into());
|
||||||
|
}
|
||||||
|
text.push_str(&part);
|
||||||
|
reads.extend(used);
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
for (paragraph, vertical, enter) in levels {
|
||||||
|
if !text.is_empty() {
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
if let Some((paragraph, line)) = paragraph {
|
||||||
|
let mode = if paragraph.restricted {
|
||||||
|
"restricted horizontal"
|
||||||
|
} else {
|
||||||
|
"horizontal"
|
||||||
|
};
|
||||||
|
text.push_str(&format!("### {mode} mode entered at line {line}"));
|
||||||
|
let language = paragraph.initial_language;
|
||||||
|
if !paragraph.restricted
|
||||||
|
&& (language.language != 0 || language.left_min != 2 || language.right_min != 3)
|
||||||
|
{
|
||||||
|
text.push_str(&format!(
|
||||||
|
" (language{}:hyphenmin{},{})",
|
||||||
|
language.language, language.left_min, language.right_min
|
||||||
|
));
|
||||||
|
}
|
||||||
|
render(&mut text, &text_nodes(¶graph.nodes))?;
|
||||||
|
text.push_str(&format!("\n\nspacefactor {}", paragraph.space_factor));
|
||||||
|
if !paragraph.restricted && paragraph.current_language.language != 0 {
|
||||||
|
text.push_str(&format!(
|
||||||
|
", current language {}",
|
||||||
|
paragraph.current_language.language
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if paragraph.restricted {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
let mode = if enter.is_some() {
|
||||||
|
"internal vertical"
|
||||||
|
} else {
|
||||||
|
"vertical"
|
||||||
|
};
|
||||||
|
text.push_str(&format!(
|
||||||
|
"### {mode} mode entered at line {}",
|
||||||
|
enter.unwrap_or(0)
|
||||||
|
));
|
||||||
|
if enter.is_none()
|
||||||
|
&& let Some(page) = &self.native_page
|
||||||
|
{
|
||||||
|
if !page.nodes.is_empty() {
|
||||||
|
text.push_str("\n### current page:");
|
||||||
|
render(&mut text, &vertical_nodes(&page.nodes))?;
|
||||||
|
if page.started {
|
||||||
|
let [goal, total, plus, fil, fill, filll, shrink, _] = page.dimensions;
|
||||||
|
text.push_str(&format!(
|
||||||
|
"\n\n total height {}",
|
||||||
|
registers::print_scaled_wide(total)
|
||||||
|
));
|
||||||
|
for (value, unit) in
|
||||||
|
[(plus, ""), (fil, "fil"), (fill, "fill"), (filll, "filll")]
|
||||||
|
{
|
||||||
|
if value != 0 {
|
||||||
|
text.push_str(&format!(
|
||||||
|
" plus {}{unit}",
|
||||||
|
registers::print_scaled_wide(value)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if shrink != 0 {
|
||||||
|
text.push_str(&format!(
|
||||||
|
" minus {}",
|
||||||
|
registers::print_scaled_wide(shrink)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
text.push_str(&format!(
|
||||||
|
"\n goal height {}",
|
||||||
|
registers::print_scaled_wide(goal)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
if !page.contributions.is_empty() {
|
||||||
|
text.push_str("\n### recent contributions:");
|
||||||
|
let pending: Vec<_> = page.contributions.iter().cloned().collect();
|
||||||
|
render(&mut text, &vertical_nodes(&pending))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if enter.is_none() && !vertical.nodes.is_empty() && self.native_page.is_some() {
|
||||||
|
text.push_str("\n### recent contributions:");
|
||||||
|
}
|
||||||
|
render(&mut text, &vertical_nodes(&vertical.nodes))?;
|
||||||
|
text.push_str("\n\nprevdepth ");
|
||||||
|
if vertical.prev_depth <= -1000 * 65536 {
|
||||||
|
text.push_str("ignored");
|
||||||
|
} else {
|
||||||
|
text.push_str(®isters::print_scaled(vertical.prev_depth));
|
||||||
|
}
|
||||||
|
if vertical.previous_lines != 0 {
|
||||||
|
let suffix = if vertical.previous_lines == 1 {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
"s"
|
||||||
|
};
|
||||||
|
text.push_str(&format!(
|
||||||
|
", prevgraf {} line{suffix}",
|
||||||
|
vertical.previous_lines
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok((text, reads))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Executor {
|
impl Executor {
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ impl Executor {
|
|||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
self.limits.tokens,
|
self.limits.tokens,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
.map_err(|error| self.error(error, self.current))?;
|
.map_err(|error| self.error(error, self.current))?;
|
||||||
self.reads.extend(reads);
|
self.reads.extend(reads);
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ use std::{
|
|||||||
sync::{Arc, Mutex, OnceLock, Weak},
|
sync::{Arc, Mutex, OnceLock, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCHEMA: u32 = 47;
|
const SCHEMA: u32 = 48;
|
||||||
const COMPATIBLE_SCHEMAS: [u32; 16] = [
|
const COMPATIBLE_SCHEMAS: [u32; 17] = [
|
||||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, SCHEMA,
|
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, 46, 47, SCHEMA,
|
||||||
];
|
];
|
||||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
|
|||||||
@@ -413,6 +413,7 @@ pub enum Dependency {
|
|||||||
EscapeChar,
|
EscapeChar,
|
||||||
InteractionMode,
|
InteractionMode,
|
||||||
GroupState,
|
GroupState,
|
||||||
|
ConditionalState,
|
||||||
AssignmentState,
|
AssignmentState,
|
||||||
TokenParameter(TokenParameter),
|
TokenParameter(TokenParameter),
|
||||||
GlobalDefs,
|
GlobalDefs,
|
||||||
@@ -485,6 +486,11 @@ pub enum Event {
|
|||||||
MissingGlyph(MissingGlyph),
|
MissingGlyph(MissingGlyph),
|
||||||
ShowBox(ShowBoxReport),
|
ShowBox(ShowBoxReport),
|
||||||
Show(ShowReport),
|
Show(ShowReport),
|
||||||
|
ShowRedirected {
|
||||||
|
stream: u8,
|
||||||
|
text: String,
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
BuiltParagraph(Box<NativeParagraph>),
|
BuiltParagraph(Box<NativeParagraph>),
|
||||||
BuiltMath(Box<NativeMath>),
|
BuiltMath(Box<NativeMath>),
|
||||||
BuiltDisplay(Box<NativeDisplay>),
|
BuiltDisplay(Box<NativeDisplay>),
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub enum Parameter {
|
|||||||
Defaultskewchar,
|
Defaultskewchar,
|
||||||
Tracinglostchars,
|
Tracinglostchars,
|
||||||
Tracingonline,
|
Tracingonline,
|
||||||
|
Showstream,
|
||||||
Displaywidowpenalty,
|
Displaywidowpenalty,
|
||||||
Predisplaypenalty,
|
Predisplaypenalty,
|
||||||
Postdisplaypenalty,
|
Postdisplaypenalty,
|
||||||
@@ -162,6 +163,7 @@ impl Parameter {
|
|||||||
Self::Defaultskewchar,
|
Self::Defaultskewchar,
|
||||||
Self::Tracinglostchars,
|
Self::Tracinglostchars,
|
||||||
Self::Tracingonline,
|
Self::Tracingonline,
|
||||||
|
Self::Showstream,
|
||||||
Self::Displaywidowpenalty,
|
Self::Displaywidowpenalty,
|
||||||
Self::Predisplaypenalty,
|
Self::Predisplaypenalty,
|
||||||
Self::Postdisplaypenalty,
|
Self::Postdisplaypenalty,
|
||||||
@@ -306,6 +308,7 @@ impl Parameter {
|
|||||||
Self::Tolerance => 10000,
|
Self::Tolerance => 10000,
|
||||||
Self::Hangafter => 1,
|
Self::Hangafter => 1,
|
||||||
Self::Maxdeadcycles => 25,
|
Self::Maxdeadcycles => 25,
|
||||||
|
Self::Showstream => -1,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,6 +235,9 @@ pub enum Primitive {
|
|||||||
Showbox,
|
Showbox,
|
||||||
Show,
|
Show,
|
||||||
Showthe,
|
Showthe,
|
||||||
|
Showlists,
|
||||||
|
Showgroups,
|
||||||
|
Showifs,
|
||||||
Vbox,
|
Vbox,
|
||||||
Vtop,
|
Vtop,
|
||||||
Vcenter,
|
Vcenter,
|
||||||
@@ -770,6 +773,7 @@ impl Default for State {
|
|||||||
("showbox", Showbox),
|
("showbox", Showbox),
|
||||||
("show", Show),
|
("show", Show),
|
||||||
("showthe", Showthe),
|
("showthe", Showthe),
|
||||||
|
("showlists", Showlists),
|
||||||
("delcode", Delcode),
|
("delcode", Delcode),
|
||||||
("sfcode", Sfcode),
|
("sfcode", Sfcode),
|
||||||
("lccode", Lccode),
|
("lccode", Lccode),
|
||||||
@@ -1343,6 +1347,8 @@ impl State {
|
|||||||
("eTeXversion", Etexversion),
|
("eTeXversion", Etexversion),
|
||||||
("eTeXrevision", Etexrevision),
|
("eTeXrevision", Etexrevision),
|
||||||
("currentgrouplevel", Currentgrouplevel),
|
("currentgrouplevel", Currentgrouplevel),
|
||||||
|
("showgroups", Showgroups),
|
||||||
|
("showifs", Showifs),
|
||||||
("currentgrouptype", Currentgrouptype),
|
("currentgrouptype", Currentgrouptype),
|
||||||
("lastnodetype", Lastnodetype),
|
("lastnodetype", Lastnodetype),
|
||||||
("pagediscards", Pagediscards),
|
("pagediscards", Pagediscards),
|
||||||
|
|||||||
@@ -1451,6 +1451,26 @@ XYZ、Fit 与 FitH/FitV 系列在本阶段覆盖,矩形视图见后续实现
|
|||||||
- `checkpoint/receipt.json` 为 `9f43c57a440c25faf39f8faa2a1298e45f1e057f481ae818b81a38c60a224e27`。
|
- `checkpoint/receipt.json` 为 `9f43c57a440c25faf39f8faa2a1298e45f1e057f481ae818b81a38c60a224e27`。
|
||||||
- `related-tests.log` 为 `d9bb129201a3f82b4ce125bc31d69a5a9d0b30d69868022ccac05790bf852e45`。
|
- `related-tests.log` 为 `d9bb129201a3f82b4ce125bc31d69a5a9d0b30d69868022ccac05790bf852e45`。
|
||||||
|
|
||||||
|
### TeX 诊断写入实际流
|
||||||
|
|
||||||
|
连接了 `\showstream`、`\show`、`\showthe`、`\showbox`、`\showlists`、
|
||||||
|
`\showgroups` 和 `\showifs`。诊断读取当时的参数与流状态,通过原生文件
|
||||||
|
写出路径写入实际打开的流。关闭后恢复常规日志及交互诊断。新增格式
|
||||||
|
schema48,继续接受 schema47。活动列表使用真正的盒、段落、页面和
|
||||||
|
贡献列表。活动数学、对齐、输出例程中的列表与页面插入类摘要仍待覆盖。
|
||||||
|
|
||||||
|
三份 pdfTeX INITEX 文件逐字节一致,覆盖开闭流、长行、8 位字符、真实
|
||||||
|
分组和条件、空盒和负深度。另有实际横盒、纵盒与已构建页面的流输出
|
||||||
|
逐字节相同,SHA-256 为
|
||||||
|
47d243eaf8759f9b9e466f22c439ceb50276554ead5f67f231a72688899affe3。
|
||||||
|
14项定向回归通过。检查点续编复用924步,重放前缀的第一次写入。修改
|
||||||
|
第二次写入的值后,两份输出文件、PDF、SVG 和来源映射与独立全量一致。
|
||||||
|
回执位于 target/p2-show-stream-native。
|
||||||
|
|
||||||
|
pdfTeX 兼容 profile 仍为1.40.22。下一项按原始 TFM 与虚拟字体位移补齐
|
||||||
|
`\letterspacefont`,再用未修改的 LaTeX 后端核对版本分支。
|
||||||
|
[TeX Live showstream.ch](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/showstream.ch)
|
||||||
|
|
||||||
### PDF 字面中的矩阵与来源映射
|
### PDF 字面中的矩阵与来源映射
|
||||||
|
|
||||||
来源映射与 PDF 写入共用设备原点的取整。实际字面中的 `q`、`Q` 和
|
来源映射与 PDF 写入共用设备原点的取整。实际字面中的 `q`、`Q` 和
|
||||||
|
|||||||
@@ -236,3 +236,29 @@ fn error_recovery_preserves_real_side_effect_ownership_and_recompiles() {
|
|||||||
);
|
);
|
||||||
fs::remove_dir_all(root).unwrap();
|
fs::remove_dir_all(root).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn redirected_show_uses_the_open_stream_without_setting_the_cli_error_status() {
|
||||||
|
let root = directory();
|
||||||
|
let oracle = directory();
|
||||||
|
let entry = "show-stream.tex";
|
||||||
|
let input = r"\catcode123=1\catcode125=2
|
||||||
|
\immediate\openout5=report.dat
|
||||||
|
{\showstream=5\def\shown{ABC}\show\shown\showthe\count0\showlists}
|
||||||
|
\immediate\closeout5
|
||||||
|
\end";
|
||||||
|
fs::write(root.join(entry), input).unwrap();
|
||||||
|
fs::write(oracle.join(entry), input).unwrap();
|
||||||
|
let expected = reference(&oracle, entry);
|
||||||
|
let actual = native(&root, entry);
|
||||||
|
assert!(expected.status.success());
|
||||||
|
assert!(actual.status.success(), "{actual:?}");
|
||||||
|
assert_eq!(
|
||||||
|
fs::read(root.join("report.dat")).unwrap(),
|
||||||
|
fs::read(oracle.join("report.dat")).unwrap()
|
||||||
|
);
|
||||||
|
let log = fs::read_to_string(root.join("job.log")).unwrap();
|
||||||
|
assert!(!log.contains("> \\shown"));
|
||||||
|
fs::remove_dir_all(root).unwrap();
|
||||||
|
fs::remove_dir_all(oracle).unwrap();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user