code wiki / _hdl_build / nx_regex_vm.nx

nx_regex_vm.nx

buildroot/runtime/_hdl_build/nx_regex_vm.nx

10785 B143 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic regex
docsdependenciesstructsconstsfunctions

about

nx_regex_vm.nx -- FULL regex with ALTERNATION | and GROUPS () via a Thompson NFA, still LINEAR-TIME (epsilon- closure state-set, NO backtracking => ReDoS-immune). Closes the regex gap beyond the atom-NFA (nx_regex_lib). Pipeline: re2post (iterative, paren-stack) -> post2nfa (explicit state graph) -> sim (state-set). T1 'a|b' T2 '(ab)+' T3 'a(b|c)d' T4 '(a|b)*c' T5 EXCEED '(a|a)*b' on 24 a's = LINEAR T6 teeth non-match. expect_exit: 0 Sovereign: nx_syscalls.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_regex_vm.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write re_vm_match sys_mmap re2post sys_mmap ↻ cs_set post2nfa sys_mmap ↻ addstate addstate ↻ cs_match ck g_puts ↻ g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_openat_append sys_write ↻ sys_close sys_exit

structs

none

consts

8const K_MAGIC_1024: i64 = 1024

functions

10func g_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: ckmain calls 1: sys_write
15func g_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
16func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
17func cs_set(csbm: *i64, base: i64, ch: i64) -> i64 { csbm[base+(ch>>6)]=csbm[base+(ch>>6)]|(1<<(ch&63)); return 0 }
called by 1: re2post
18func cs_match(csbm: *i64, cls: i64, ch: i64) -> i64 { return (csbm[cls*4+(ch>>6)]>>(ch&63))&1 }
called by 1: re_vm_match
22func re2post(re: *u8, pop: *i64, parg: *i64, csbm: *i64, pcsn: *i64) -> i64
called by 1: re_vm_match calls 2: sys_mmapcs_set
54func post2nfa(pop: *i64, parg: *i64, np: i64, scls: *i64, sto: *i64, se1: *i64, se2: *i64, pns: *i64, pmatch: *i64) -> i64
called by 1: re_vm_match calls 1: sys_mmap
86func addstate(scls: *i64, sto: *i64, se1: *i64, se2: *i64, s: i64, clist: *i64, cnp: *i64, seen: *i64, gen: i64, mst: i64, mf: *i64) -> i64
called by 2: addstatere_vm_match calls 1: addstate
95func re_vm_match(re: *u8, text: *u8, tn: i64) -> i64
118func main() -> i64