Expand native Unicode character primitives and definitions

This commit is contained in:
gloamxun committed 2026-11-21 11:58:23 +08:00
1 parent d17680fcd8
commit 651fab42f1
7 files changed
+227 -31

No files matched your search

@@ -105,11 +105,12 @@ impl Executor {
}
fn math_code_char(
&mut self,
c: char,
c: u32,
token: &Token,
) -> Result<Option<(NoadClass, MathChar)>, Error> {
let code = self.read_math_code(c as u32);
let code = self.read_math_code(c);
if code.is_active() {
let c = self.scalar_character(c, token.span)?;
let mut t = token.clone();
t.kind = TokenKind::Command(CommandName::Active(c));
self.unread(t.into())?;
@@ -523,14 +524,14 @@ impl Executor {
});
}
CatCode::Letter | CatCode::Other => {
if let Some((class, c)) = self.math_code_char(*c, token)? {
if let Some((class, c)) = self.math_code_char(*c as u32, token)? {
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token))
}
}
_ => return self.fail("unsupported native math category"),
},
Meaning::CharGiven(c) => {
if let Some((class, c)) = self.math_code_char(*c as char, token)? {
if let Some((class, c)) = self.math_code_char(*c, token)? {
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token))
}
}
@@ -574,11 +575,9 @@ impl Executor {
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token));
}
Mathchar | Char | Delimiter => {
let n = self.integer(files)?;
if *p == Char {
let c = u8::try_from(n)
.map_err(|_| self.error("char must be in 0..255", token.span))?;
if let Some((class, c)) = self.math_code_char(c as char, token)? {
let c = self.character_number("char", 0xFFFF, files)?;
if let Some((class, c)) = self.math_code_char(c, token)? {
self.accept_math_field(
MathField::Char(c),
class,
@@ -586,12 +585,14 @@ impl Executor {
)
}
} else if *p == Delimiter {
let n = self.integer(files)?;
if !(0..1 << 27).contains(&n) {
return self.fail("delimiter must be in 0..134217727");
}
let (class, c) = self.decode_math_char((n >> 12) as u16);
self.accept_math_field(MathField::Char(c), class, TokenOrigin::from(token));
} else {
let n = self.integer(files)?;
if !(0..32768).contains(&n) {
return self.fail("mathchar must be in 0..32767");
};