code wiki / (root) / nx_hyphen.nx

nx_hyphen.nx

buildroot/runtime/nx_hyphen.nx

13624 B285 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_gate_verdict.nx nx_syscalls.nx nx_hyphen.nx

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

main hy_puts sys_write sys_exit hy_seq hy_selftest gv_head gv_puts sys_write ↻ gv_ctr sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_mmap ↻ hy_points sys_mmap ↻ hy_prepare hy_apply hy_pattern hy_slen sys_mmap ↻ hy_puts ↻ hy_seq ↻ gv_check gv_puts ↻ hy_num sys_write ↻ sys_mmap ↻

structs

none

consts

28const HY_MAXW: i64 = 64
29const HY_MAXPOS: i64 = 80
30const HY_NPAT: i64 = 41
31const HY_MIN_HEAD: i64 = 2 // never break with fewer than 2 letters before the hyphen (\lefthyphenmin)
32const HY_MIN_TAIL: i64 = 3 // ... nor fewer than 3 after (\righthyphenmin). TeX's English defaults.

functions

34func 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 }
called by 2: hy_selftestmain calls 1: sys_write
35func hy_num(v: i64) -> i64
called by 2: hy_selftestmain calls 2: sys_writesys_mmap
45func 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
46func hy_seq(a: *u8, b: *u8) -> i64
called by 2: hy_selftestmain
53func hy_pattern(i: i64) -> *u8
called by 1: hy_apply
103func hy_prepare(word: *u8, work: *u8) -> i64
called by 1: hy_points
120func hy_apply(work: *u8, wn: i64, pos: *i64) -> i64
called by 1: hy_points calls 3: hy_patternhy_slensys_mmap
169func hy_points(word: *u8, out: *u8) -> i64
197func hy_selftest() -> i64
272func main(argc: i64, argv: *i64) -> i64