Execute XeTeX character classes and inter-character token lists

This commit is contained in:
gloamxun committed 2026-11-21 17:31:30 +08:00
1 parent d11ac0cba1
commit 5df90f113c
15 files changed
+462 -14

No files matched your search

+72 -2
View File
@@ -15,6 +15,7 @@ mod expressions;
mod fonts;
mod hyphenation;
mod input;
mod interchar;
mod list_tail;
mod marks;
mod math;
@@ -60,6 +61,7 @@ struct InputToken {
frozen: bool,
end_write: bool,
alignment: Option<alignment::Boundary>,
xe_backed_char: bool,
}
impl From<Token> for InputToken {
fn from(token: Token) -> Self {
@@ -68,6 +70,7 @@ impl From<Token> for InputToken {
frozen: false,
end_write: false,
alignment: None,
xe_backed_char: false,
}
}
}
@@ -112,6 +115,7 @@ enum TokenInputKind {
Write,
Mark,
Output,
XeInterChar,
}
enum TheValue {
Tokens(Vec<Token>),
@@ -561,7 +565,8 @@ impl Executor {
}
Ok(())
}
fn unread(&mut self, token: InputToken) -> Result<(), Error> {
fn unread(&mut self, mut token: InputToken) -> Result<(), Error> {
token.xe_backed_char = false;
self.discard_exhausted_tokens();
self.push_kind(vec![token], TokenInputKind::BackedUp)
}
@@ -914,6 +919,7 @@ impl Executor {
frozen: definition_context,
end_write: false,
alignment: None,
xe_backed_char: false,
})
.collect(),
)?,
@@ -948,6 +954,7 @@ impl Executor {
frozen: definition_context,
end_write: false,
alignment: None,
xe_backed_char: false,
})
.collect(),
)?;
@@ -1228,6 +1235,13 @@ impl Executor {
Meaning::Primitive(p @ (Gluestretch | Glueshrink)) => {
RegisterValue::Dimension(self.glue_component(p, files)?).text(false)
}
Meaning::Primitive(XeTeXinterchartoks) => {
let index = self.xe_inter_char_index(files)?;
let tokens = self
.read_xe_inter_char_tokens(index)
.map_or_else(Vec::new, |tokens| tokens.to_vec());
return Ok(TheValue::Tokens(tokens));
}
Meaning::Primitive(Toks) => {
let index = self.register_index(files)?;
self.reads.insert(Dependency::Toks(index));
@@ -1646,6 +1660,7 @@ impl Executor {
frozen: true,
end_write: true,
alignment: None,
xe_backed_char: false,
},
])?;
self.push_kind(
@@ -2318,6 +2333,10 @@ impl Executor {
Meaning::Primitive(Primitive::Interactionmode) => Ok(self.interaction_mode_value()),
Meaning::Primitive(Primitive::Pdftexversion) => Ok(Self::PDFTEX_VERSION),
Meaning::Primitive(Primitive::XeTeXversion) => Ok(Self::XETEX_VERSION),
Meaning::Primitive(Primitive::XeTeXcharclass) => {
let character = self.character_number("XeTeXcharclass index", 0x10FFFF, files)?;
Ok(i32::from(self.read_xe_char_class(character)))
}
Meaning::Primitive(Primitive::XeTeXpdfpagecount) => {
self.xdv_pdf_page_count(&next.token, files)
}
@@ -3221,6 +3240,8 @@ impl Executor {
Primitive::XeTeXpicfile => "XeTeXpicfile".into(),
Primitive::XeTeXinputencoding => "XeTeXinputencoding".into(),
Primitive::XeTeXdefaultencoding => "XeTeXdefaultencoding".into(),
Primitive::XeTeXcharclass => "XeTeXcharclass".into(),
Primitive::XeTeXinterchartoks => "XeTeXinterchartoks".into(),
Primitive::BeginL => "beginL".into(),
Primitive::EndL => "endL".into(),
Primitive::BeginR => "beginR".into(),
@@ -3711,6 +3732,7 @@ impl Executor {
files: &mut F,
mut capture_boundary: impl FnMut(&mut Self, usize, &mut F),
) -> Result<(), Error> {
let xe = self.state.input_profile() == InputProfile::XeTeX;
loop {
self.check_box_capacity(None)?;
capture_boundary(self, initial_depth, files);
@@ -3720,11 +3742,29 @@ impl Executor {
break;
};
if let Some(boundary) = input.alignment {
if xe && self.xe_end_char_run(&input)? {
continue;
}
self.alignment_boundary(boundary, files)?;
continue;
}
let meaning = self.meaning(&input.token);
let frozen_expandable = Self::suppresses_meaning(&input, &meaning);
if xe
&& (frozen_expandable
|| !matches!(
&meaning,
Meaning::Character(TokenKind::Character(
_,
CatCode::Letter | CatCode::Other
)) | Meaning::CharGiven(_)
| Meaning::Primitive(Primitive::Char | Primitive::Noboundary)
))
&& self.xe_end_char_run(&input)?
{
continue;
}
let xe_backed_char = input.xe_backed_char;
let token = input.token;
if self.read_parameter(Parameter::Tracingcommands).width() > 0 {
if frozen_expandable {
@@ -3762,6 +3802,7 @@ impl Executor {
frozen: input.frozen,
end_write: input.end_write,
alignment: None,
xe_backed_char: false,
})?;
self.insert_paragraph_token(span)?;
continue;
@@ -3806,6 +3847,7 @@ impl Executor {
frozen: input.frozen,
end_write: input.end_write,
alignment: None,
xe_backed_char: false,
})?;
self.begin_paragraph(self.current, true)?;
continue;
@@ -3835,6 +3877,12 @@ impl Executor {
}
}
CatCode::Letter | CatCode::Other | CatCode::Space => {
if xe
&& code != CatCode::Space
&& self.xe_start_character(c, code, &token, xe_backed_char)?
{
continue;
}
self.text_character(c, code, &token, files)?;
self.events.push(Event::Character(Token {
kind: TokenKind::Character(c, code),
@@ -3847,6 +3895,9 @@ impl Executor {
use Primitive::*;
match primitive {
Noboundary => {
if xe && self.xe_native_boundary_before_noboundary(&token)? {
continue;
}
self.finish_text(false)?;
if self.paragraph.is_some() {
if let Some(next) = self.expanded(files)? {
@@ -3858,7 +3909,11 @@ impl Executor {
)) | Meaning::CharGiven(_)
| Meaning::Primitive(Char)
);
self.paragraph.as_mut().unwrap().cancel_boundary = cancel;
let paragraph = self.paragraph.as_mut().unwrap();
paragraph.cancel_boundary = cancel;
if xe && cancel {
paragraph.xe_char_run = None;
}
self.unread(next)?;
}
}
@@ -4024,6 +4079,11 @@ impl Executor {
Char => {
let c = self.character_number("char", 0x10FFFF, files)?;
let c = self.scalar_character(c, token.span)?;
if xe
&& self.xe_start_character(c, CatCode::Other, &token, xe_backed_char)?
{
continue;
}
self.text_character(c, CatCode::Other, &token, files)?;
self.events.push(Event::Character(Token {
kind: TokenKind::Character(c, CatCode::Other),
@@ -4088,6 +4148,9 @@ impl Executor {
}
Meaning::CharGiven(c) => {
let c = self.scalar_character(c, token.span)?;
if xe && self.xe_start_character(c, CatCode::Other, &token, xe_backed_char)? {
continue;
}
self.text_character(c, CatCode::Other, &token, files)?;
self.events.push(Event::Character(Token {
kind: TokenKind::Character(c, CatCode::Other),
@@ -4351,6 +4414,8 @@ impl Executor {
state.assign_sfcode(c, value as u16, global);
})?;
}
Some(XeTeXcharclass) => self.assign_xe_char_class(global, files)?,
Some(XeTeXinterchartoks) => self.assign_xe_inter_char_tokens(global, files)?,
Some(p @ (Delcode | Udelcode | Udelcodenum)) => {
self.scan_delimiter_code_assignment(p, global, files)?;
}
@@ -4626,6 +4691,11 @@ impl Executor {
self.reads.insert(Dependency::Toks(other));
self.state.tokens(other)
}
Meaning::Primitive(Primitive::XeTeXinterchartoks) => {
let index = self.xe_inter_char_index(files)?;
self.read_xe_inter_char_tokens(index)
.map_or_else(Vec::new, |tokens| tokens.to_vec())
}
Meaning::Primitive(Primitive::Toks) => {
let other = self.register_index(files)?;
self.reads.insert(Dependency::Toks(other));