nx_txtscan_lib.nx
buildroot/runtime/nx_txtscan_lib.nx
about
nx_txtscan_lib.nx -- BYTE-ORIENTED text search. The unit of a match is an OFFSET, never a line.
u2605u2605u2605u2605u2605u2605WE DID NOT ONLY AVOID THE UNIX TOOLS, WE INHERITED THEIR UNIT OF MEANING. Every sovereign
search organ in this estate -- nx_codegrep, nx_shelltool grep -- scans for a substring and then
prints "the line that contains it". That is grep's worldview, reimplemented in NishiLang: it
assumes text is a sequence of newline-delimited records.
MEASURED 2026-08-05, and this is the bug that motivated the organ: the ruler corpus
knowledge/library/write_nsfwbot_flowgpt_2601_14324.txt is 112,755 bytes on ONE line (scraped HTML,
as most fetched text is). Asking the sovereign grep for "greeting" returned the ENTIRE FILE as a
single match. A search that echoes 112KB for a 8-byte pattern has not searched, it has copied --
and it reports "1 match" while telling you nothing about WHERE.
u2605A TOOL THAT DEGRADES TO THE IDENTITY FUNCTION ON ITS HARDEST INPUT STILL REPORTS SUCCESS.
So the fix is not a faster grep, it is a different RECORD: the offset. Offsets exist in every
byte stream -- minified JSON, scraped HTML, a firmware image, a file with no newline at all --
whereas lines are a property some text happens to have. This organ imposes its own record
structure on the input instead of borrowing the input's.
PURE: no syscalls, no allocation, caller owns every buffer -- so the gate can prove the search
hermetically with in-memory fixtures and no filesystem at all. The CLI (nx_txtscan.nx) adds I/O.
license_tier: ORIGINAL
module: nishi-core.text.scan
capability: TEXT_SCAN_BYTE_ORIENTED
dependencies 0 imports · 3 importers
imports: none
imported by: nx_slopmeter_lib.nxnx_txtscan.nxnx_txtscan_gate.nx
structs
| none |
consts
| 26 | const TX_NOT_FOUND: i64 = 0 - 1 |
| 33 | const TX_STEP_OVERLAP: i64 = 1 |
| 34 | const TX_STEP_DISJOINT: i64 = 0 |
| 36 | const TX_CASE_SENSITIVE: i64 = 0 |
| 37 | const TX_CASE_INSENSITIVE: i64 = 1 |
functions
| 39 | func tx_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } |
| 40 | func tx_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 43 | func tx_match_at(buf: *u8, i: i64, pat: *u8, m: i64, ci: i64) -> i64 |
| 61 | func tx_next(buf: *u8, n: i64, from: i64, pat: *u8, m: i64, ci: i64) -> i64 |
| 74 | func tx_count(buf: *u8, n: i64, pat: *u8, m: i64, ci: i64, step: i64) -> i64 |
| 99 | func tx_is_ctl(c: i64) -> i64 |
| 108 | func tx_next_ctl(buf: *u8, n: i64, from: i64) -> i64 |
| 121 | func tx_run_len(buf: *u8, n: i64, at: i64) -> i64 |
| 134 | func tx_ctx_lo(hit: i64, ctx: i64) -> i64 { let a: i64 = hit - ctx; if a < 0 { return 0 } return a } |
| 135 | func tx_ctx_hi(hit: i64, m: i64, ctx: i64, n: i64) -> i64 |