nx_hyphen.nx
buildroot/runtime/nx_hyphen.nx
about
nx_hyphen.nx -- LIANG HYPHENATION (the algorithm behind TeX's \hyphenation), integer-exact.
WHY: nx_kp_break optimises the breakpoints it is GIVEN. Knuth-Plass in TeX is strictly stronger than the
version I shipped first, because TeX also gets to break INSIDE words -- hyphenation points are extra
candidate breaks fed into the same optimisation. Without them a narrow column has too few places to break
and even an optimal breaker is forced into loose lines. This organ supplies those points.
HOW (Liang 1983): wrap the word in dots (".hyphenation."), slide every pattern over it, and where a pattern
matches, its digits vote on the inter-letter positions it covers. Each position takes the MAXIMUM vote it
receives. An ODD final value means "a break is allowed here", even means "not allowed". Odd/even rather
than a threshold is what lets a later, longer, more specific pattern VETO a shorter general one -- the
mechanism that makes the pattern set composable instead of order-dependent.
★ SCOPE, STATED PLAINLY RATHER THAN IMPLIED: TeX's English pattern file holds 4447 patterns. This organ
ships a SUBSET (see HY_PAT below). The gate therefore proves two DIFFERENT things and keeps them apart:
(a) the ALGORITHM is correct -- it reproduces the exact expected points for words the loaded patterns
cover, and it correctly refuses the ones they veto. That is a pass/fail claim.
(b) COVERAGE over a wider word list is REPORTED AS A NUMBER with no verdict attached, because a subset
cannot honestly be graded against a bar nobody calibrated.
Reporting (b) as a verdict is how a partial capability starts being counted as a whole one.
nx_hyphen word <word> -- show the hyphenation points
nx_hyphen selftest -- the gate
license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_gate_verdict.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 28 | const HY_MAXW: i64 = 64 |
| 29 | const HY_MAXPOS: i64 = 80 |
| 30 | const HY_NPAT: i64 = 41 |
| 31 | const HY_MIN_HEAD: i64 = 2 // never break with fewer than 2 letters before the hyphen (\lefthyphenmin) |
| 32 | const HY_MIN_TAIL: i64 = 3 // ... nor fewer than 3 after (\righthyphenmin). TeX's English defaults. |
functions
| 34 | func hy_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 35 | func hy_num(v: i64) -> i64 |
| 45 | func hy_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } called by 1: hy_apply |
| 46 | func hy_seq(a: *u8, b: *u8) -> i64 |
| 53 | func hy_pattern(i: i64) -> *u8 called by 1: hy_apply |
| 103 | func hy_prepare(word: *u8, work: *u8) -> i64 called by 1: hy_points |
| 120 | func hy_apply(work: *u8, wn: i64, pos: *i64) -> i64 |
| 169 | func hy_points(word: *u8, out: *u8) -> i64 |
| 197 | func hy_selftest() -> i64 |
| 272 | func main(argc: i64, argv: *i64) -> i64 |