code wiki / (root) / nx_text_sentences.nx

nx_text_sentences.nx source

↩ module page · 43 lines · 2251 B

1// nx_text_sentences.nx -- shared text primitive extracted from the research stack (Consolidation-Without-Loss 2// STEP A, 2026-07-14). txt_sentence_end = the decimal-safe sentence-boundary scan: a '.' ends a sentence only 3// when followed by space / newline / end (NOT a decimal point like "86.8"); '!' and '?' always end. This scan was 4// BYTE-IDENTICAL in rsq_claim_verdict (S1) and rvs_verify_answer (S1<->S2); extracted here so both call ONE copy. 5// ⚠ nx_research_report (S3) does NOT use this -- it has its own carry-aware state machine (kept separate by 6// design; see the dossier). Contract locked by: nx_research_synth_qwen_gate 8/8 + nx_research_verify_synth_gate 4/4. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10// given a sentence start s in buf[0,blen), return the end index e (index of the terminator, or blen). 11func txt_sentence_end(buf: *u8, s: i64, blen: i64) -> i64 { 12 var e: i64 = s 13 var go: i64 = 1 14 while go == 1 { 15 go = 0 16 if e < blen { 17 let c: i64 = buf[e] as i64 & 0xff 18 if c == 33 { } else { if c == 63 { } else { 19 if c == 46 { 20 var term: i64 = 0 21 if e+1 >= blen { term = 1 } else { let nx2: i64 = buf[e+1] as i64 & 0xff; if nx2 == 32 { term = 1 } else { if nx2 == 10 { term = 1 } } } 22 if term == 0 { e = e + 1; go = 1 } 23 } else { e = e + 1; go = 1 } 24 } } 25 } 26 } 27 return e 28} 29 30// parse one [number] citation token at buf[i]=='['. outp[0]=val, outp[1]=complete (1 iff a ']' closed it). 31// returns the end offset (after ']' if complete, else after the digits). Canonical [n]-token parser shared by 32// S1 (rsq_sentence_cite) + S3 (rp_parse_cite / rp_count_cites). Contract: nx_text_sentences_gate. 33func txt_parse_cite(buf: *u8, blen: i64, i: i64, outp: *i64) -> i64 { 34 var j: i64 = i + 1 35 var val: i64 = 0 36 var got: i64 = 0 37 var go: i64 = 1 38 while go == 1 { go = 0; if j < blen { let d: i64 = buf[j] as i64 & 0xff; if d >= 48 { if d <= 57 { val = val*10 + (d-48); got = got + 1; j = j + 1; go = 1 } } } } 39 outp[0] = val 40 outp[1] = 0 41 if got > 0 { if j < blen { if (buf[j] as i64 & 0xff) == 93 { outp[1] = 1; return j + 1 } } } 42 return j 43}