interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / site / verify-text.om

636 lines · 14177 bytes Raw Blame History
1note verify-text.om: the HTML reading the oracle does (oracle.rs, seo.rs attr/tag_name,
2note boxlink.rs, voice.rs), ported byte for byte. Every function works on arena slots
3note (verify-core.om); positions are slot-relative. A function that builds text returns a new
4note slot that the caller drops.
5global vtn uchar 64
6global vtnn ulong 1
7global vav ulong 2
8global vax ulong 4
9global vlab uchar 64
10global vlabn ulong 1
11text vxscr "script"
12text vxsty "style"
13text vxtpl "template"
14text vxnos "noscript"
15text vxvoid "area\nbase\nbr\ncol\nembed\nhr\nimg\ninput\nlink\nmeta\nsource\ntrack\nwbr\n"
16text vxcom "<!--"
17text vxcomx "-->"
18text vxhid "hidden"
19text vxah "aria-hidden"
20text vxtrue "true"
21text vxclass "class"
22text vxhref "href"
23text vxa "<a"
24text vxaend "</a>"
25text vxclo "</"
26text vxsl "/>"
27text vxlt "<"
28text vxid "id"
29text vxmain "<main"
30text vxnoso "<noscript"
31text vxnosc "</noscript>"
32note entity tables: pattern LF replacement LF ... in the order Rust applies its replace calls
33text vxent1 "&nbsp;\n \n&quot;\n\"\n&#39;\n'\n&lt;\n<\n&gt;\n>\n&amp;\n&\n"
34text vxent2 "&amp;\n&\n&#39;\n'\n&apos;\n'\n&quot;\n\"\n&lt;\n<\n&gt;\n>\n&nbsp;\n \n"
35
36note ---------------------------------------------------------------- bytes in a slot
37fn sv_aws c uchar to bool
38ret or or eq c 32 eq c 9 or or eq c 10 eq c 12 eq c 13
39end
40fn sv_awsr c uchar to bool
41note the set Rust's starts_with(['>', ' ', '\t', '\n', '\r']) accepts after a tag name
42ret or or eq c 62 eq c 32 or or eq c 9 eq c 10 eq c 13
43end
44fn sv_bat s ulong i ulong to uchar
45if ge i sv_n s
46ret 0
47end
48ret sv_b s i
49end
50note sv_tagend: index of the first '>' at or after i, VNONE.
51fn sv_tagend s ulong i ulong to ulong
52ret sv_findb2 s 62 i
53end
54fn sv_findb2 s ulong c uchar from ulong to ulong
55wn = sv_n s
56wb = sv_off s
57wi = from
58while lt wi wn bound 64
59wk = ulong 0
60while and lt wi wn lt wk 262144 bound 262144
61if eq get va add wb wi c
62ret wi
63end
64wi = add wi 1
65wk = add wk 1
66end
67end
68ret VNONE
69end
70note sv_tname: seo.rs tag_name: skip every leading '<', then every '/', then ASCII alphanumerics,
71note lowercased, into vtn; returns the length.
72fn sv_tname s ulong i ulong to ulong
73while eq sv_bat s i 60 bound 999999
74i = add i 1
75end
76while eq sv_bat s i 47 bound 999999
77i = add i 1
78end
79wn = ulong 0
80while lt wn 64 bound 64
81c = sv_bat s i
82if not or sv_isdig c or and ge c 65 le c 90 and ge c 97 le c 122
83break
84end
85put vtn wn sv_lc c
86wn = add wn 1
87i = add i 1
88end
89put vtnn 0 wn
90ret wn
91end
92fn sv_tnis pat view uchar * to bool
93if ne get vtnn 0 len pat
94ret false
95end
96for wj ulong len pat
97if ne get vtn wj get pat wj
98ret false
99end
100end
101ret true
102end
103fn sv_tnin t view uchar * to bool
104for wk ulong sv_tcount t
105wa = sv_tat t wk
106if sv_tnis part t wa sv_tlen t wa
107ret true
108end
109end
110ret false
111end
112note sv_aqval: the quoted value opening at wj (< we) for sv_attr: its start (>= 1, length in
113note vav[0]); VNONE when unterminated before we; 0 when wj holds no quote (keep scanning).
114fn sv_aqval s ulong wj ulong we ulong to ulong
115wq = sv_bat s wj
116if and lt wj we or eq wq 34 eq wq 39
117wz = sv_findb2 s wq add wj 1
118if or eq wz VNONE ge wz we
119ret VNONE
120end
121put vav 0 sub wz add wj 1
122ret add wj 1
123end
124ret 0
125end
126note sv_attr: seo.rs attr(tag, name) over the tag bytes [t0, t1] ('>' at t1). Found: value offset,
127note vav[0] its length. Missing: VNONE. A value whose closing quote is missing ends the search
128note (Rust's `?`).
129fn sv_attr s ulong t0 ulong t1 ulong name view uchar * to ulong
130wi = t0
131we = add t1 1
132while true bound 999999
133wst = sv_findn s name wi we
134if eq wst VNONE
135ret VNONE
136end
137wok = and gt wst t0 sv_aws sv_b s sub wst 1
138wj = add wst len name
139while and lt wj we sv_aws sv_bat s wj bound 999999
140wj = add wj 1
141end
142if and wok and lt wj we eq sv_bat s wj 61
143wj = add wj 1
144while and lt wj we sv_aws sv_bat s wj bound 999999
145wj = add wj 1
146end
147wv = sv_aqval s wj we
148if ne wv 0
149ret wv
150end
151end
152wi = add wst len name
153end
154ret VNONE
155end
156note sv_aeq: the attribute value at v (length vav[0], from sv_attr) equals want; v VNONE is false.
157fn sv_aeq s ulong v ulong want view uchar * to bool
158if eq v VNONE
159ret false
160end
161if ne get vav 0 len want
162ret false
163end
164ret sv_eqat s v want
165end
166note sv_anstp: byte i of slot s ends an attribute-name run (space, '>' or '/').
167fn sv_anstp s ulong i ulong to bool
168c = sv_bat s i
169ret or or sv_aws c eq c 62 eq c 47
170end
171note sv_anend: byte i of slot s ends an attribute name (space, '=', '>' or '/').
172fn sv_anend s ulong i ulong to bool
173c = sv_bat s i
174ret or or sv_aws c eq c 61 or eq c 62 eq c 47
175end
176note sv_anames: oracle.rs attr_names(tag) contains the lowercase name.
177fn sv_anames s ulong t0 ulong t1 ulong name view uchar * to bool
178we = add t1 1
179wi = add t0 1
180while and lt wi we not sv_anstp s wi bound 999999
181wi = add wi 1
182end
183while true bound 999999
184while and lt wi we or sv_aws sv_bat s wi eq sv_bat s wi 47 bound 999999
185wi = add wi 1
186end
187if or ge wi we eq sv_bat s wi 62
188ret false
189end
190wst = wi
191while and lt wi we not sv_anend s wi bound 999999
192wi = add wi 1
193end
194if eq sub wi wst len name
195if sv_eqatc s wst name
196ret true
197end
198end
199wi = sv_anval s wi we
200end
201ret false
202end
203fn sv_anval s ulong wi ulong we ulong to ulong
204while and lt wi we sv_aws sv_bat s wi bound 999999
205wi = add wi 1
206end
207if and lt wi we eq sv_bat s wi 61
208wi = add wi 1
209while and lt wi we sv_aws sv_bat s wi bound 999999
210wi = add wi 1
211end
212wq = sv_bat s wi
213if and lt wi we or eq wq 34 eq wq 39
214wi = add wi 1
215while and lt wi we ne sv_bat s wi wq bound 999999
216wi = add wi 1
217end
218ret add wi 1
219end
220while and lt wi we not or sv_aws sv_bat s wi eq sv_bat s wi 62 bound 999999
221wi = add wi 1
222end
223end
224ret wi
225end
226note sv_eend: oracle.rs element_end(html, body, name) with name in vtn: index just past the
227note matching close tag (ASCII case-insensitive), counting nested opens; VNONE.
228fn sv_eend s ulong body ulong to ulong
229wd = ulong 1
230wi = body
231wn = get vtnn 0
232while true bound 999999
233wl = sv_findb2 s 60 wi
234if eq wl VNONE
235ret VNONE
236end
237if sv_isclose s wl
238wd = sub wd 1
239if eq wd 0
240ret add add wl 3 wn
241end
242else
243if sv_isopen s wl
244wd = add wd 1
245end
246end
247wi = add wl 1
248end
249ret VNONE
250end
251fn sv_vtnat s ulong i ulong to bool
252wn = get vtnn 0
253if gt add i wn sv_n s
254ret false
255end
256for wj ulong wn
257if ne sv_lc sv_b s add i wj get vtn wj
258ret false
259end
260end
261ret true
262end
263fn sv_isclose s ulong wl ulong to bool
264if ne sv_bat s add wl 1 47
265ret false
266end
267if not sv_vtnat s add wl 2
268ret false
269end
270ret eq sv_bat s add add wl 2 get vtnn 0 62
271end
272fn sv_isopen s ulong wl ulong to bool
273if not sv_vtnat s add wl 1
274ret false
275end
276wi = add add wl 1 get vtnn 0
277if ge wi sv_n s
278ret false
279end
280c = sv_b s wi
281ret or sv_awsr c eq c 47
282end
283
284note ---------------------------------------------------------------- strip
285note sv_strip: oracle.rs strip(html, drop, hidden) over slot s. Flags: 1 script, 2 style,
286note 4 template, 8 noscript dropped; 16 hidden (the hidden attribute or aria-hidden="true").
287note markup = 7, reachable = 31, the noscript source = 23, reader text = 23, page_assets = 0.
288fn sv_dropn fl ulong to bool
289if and ne and fl 1 0 sv_tnis vxscr
290ret true
291end
292if and ne and fl 2 0 sv_tnis vxsty
293ret true
294end
295if and ne and fl 4 0 sv_tnis vxtpl
296ret true
297end
298ret and ne and fl 8 0 sv_tnis vxnos
299end
300fn sv_strip s ulong fl ulong to ulong
301wo = sv_snew
302wi = ulong 0
303wn = sv_n s
304while lt wi wn bound 999999
305wl = sv_findb2 s 60 wi
306if eq wl VNONE
307break
308end
309sv_pusha add sv_off s wi sub wl wi
310wi = sv_strip1 s fl wl
311end
312if lt wi wn
313sv_pusha add sv_off s wi sub wn wi
314end
315ret wo
316end
317note sv_strip1: one '<' at wl: push what the pass keeps, return where scanning resumes.
318fn sv_strip1 s ulong fl ulong wl ulong to ulong
319wn = sv_n s
320if sv_eqat s wl vxcom
321wz = sv_find s vxcomx wl
322sv_push 32
323if eq wz VNONE
324ret wn
325end
326ret add wz 3
327end
328wnl = sv_tname s wl
329wg = sv_tagend s wl
330if eq wg VNONE
331ret wn
332end
333wop = and gt wnl 0 not or eq sv_bat s add wl 1 47 eq sv_bat s add wl 1 33
334whide = false
335if wop
336whide = sv_dropn fl
337if and not whide ne and fl 16 0
338whide = or sv_anames s wl wg vxhid sv_aeq s sv_attr s wl wg vxah vxtrue
339end
340end
341if whide
342sv_push 32
343if or sv_tnin vxvoid eq sv_b s sub wg 1 47
344ret add wg 1
345end
346wz = sv_eend s add wg 1
347if eq wz VNONE
348ret wn
349end
350ret wz
351end
352sv_pusha add sv_off s wl add sub wg wl 1
353ret add wg 1
354end
355
356note ---------------------------------------------------------------- reader text
357fn sv_slot1 a ulong b ulong src ulong to ulong
358ws = sv_snew
359sv_pusha add sv_off src a sub b a
360ret ws
361end
362note sv_coll: move slot g (the newest) down onto slot f and pop everything above f.
363fn sv_coll f ulong g ulong to void
364wn = sv_n g
365wfo = sv_off f
366wgo = sv_off g
367sv_amove wfo wgo wn
368put vns 0 add f 1
369put vsn f wn
370put vtop 0 add wfo wn
371end
372note sv_untag: in place, '<' opens a tag, '>' in a tag becomes one space (oracle reader_text).
373fn sv_untag s ulong to void
374wo = sv_off s
375wn = sv_n s
376wout = ulong 0
377win = false
378for wi ulong wn
379c = get va add wo wi
380if eq c 60
381win = true
382else
383if and eq c 62 win
384win = false
385put va add wo wout 32
386wout = add wout 1
387else
388if not win
389put va add wo wout c
390wout = add wout 1
391end
392end
393end
394end
395sv_trunc s wout
396end
397note sv_aput: copy rep into the arena at dst (split out of sv_repl for registers).
398fn sv_aput dst ulong rep view uchar * to void
399for wj ulong len rep
400put va add dst wj get rep wj
401end
402end
403note sv_repl: in place, every non-overlapping pat (left to right) becomes rep (len rep <= len pat).
404fn sv_repl s ulong pat view uchar * rep view uchar * to void
405note the slot offset and length are read per use (unchanged until sv_trunc): register budget.
406wout = ulong 0
407wi = ulong 0
408while lt wi sv_n s bound 64
409wk = ulong 0
410while and lt wi sv_n s lt wk 262144 bound 262144
411if sv_eqat s wi pat
412sv_aput add sv_off s wout rep
413wout = add wout len rep
414wi = add wi len pat
415else
416sv_amove add sv_off s wout add sv_off s wi 1
417wout = add wout 1
418wi = add wi 1
419end
420wk = add wk 1
421end
422end
423sv_trunc s wout
424end
425fn sv_ents s ulong t view uchar * to void
426wk = ulong 0
427note wrep: the replacement half of one pair; omc error 19 refuses two parts of t in one call.
428wrep = new uchar 64 0
429while lt wk sv_tcount t bound 64
430wa = sv_tat t wk
431wb = sv_tat t add wk 1
432wn = sv_tlen t wb
433if gt wn 64
434trap 10
435end
436for wj ulong wn
437put wrep wj get t add wb wj
438end
439sv_repl s part t wa sv_tlen t wa part wrep 0 wn
440wk = add wk 2
441end
442end
443note sv_rtext: oracle reader_text of [a, b) in slot src, as a new slot.
444fn sv_rtext src ulong a ulong b ulong to ulong
445wf = sv_slot1 a b src
446wg = sv_strip wf 23
447sv_untag wg
448sv_ents wg vxent1
449sv_squash wg
450sv_coll wf wg
451ret wf
452end
453
454note ---------------------------------------------------------------- anchors
455note sv_anx: the next anchor at or after i in [0, lim) of slot r (oracle anchors over the prefix
456note r[..lim]). Returns its '<' or VNONE; vax[0] = '>' of the open tag, vax[1] = the close (or lim),
457note vax[2] = href offset or VNONE, vax[3] = href length.
458fn sv_anx r ulong i ulong lim ulong to ulong
459while true bound 999999
460wa = sv_findx r vxa i lim true
461if eq wa VNONE
462ret VNONE
463end
464i = add wa 2
465if lt i lim
466if sv_awsr sv_lc sv_b r i
467wg = sv_findb2 r 62 wa
468if or eq wg VNONE ge wg lim
469ret VNONE
470end
471wc = sv_findx r vxaend wg lim true
472if eq wc VNONE
473wc = lim
474end
475put vax 0 wg
476put vax 1 wc
477put vax 2 sv_attr r wa wg vxhref
478put vax 3 get vav 0
479ret wa
480end
481end
482end
483ret VNONE
484end
485fn sv_hrefis r ulong want view uchar * to bool
486if eq get vax 2 VNONE
487ret eq len want 0
488end
489if ne get vax 3 len want
490ret false
491end
492ret sv_eqat r get vax 2 want
493end
494note sv_alink: first anchor from i in r[..lim] with href == want whose reader text satisfies mode:
495note 0 not empty, 1 contains 'X', 2 equals the label set by sv_setlab. Returns the index after it
496note (its close) or VNONE.
497fn sv_setlab label view uchar * to void
498if gt len label len vlab
499sr_fail vtcap
500end
501for wj ulong len label
502put vlab wj get label wj
503end
504put vlabn 0 len label
505end
506fn sv_labis t ulong to bool
507if ne sv_n t get vlabn 0
508ret false
509end
510for wj ulong sv_n t
511if ne sv_b t wj get vlab wj
512ret false
513end
514end
515ret true
516end
517fn sv_alink r ulong i ulong lim ulong want view uchar * mode ulong to ulong
518while true bound 999999
519wa = sv_anx r i lim
520if eq wa VNONE
521ret VNONE
522end
523wc = get vax 1
524if sv_hrefis r want
525wt = sv_rtext r add get vax 0 1 wc
526wok = gt sv_n wt 0
527if eq mode 1
528wok = ne sv_findb wt 88 VNONE
529end
530if eq mode 2
531wok = sv_labis wt
532end
533sv_drop wt
534if wok
535ret wc
536end
537end
538i = wc
539end
540ret VNONE
541end
542
543note ---------------------------------------------------------------- classes and ids
544note sv_fclass: oracle find_class: the first tag from i (not </ or <!) whose class attribute holds
545note token as an ASCII-whitespace-separated word; returns its '<' (vax[0] = its '>'), VNONE.
546fn sv_fclass s ulong i ulong token view uchar * to ulong
547while true bound 999999
548wl = sv_findb2 s 60 i
549if eq wl VNONE
550ret VNONE
551end
552wg = sv_tagend s wl
553if eq wg VNONE
554ret VNONE
555end
556wc = sv_bat s add wl 1
557if not or eq wc 47 eq wc 33
558wv = sv_attr s wl wg vxclass
559if ne wv VNONE
560if sv_hastok s wv get vav 0 token false
561put vax 0 wg
562ret wl
563end
564end
565end
566i = add wg 1
567end
568ret VNONE
569end
570note sv_hastok: the value [v, v+n) split on whitespace (ASCII, or Unicode when uni) holds token.
571fn sv_hastok s ulong v ulong n ulong token view uchar * uni bool to bool
572wi = v
573we = add v n
574while lt wi we bound 999999
575while and lt wi we sv_tokws s wi uni bound 999999
576wi = add wi sv_cpl s wi
577end
578wst = wi
579while and lt wi we not sv_tokws s wi uni bound 999999
580wi = add wi sv_cpl s wi
581end
582if and gt wi wst eq sub wi wst len token
583if sv_eqat s wst token
584ret true
585end
586end
587end
588ret false
589end
590fn sv_tokws s ulong i ulong uni bool to bool
591if uni
592ret sv_ins sv_cp s i
593end
594ret sv_aws sv_b s i
595end
596note sv_hasid: oracle has_id over the markup slot m (already stripped with flags 7).
597fn sv_hasid m ulong id view uchar * to bool
598wi = ulong 0
599while true bound 999999
600wl = sv_findb2 m 60 wi
601if eq wl VNONE
602ret false
603end
604wg = sv_tagend m wl
605if eq wg VNONE
606ret false
607end
608if ne sv_bat m add wl 1 47
609if sv_aeq m sv_attr m wl wg vxid id
610ret true
611end
612end
613wi = add wg 1
614end
615ret false
616end
617note sv_mains: the number of "<main" followed by > or whitespace in r (ASCII case-insensitive),
618note vax[0] = the first one.
619fn sv_mains r ulong to ulong
620wc = ulong 0
621wi = ulong 0
622while true bound 999999
623wm = sv_findc r vxmain wi
624if eq wm VNONE
625ret wc
626end
627if sv_awsr sv_lc sv_bat r add wm 5
628if eq wc 0
629put vax 0 wm
630end
631wc = add wc 1
632end
633wi = add wm 1
634end
635ret wc
636end