Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/synapse/claims/src/30_parse.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / synapse / claims / src / 30_parse.om` 410 lines ยท 6602 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Strict ledger-line scanner. A line is accepted only in the exact canonical form this tool writes 3 note (fixed key order, no spaces, canonical escapes), so "parse ok" also means "re-serialises to itself". 4 note Results go to gp cells (offsets into the line); the cursor is gp[ppos], the line length gp[pln]. 5 6 const qseq ulong 0 7 const qts ulong 1 8 const qop ulong 2 9 const qid ulong 3 10 const qag ulong 4 11 const qagl ulong 5 12 const qse ulong 6 13 const qsel ulong 7 14 const qkind ulong 8 15 const qtg ulong 9 16 const qtgl ulong 10 17 const qmode ulong 11 18 const qttl ulong 12 19 const qexp ulong 13 20 const qst ulong 14 21 const qin ulong 15 22 const qinl ulong 16 23 const qev ulong 17 24 const qevl ulong 18 25 const qor ulong 19 26 const qorl ulong 20 27 const qprev ulong 21 28 const qhpos ulong 22 29 const qhash ulong 23 30 const qsig ulong 24 31 const ppos ulong 30 32 const pln ulong 31 33 const pso ulong 32 34 const psl ulong 33 35 36 text kv "{\"v\":1,\"seq\":" 37 text kts ",\"ts\":" 38 text kop ",\"op\":" 39 text kid ",\"id\":" 40 text kag ",\"agent\":" 41 text kse ",\"session\":" 42 text kkind ",\"kind\":" 43 text ktg ",\"target\":" 44 text kmode ",\"mode\":" 45 text kttl ",\"ttl_s\":" 46 text kexp ",\"expires\":" 47 text kst ",\"state\":" 48 text kin ",\"intent\":" 49 text kev ",\"evidence\":[" 50 text kor ",\"origin\":" 51 text kprev ",\"prev\":" 52 text khash ",\"hash\":" 53 text tu00 "00" 54 text ksig ",\"sig\":" 55 56 fn sc_at s edit uchar * to ulong 57 p = get gp ppos 58 if ge p get gp pln 59 ret 256 60 end 61 ret ulong get s p 62 end 63 64 fn sc_adv k ulong to void 65 put gp ppos add get gp ppos k 66 end 67 68 fn sc_lit s edit uchar * t view uchar * to bool 69 p = get gp ppos 70 if gt add p len t get gp pln 71 ret false 72 end 73 for i ulong len t 74 if ne get s add p i get t i 75 ret false 76 end 77 end 78 sc_adv len t 79 ret true 80 end 81 82 note sc_uint: 1..19 digits, no leading zero (except "0"); value or tbad 83 fn sc_uint s edit uchar * to ulong 84 v = ulong 0 85 k = ulong 0 86 while true bound 25 87 c = sc_at s 88 if or lt c 48 gt c 57 89 break 90 end 91 if and eq k 1 eq v 0 92 ret tbad 93 end 94 if ge k 19 95 ret tbad 96 end 97 v = add mul v 10 sub c 48 98 k = add k 1 99 sc_adv 1 100 end 101 if eq k 0 102 ret tbad 103 end 104 ret v 105 end 106 107 note sc_sf: quoted safe string (sf_ok charset, 1..256) -> gp[pso], gp[psl] 108 fn sc_sf s edit uchar * to bool 109 if ne sc_at s 34 110 ret false 111 end 112 sc_adv 1 113 st = get gp ppos 114 k = ulong 0 115 while true bound 300 116 c = sc_at s 117 if eq c 34 118 break 119 end 120 if or or lt c 33 gt c 126 eq c 92 121 ret false 122 end 123 if ge k 256 124 ret false 125 end 126 k = add k 1 127 sc_adv 1 128 end 129 if eq k 0 130 ret false 131 end 132 sc_adv 1 133 put gp pso st 134 put gp psl k 135 ret true 136 end 137 138 note sc_txt: quoted JSON string in this tool's canonical escaping (\" \\ \n \t \r, other controls 139 note \u00xx lowercase); raw bytes >= 0x20 except quote/backslash. Span (escaped) -> gp[pso], gp[psl]. 140 fn sc_txt s edit uchar * to bool 141 if ne sc_at s 34 142 ret false 143 end 144 sc_adv 1 145 st = get gp ppos 146 while true bound 70000 147 c = sc_at s 148 if eq c 256 149 ret false 150 end 151 if eq c 34 152 put gp pso st 153 put gp psl sub get gp ppos st 154 sc_adv 1 155 ret true 156 end 157 if lt c 32 158 ret false 159 end 160 if eq c 92 161 sc_adv 1 162 d = sc_at s 163 if or or or eq d 34 eq d 92 eq d 110 or eq d 116 eq d 114 164 sc_adv 1 165 continue 166 end 167 if ne d 117 168 ret false 169 end 170 sc_adv 1 171 if eq sc_lit s tu00 false 172 ret false 173 end 174 h = sc_at s 175 sc_adv 1 176 l = sc_at s 177 sc_adv 1 178 if or gt h 49 lt h 48 179 ret false 180 end 181 if eq hexv uchar and l 255 16 182 ret false 183 end 184 if gt l 255 185 ret false 186 end 187 x = add mul sub h 48 16 hexv uchar l 188 if or or eq x 10 eq x 9 eq x 13 189 ret false 190 end 191 continue 192 end 193 sc_adv 1 194 end 195 ret false 196 end 197 198 199 note sc_hex: quoted string of exactly k lowercase hex digits -> offset of first digit 200 fn sc_hex s edit uchar * k ulong to ulong 201 if ne sc_at s 34 202 ret tbad 203 end 204 sc_adv 1 205 st = get gp ppos 206 for i ulong k 207 c = sc_at s 208 if gt c 255 209 ret tbad 210 end 211 if eq hexv uchar c 16 212 ret tbad 213 end 214 sc_adv 1 215 end 216 if ne sc_at s 34 217 ret tbad 218 end 219 sc_adv 1 220 ret st 221 end 222 223 note sc_word: quoted word from wall[base .. base+cnt) -> its wall index, or tbad 224 fn sc_word s edit uchar * base ulong cnt ulong to ulong 225 if eq sc_sf s false 226 ret tbad 227 end 228 ret tw_find part s get gp pso get gp psl wall base cnt 229 end 230 231 fn sc_ts s edit uchar * to ulong 232 if ne sc_at s 34 233 ret tbad 234 end 235 sc_adv 1 236 p = get gp ppos 237 if gt add p 21 get gp pln 238 ret tbad 239 end 240 v = ts_parse s p 241 if eq v tbad 242 ret tbad 243 end 244 sc_adv 20 245 if ne sc_at s 34 246 ret tbad 247 end 248 sc_adv 1 249 ret v 250 end 251 252 note evidence list after `"evidence":[`: zero or more sf strings joined by commas, then `]` 253 fn sc_evl s edit uchar * to bool 254 st = get gp ppos 255 if eq sc_at s 93 256 put gp qev st 257 put gp qevl 0 258 sc_adv 1 259 ret true 260 end 261 while true bound 70000 262 if eq sc_sf s false 263 ret false 264 end 265 c = sc_at s 266 if eq c 93 267 put gp qev st 268 put gp qevl sub get gp ppos st 269 sc_adv 1 270 ret true 271 end 272 if ne c 44 273 ret false 274 end 275 sc_adv 1 276 end 277 ret false 278 end 279 280 fn sc_put q ulong v ulong to bool 281 put gp q v 282 ret ne v tbad 283 end 284 285 fn sc_sfk s edit uchar * t view uchar * q ulong to bool 286 if eq sc_lit s t false 287 ret false 288 end 289 if eq sc_sf s false 290 ret false 291 end 292 put gp q get gp pso 293 put gp add q 1 get gp psl 294 ret true 295 end 296 297 note pl_head: v .. ttl_s 298 fn pl_head s edit uchar * to bool 299 if eq sc_lit s kv false 300 ret false 301 end 302 if eq sc_put qseq sc_uint s false 303 ret false 304 end 305 if eq sc_lit s kts false 306 ret false 307 end 308 if eq sc_put qts sc_ts s false 309 ret false 310 end 311 if eq sc_lit s kop false 312 ret false 313 end 314 if eq sc_put qop sc_word s 0 5 false 315 ret false 316 end 317 if eq sc_lit s kid false 318 ret false 319 end 320 if eq sc_put qid sc_hex s 16 false 321 ret false 322 end 323 if eq sc_sfk s kag qag false 324 ret false 325 end 326 if eq sc_sfk s kse qse false 327 ret false 328 end 329 if eq sc_lit s kkind false 330 ret false 331 end 332 if eq sc_put qkind sc_word s 13 5 false 333 ret false 334 end 335 if eq sc_sfk s ktg qtg false 336 ret false 337 end 338 if eq sc_lit s kmode false 339 ret false 340 end 341 if eq sc_put qmode sc_word s 18 2 false 342 ret false 343 end 344 if eq sc_lit s kttl false 345 ret false 346 end 347 ret sc_put qttl sc_uint s 348 end 349 350 note pl_line: whole-line scan; true when s[0..n) is a canonical event line 351 fn pl_line s edit uchar * n ulong to bool 352 put gp ppos 0 353 put gp pln n 354 if eq pl_head s false 355 ret false 356 end 357 if eq sc_lit s kexp false 358 ret false 359 end 360 if eq sc_put qexp sc_ts s false 361 ret false 362 end 363 if eq sc_lit s kst false 364 ret false 365 end 366 if eq sc_put qst sc_word s 5 8 false 367 ret false 368 end 369 if eq sc_lit s kin false 370 ret false 371 end 372 if eq sc_txt s false 373 ret false 374 end 375 put gp qin get gp pso 376 put gp qinl get gp psl 377 if eq sc_lit s kev false 378 ret false 379 end 380 if eq sc_evl s false 381 ret false 382 end 383 if eq sc_sfk s kor qor false 384 ret false 385 end 386 if eq sc_lit s kprev false 387 ret false 388 end 389 if eq sc_put qprev sc_hex s 64 false 390 ret false 391 end 392 put gp qhpos get gp ppos 393 if eq sc_lit s khash false 394 ret false 395 end 396 if eq sc_put qhash sc_hex s 64 false 397 ret false 398 end 399 if eq sc_lit s ksig false 400 ret false 401 end 402 if eq sc_put qsig sc_hex s 128 false 403 ret false 404 end 405 if ne sc_at s 125 406 ret false 407 end 408 sc_adv 1 409 ret eq get gp ppos n 410 end