code wiki / _hdl_build / nx_sitegen_parse.nx

nx_sitegen_parse.nx source

↩ module page · 109 lines · 6652 B

1// nx_sitegen_parse.nx -- AUTONOMY CORE: parse a blueprint TEXT FILE (the ".site" format) into the engine's 2// block arrays, so a site is authored as a DATA FILE that the Nishi team / a human / a local LLM can drop in, 3// and an organ builds it -- no hardcoded blueprint, no AI in the build. The format is line-based + pipe- 4// delimited (human-readable + machine-writable): 5// title|<page title> 6// header|<brand>|<cta_label>|<cta_href> 7// hero|<headline>|<sub>|<cta_label>|<cta_href> 8// search|<action>|<placeholder> 9// cards|<heading> (then one or more) card|<title>|<body> 10// steps|<heading> (then one or more) step|<label> 11// trust| (then one or more) sig|<signal> 12// footer|<text> 13// card/step/sig attach to the most recent cards/steps/trust block. Unknown kinds + orphan items + blank / 14// pipe-less lines are SKIPPED gracefully (forward-compatible). Field strings are copied into a caller-owned 15// arena so they outlive the parse. Composes nx_sitegen (the block-kind vocabulary). license_tier: ORIGINAL 16import "nx_sitegen.nx" 17import "nx_syscalls.nx" 18 19func sgp_streq(s: *u8, lit: *u8) -> i64 { 20 var i: i64 = 0 21 var go: i64 = 1 22 while go == 1 { 23 let cs: i64 = s[i] as i64 24 let cl: i64 = lit[i] as i64 25 if cs != cl { return 0 } 26 if cs == 0 { return 1 } 27 i = i + 1 28 } 29 return 0 30} 31 32func sgp_strcpy(dst: *u8, src: *u8, cap: i64) -> i64 { 33 var i: i64 = 0 34 while src[i] != (0 as u8) { if i < cap { dst[i] = src[i] } i = i + 1 } 35 if i < cap { dst[i] = 0 as u8 } 36 if i >= cap { dst[cap-1] = 0 as u8 } 37 return i 38} 39 40// copy line text[ls..le) into arena (null-terminated) at offset ap[0]; tokenize on '|' in place; fill fld[] 41// with pointers (as i64) to each null-terminated segment; advance ap[0]; return field count. 42func sgp_tok(text: *u8, ls: i64, le: i64, arena: *u8, ap: *i64, fld: *i64, maxf: i64) -> i64 { 43 var o: i64 = ap[0] 44 let base: i64 = o 45 var i: i64 = ls 46 while i < le { arena[o] = text[i]; o = o + 1; i = i + 1 } 47 arena[o] = 0 as u8; o = o + 1 48 ap[0] = o 49 var nf: i64 = 0 50 fld[nf] = (arena + base) as i64; nf = nf + 1 51 var k: i64 = base 52 let endb: i64 = o - 1 53 while k < endb { 54 if (arena[k] as i64) == 124 { // '|' 55 arena[k] = 0 as u8 56 if nf < maxf { fld[nf] = (arena + k + 1) as i64; nf = nf + 1 } 57 } 58 k = k + 1 59 } 60 return nf 61} 62 63// parse the whole blueprint text into the block arrays + title_out. returns block count (>=0). 64func sgp_parse(text: *u8, tn: i64, kind: *i64, a: *i64, b: *i64, c: *i64, d: *i64, list: *i64, lcount: *i64, maxblk: i64, arena: *u8, title_out: *u8, title_cap: i64) -> i64 { 65 let ap: *i64 = sys_mmap(8) as *i64 // arena write offset (zero-init) 66 let empty: *u8 = "" as *u8 67 var nblk: i64 = 0 68 var cur_cards: i64 = 0 - 1 69 var cur_steps: i64 = 0 - 1 70 var cur_trust: i64 = 0 - 1 71 var cur_faq: i64 = 0 - 1 72 var cur_gallery: i64 = 0 - 1 73 var ls: i64 = 0 74 var i: i64 = 0 75 while i <= tn { 76 var eol: i64 = 0 77 if i == tn { eol = 1 } 78 if i < tn { if (text[i] as i64) == 10 { eol = 1 } } 79 if eol == 1 { 80 let le: i64 = i 81 if le > ls { 82 let fld: *i64 = sys_mmap(8*8) as *i64 83 var z: i64 = 0 84 while z < 8 { fld[z] = empty as i64; z = z + 1 } 85 sgp_tok(text, ls, le, arena, ap, fld, 8) 86 let kw: *u8 = fld[0] as *u8 87 if sgp_streq(kw, "title" as *u8) == 1 { sgp_strcpy(title_out, fld[1] as *u8, title_cap) } 88 if sgp_streq(kw, "header" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_HEADER; a[nblk]=fld[1]; b[nblk]=fld[2]; c[nblk]=fld[3]; nblk=nblk+1 } } 89 if sgp_streq(kw, "hero" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_HERO; a[nblk]=fld[1]; b[nblk]=fld[2]; c[nblk]=fld[3]; d[nblk]=fld[4]; nblk=nblk+1 } } 90 if sgp_streq(kw, "search" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_SEARCH; a[nblk]=fld[1]; b[nblk]=fld[2]; nblk=nblk+1 } } 91 if sgp_streq(kw, "cards" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_CARDS; a[nblk]=fld[1]; let it: *i64 = sys_mmap(8*64) as *i64; list[nblk]=it as i64; lcount[nblk]=0; cur_cards=nblk; nblk=nblk+1 } } 92 if sgp_streq(kw, "card" as *u8) == 1 { if cur_cards >= 0 { let it: *i64 = list[cur_cards] as *i64; let cnt: i64 = lcount[cur_cards]; let bi: i64 = cnt*2; it[bi]=fld[1]; it[bi+1]=fld[2]; lcount[cur_cards]=cnt+1 } } 93 if sgp_streq(kw, "steps" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_STEPS; a[nblk]=fld[1]; let it: *i64 = sys_mmap(8*64) as *i64; list[nblk]=it as i64; lcount[nblk]=0; cur_steps=nblk; nblk=nblk+1 } } 94 if sgp_streq(kw, "step" as *u8) == 1 { if cur_steps >= 0 { let it: *i64 = list[cur_steps] as *i64; let cnt: i64 = lcount[cur_steps]; it[cnt]=fld[1]; lcount[cur_steps]=cnt+1 } } 95 if sgp_streq(kw, "trust" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_TRUST; let it: *i64 = sys_mmap(8*64) as *i64; list[nblk]=it as i64; lcount[nblk]=0; cur_trust=nblk; nblk=nblk+1 } } 96 if sgp_streq(kw, "sig" as *u8) == 1 { if cur_trust >= 0 { let it: *i64 = list[cur_trust] as *i64; let cnt: i64 = lcount[cur_trust]; it[cnt]=fld[1]; lcount[cur_trust]=cnt+1 } } 97 if sgp_streq(kw, "footer" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_FOOTER; a[nblk]=fld[1]; nblk=nblk+1 } } 98 if sgp_streq(kw, "faq" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_FAQ; a[nblk]=fld[1]; let it: *i64 = sys_mmap(8*64) as *i64; list[nblk]=it as i64; lcount[nblk]=0; cur_faq=nblk; nblk=nblk+1 } } 99 if sgp_streq(kw, "qa" as *u8) == 1 { if cur_faq >= 0 { let it: *i64 = list[cur_faq] as *i64; let cnt: i64 = lcount[cur_faq]; let bi: i64 = cnt*2; it[bi]=fld[1]; it[bi+1]=fld[2]; lcount[cur_faq]=cnt+1 } } 100 if sgp_streq(kw, "gallery" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_GALLERY; a[nblk]=fld[1]; let it: *i64 = sys_mmap(8*64) as *i64; list[nblk]=it as i64; lcount[nblk]=0; cur_gallery=nblk; nblk=nblk+1 } } 101 if sgp_streq(kw, "img" as *u8) == 1 { if cur_gallery >= 0 { let it: *i64 = list[cur_gallery] as *i64; let cnt: i64 = lcount[cur_gallery]; let bi: i64 = cnt*2; it[bi]=fld[1]; it[bi+1]=fld[2]; lcount[cur_gallery]=cnt+1 } } 102 if sgp_streq(kw, "cta" as *u8) == 1 { if nblk < maxblk { kind[nblk]=SG_CTA; a[nblk]=fld[1]; b[nblk]=fld[2]; c[nblk]=fld[3]; d[nblk]=fld[4]; nblk=nblk+1 } } 103 } 104 ls = i + 1 105 } 106 i = i + 1 107 } 108 return nblk 109}