Reuse resolved character categories within each native scan

This commit is contained in:
gloamxun committed 2026-11-29 05:01:56 +08:00
1 parent 4791c42403
commit 48d42052b8
2 files changed
+51 -21

No files matched your search

+21 -21
View File
@@ -71,9 +71,10 @@ mod tests {
#[test] #[test]
fn unread_character_category_changes_after_control_word_lookahead() { fn unread_character_category_changes_after_control_word_lookahead() {
for text in ["\\set!", "\\set^^21"] {
let mut mouth = Mouth::new( let mut mouth = Mouth::new(
0, 0,
"\\set!".into(), text.into(),
super::super::InputProfile::UnicodeScalar, super::super::InputProfile::UnicodeScalar,
); );
let mut state = State::default(); let mut state = State::default();
@@ -83,10 +84,10 @@ mod tests {
TokenKind::Command(CommandName::Control("set".into())) TokenKind::Command(CommandName::Control("set".into()))
); );
state.assign_catcode('!', CatCode::Active, false); state.assign_catcode('!', CatCode::Active, false);
assert_eq!( let next = mouth.next(&state, &mut reads).unwrap().unwrap();
mouth.next(&state, &mut reads).unwrap().unwrap().kind, assert_eq!(next.kind, TokenKind::Command(CommandName::Active('!')));
TokenKind::Command(CommandName::Active('!')) assert_eq!((next.span.start, next.span.end), (4, text.len()));
); }
} }
#[test] #[test]
fn endlinechar_is_frozen_when_the_physical_line_is_loaded() { fn endlinechar_is_frozen_when_the_physical_line_is_loaded() {
@@ -640,14 +641,15 @@ impl Mouth {
/// Decode TeX's ^^ form before category lookup. Category changes affect /// Decode TeX's ^^ form before category lookup. Category changes affect
/// unread characters; tokens already in macro bodies are never retokenized. /// unread characters; tokens already in macro bodies are never retokenized.
fn peek(&mut self, state: &State, reads: &mut DependencyReads) -> Option<Character> { fn peek(&mut self, state: &State, reads: &mut DependencyReads) -> Option<(Character, CatCode)> {
loop { loop {
let c = *self.line.get(self.cursor)?; let c = *self.line.get(self.cursor)?;
if Self::catcode(state, reads, c.value) != CatCode::Superscript { let code = Self::catcode(state, reads, c.value);
return Some(c); if code != CatCode::Superscript {
return Some((c, code));
} }
let Some((value, extra)) = self.expanded_superscript(c.value, self.cursor + 1) else { let Some((value, extra)) = self.expanded_superscript(c.value, self.cursor + 1) else {
return Some(c); return Some((c, code));
}; };
let mut replacement = Character { value, ..c }; let mut replacement = Character { value, ..c };
for &part in &self.line[self.cursor + 1..=self.cursor + extra] { for &part in &self.line[self.cursor + 1..=self.cursor + extra] {
@@ -659,12 +661,16 @@ impl Mouth {
/// get_next's ordinary ^^ conversion changes cur_chr and advances loc. /// get_next's ordinary ^^ conversion changes cur_chr and advances loc.
/// Only the control-sequence scanner rewrites the input buffer (peek). /// Only the control-sequence scanner rewrites the input buffer (peek).
/// Keeping these paths distinct also preserves TeX's displayed context. /// Keeping these paths distinct also preserves TeX's displayed context.
fn next_character(&mut self, state: &State, reads: &mut DependencyReads) -> Character { fn next_character(&mut self, state: &State, reads: &mut DependencyReads) -> (Character, CatCode) {
let mut c = self.line[self.cursor]; let mut c = self.line[self.cursor];
self.cursor += 1; self.cursor += 1;
while Self::catcode(state, reads, c.value) == CatCode::Superscript { loop {
let code = Self::catcode(state, reads, c.value);
if code != CatCode::Superscript {
return (c, code);
}
let Some((value, extra)) = self.expanded_superscript(c.value, self.cursor) else { let Some((value, extra)) = self.expanded_superscript(c.value, self.cursor) else {
break; return (c, code);
}; };
c.value = value; c.value = value;
for &part in &self.line[self.cursor..self.cursor + extra] { for &part in &self.line[self.cursor..self.cursor + extra] {
@@ -672,7 +678,6 @@ impl Mouth {
} }
self.cursor += extra; self.cursor += extra;
} }
c
} }
pub fn next( pub fn next(
&mut self, &mut self,
@@ -685,13 +690,12 @@ impl Mouth {
return Ok(None); return Ok(None);
} }
} }
let c = self.next_character(state, reads); let (c, code) = self.next_character(state, reads);
let mut span = Span { let mut span = Span {
source: self.source, source: self.source,
start: c.start, start: c.start,
end: c.end, end: c.end,
}; };
let code = Self::catcode(state, reads, c.value);
let kind = match code { let kind = match code {
CatCode::Ignored => continue, CatCode::Ignored => continue,
CatCode::Invalid => { CatCode::Invalid => {
@@ -726,17 +730,13 @@ impl Mouth {
} }
CatCode::Escape => { CatCode::Escape => {
let mut name = String::new(); let mut name = String::new();
if let Some(next) = self.peek(state, reads) { if let Some((next, code)) = self.peek(state, reads) {
self.cursor += 1; self.cursor += 1;
span.start = span.start.min(next.start); span.start = span.start.min(next.start);
span.end = span.end.max(next.end); span.end = span.end.max(next.end);
name.push(next.value); name.push(next.value);
let code = Self::catcode(state, reads, next.value);
if code == CatCode::Letter { if code == CatCode::Letter {
while let Some(next) = self.peek(state, reads) { while let Some((next, CatCode::Letter)) = self.peek(state, reads) {
if Self::catcode(state, reads, next.value) != CatCode::Letter {
break;
}
name.push(next.value); name.push(next.value);
span.start = span.start.min(next.start); span.start = span.start.min(next.start);
span.end = span.end.max(next.end); span.end = span.end.max(next.end);
+30
View File
@@ -18,6 +18,36 @@
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 | | W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 | | W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
## 2026-11-29 字符扫描中的类别查询
物理输入读取和控制序列前瞻直接返回本次扫描已解析的类别。
连续上标转换按转换后的字符继续查询。未消耗的字符留给下次
扫描,仍按之后的赋值重新判定。保留 ^^ 的普通游标推进与前瞻
改写行缓冲的区别,来源范围沿用实际输入字节。
四项输入回归通过。新的实际原版 INITEX 对照覆盖两种 profile
的分组恢复、首次前瞻后改成活字符及 ^^,XeTeX 另覆盖四位和
六位转义组合成控制序列。故障探针的原生前后诊断匹配,错误
范围仍指向源字节 88..92,52 项依赖、事件和状态指纹相同。
1,760,087 字节的扫描用例中,十组交替运行的进程 CPU 时间
中位数为 226.5 → 206.4 ms,十组候选均低于对照,输出 PDF
逐字节一致。较早六组的墙钟中位数为 496.8 → 520.7 ms,波动
较大,原样本保留。原样 NeurIPS 的单次编辑执行为 3.25 → 3.28 s,
未观察到稳定的整作业收益。编辑及故障恢复的 PDF、SVG、依赖、
来源映射、资源和辅助文件均通过对照,只重新转换第 3 页。
正式浏览器延迟和出版模板矩阵仍按统一门禁验收。
下一功能批次的实际 XDV 证据已冻结。原版无显式版本时输出
PDF 1.5 和对象流,原生当前输出 PDF 1.4 和传统交叉引用表。
第一页显式 PDF 2.0 在两端生效,参考仍使用对象流。第二页
版本指令未改变原版的文档版本。实际两页输入和对象结构在
next-xdv-version/,支持从设备默认值和压缩策略共同推进。
[原版驱动的默认设置](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/dvipdfmx.c#L80-L105)
证据在 target/p4-scan-categories/。SHA256SUMS 指纹为
b170fb77079c625ae74d411e7e875f3599f3119014e01d51958433f8a53b69c9。
## 2026-11-29 执行依赖去重与字符类别读取 ## 2026-11-29 执行依赖去重与字符类别读取
字节范围内的字符类别读取通过位图登记,其他依赖在执行时用 字节范围内的字符类别读取通过位图登记,其他依赖在执行时用