2title = "4i: Parsing (Useful Idioms)"
11Parse alphabetic characters, both upper and lowercase.
16 ++ alf ;~(pose low hig) :: alphabetic
28 > (scan "AaBbCc" (star alf))
36Alphanumeric characters
38Parse alphanumeric characters - both alphabetic characters and numbers.
43 ++ aln ;~(pose low hig nud) :: alphanumeric
52 > (scan "alf42" (star aln))
55 > (scan "0123456789abcdef" (star aln))
65Parse alphanumeric strings and hep, "-".
70 ++ alp ;~(pose low hig nud hep) :: alphanumeric and -
82 > (scan "123abc-" (star alp))
93Parse the hep and lus axis syntax.
98 ++ bet ;~(pose (cold 2 hep) (cold 3 lus)) :: axis syntax - +
117Parse a tape of binary (0s and 1s) and produce its atomic representation.
122 ++ bin (bass 2 (most gon but)) :: binary to atom
137 > (scan "100000001111" bin)
147Parse a single binary digit.
152 ++ but (cook |=(a=@ (sub a '0')) (shim '0' '1')) :: binary digit
166 > (scan "01" (star but))
176Parse a single octal digit.
181 ++ cit (cook |=(a=@ (sub a '0')) (shim '0' '7')) :: octal digit
195 > (scan "60" (star cit))
205Parse a decimal number to an atom.
210 ++ dem (bass 10 (most gon dit)) :: decimal to atom
220 > (scan "150000000" dem)
232Parse a single decimal digit.
237 ++ dit (cook |=(a=@ (sub a '0')) (shim '0' '9')) :: decimal digit
245 > (scan "42" (star dit))
247 > (scan "26000" (star dit))
257Dot followed by an optional gap, used with numbers.
262 ++ dog ;~(plug dot gay) ::
272 > (scan "a. " ;~(pfix alf dog))
282Phonetic base phrase separator
287 ++ doh ;~(plug ;~(plug hep hep) gay) ::
293 /> ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
294 ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
295 /> ~nopfel-botduc-nilnev-dolfyn--
296 haspub-natlun-lodmur-holtyd
297 ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
310Parse phep, `--`, to null, `~`.
315 ++ dun (cold ~ ;~(plug hep hep)) :: -- (phep) to ~
324 [p=[p=1 q=3] q=[~ u=[p=~ q=[p=[p=1 q=3] q=""]]]]
334Parse stet, `==`, to null `~`.
339 ++ duz (cold ~ ;~(plug tis tis)) :: == (stet) to ~
347 > (duz [[1 1] "== |=..."])
348 [p=[p=1 q=3] q=[~ u=[p=~ q=[p=[p=1 q=3] q=" |=..."]]]]
358Whitespace component, either newline or space.
363 ++ gah (mask [`@`10 ' ' ~]) :: newline or ace
369 /> ^- * :: show spaces
375 [32 32 32 45 10 32 45 10 32 32 45 0]
380 [32 32 32 10 32 10 32 32 0]
382 %- scan :_ (star gah)
386 ~[32 32 32 10 32 10 32 32]
400 ++ gap (cold ~ ;~(plug gaq (star ;~(pose vul gah)))) :: plural whitespace
409Two spaces, a newline, or comment.
414 ++ gaq ;~ pose :: end of line
416 ;~(plug gah ;~(pose gah vul))
433 ++ gaw (cold ~ (star ;~(pose vul gah))) :: classic white
447 ++ gay ;~(pose gap (easy ~)) ::
455Parse long numbers - Numbers which wrap around the shell with the line
460 ++ gon ;~(pose ;~(plug bas gay fas) (easy ~)) :: long numbers \ /
469 > (gon [[1 1] "\\/"])
470 [p=[p=1 q=3] q=[~ u=[p=[~~~5c. ~ ~~~2f.] q=[p=[p=1 q=3] q=""]]]]
477Axis syntax `<` or `>`
479Parse the axis gal and gar axis syntax.
484 ++ gul ;~(pose (cold 2 gal) (cold 3 gar)) :: axis syntax < >
503Parse any hexadecimal number to an atom.
508 ++ hex (bass 16 (most gon hit)) :: hex to atom
524 > (scan "1EE7F7" hex)
526 > `@ux`(scan "1EE7F7" hex)
535Parse a single uppercase letter.
540 ++ hig (shim 'A' 'Z') :: uppercase
549 > `cord`(scan "G" hig)
552 > (scan "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (star hig))
553 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
556 [p=[p=1 q=2] q=[~ [p=~~~47. q=[p=[p=1 q=2] q=""]]]]
565Parse a single hexadecimal digit.
570 ++ hit ;~ pose :: hex digits
572 (cook |=(a=char (sub a 87)) (shim 'a' 'f'))
573 (cook |=(a=char (sub a 55)) (shim 'A' 'F'))
585 [p=[p=1 q=2] q=[~ [p=10 q=[p=[p=1 q=2] q=""]]]]
586 > (scan "2A" (star hit))
595Apply `++rule` to indented block starting at current column number, omitting
596the leading whitespace.
609 ++ inde |* sef/rule :: indentation block
611 =+ [har tap]=[p q]:+<
612 =+ lev=(fil 3 (dec q.har) ' ')
614 =+ =- roq=((star ;~(pose prn ;~(sfix eol (jest lev)) -)) har tap)
615 ;~(simu ;~(plug eol eol) eol)
617 =+ vex=(sef har(q 1) p.u.q.roq)
618 =+ fur=p.vex(q (add (dec q.har) q.p.vex))
622 &4.vex(q.p (add (dec q.har) q.p.&4.vex))
625 ?. =(10 -.res) [-.res $(res +.res)]
626 (welp [`@t`10 (trip lev)] $(res +.res))
633 > (scan "abc" (iny (star ;~(pose prn (just `@`10)))))
635 > (scan "abc" (star ;~(pose prn (just `@`10))))
637 > (scan " abc\0ade" ;~(pfix ace ace (star ;~(pose prn (just `@`10)))))
640 > (scan " abc\0ade" ;~(pfix ace ace (iny (star ;~(pose prn (just `@`10))))))
643 > (scan " abc\0a de" ;~(pfix ace ace (iny (star ;~(pose prn (just `@`10))))))
654Parse a single lowercase letter.
659 ++ low (shim 'a' 'z') :: lowercase
667 > `cord`(scan "g" low)
669 > (scan "abcdefghijklmnopqrstuvwxyz" (star low))
670 "abcdefghijklmnopqrstuvwxyz"
672 [p=[p=1 q=2] q=[~ [p=~~g q=[p=[p=1 q=2] q=""]]]]
686 ++ mes %+ cook :: hexbyte
687 |=({a/@ b/@} (add (mul 16 a) b))
697 [p=[p=1 q=3] q=[~ u=[p=42 q=[p=[p=1 q=3] q=""]]]]
708Parse Letters and `-`.
713 ++ nix (boss 256 (star ;~(pose aln cab))) ::
722 > `@t`(scan "as_me" nix)
733Parse a numeric character - A number.
738 ++ nud (shim '0' '9') :: numeric
749 [p=[p=1 q=2] q=[~ [p=~~1 q=[p=[p=1 q=2] q=""]]]]
750 > (scan "0123456789" (star nud))
759Parse any printable character.
764 ++ prn ;~(less (just `@`127) (shim 32 256))
785Parse an individual character to its cord atom representation.
790 ++ qit ;~ pose :: chars in a cord
792 ;~(pfix bas ;~(pose bas soq mes)) :: escape chars
811 > `@ux`(scan "\\0a" qit)
813 > (scan "cord" (star qit))
823Parse an individual character to its cord atom representation.
828 ++ qit ;~ pose :: chars in a cord
830 ;~(pfix bas ;~(pose bas soq mes)) :: escape chars
849 > `@ux`(scan "\\0a" qit)
851 > (scan "cord" (star qit))
862Parse single-soq cord with `\{gap}/` anywhere in the middle, or triple-single
863quote (aka triple-soq) cord, between which must be in an indented block.
868 ++ qut ;~ pose :: cord
870 (ifix [soq soq] (boss 256 (more gon qit)))
874 ;~(pose ;~(plug (plus ace) vul) (just '\0a'))
876 ;~(plug (just '\0a') soqs)
877 (boss 256 (star qat))
885 > (scan "'cord'" qut)
892 Heredoc isn't prohibited from containing quotes
894 'Heredoc isn't prohibited from containing quotes'
903Parse a triple-single quote, used for multiline strings.
908 ++ soz ;~(plug soq soq soq) :: delimiting '''
915 [~~~27. ~~~27. ~~~27.]
927A term: a letter(lowercase), followed by letters, numbers, or `-`.
934 |=(a=tape (rap 3 ^-((list ,@) a)))
935 ;~(plug low (star ;~(pose nud low hep)))
944 > `@t`(scan "sam-2" sym)
961 ++ ven ;~ (comp |=({a/@ b/@} (peg a b))) :: +>- axis syntax
966 =+ vex=?:(hom (bet tub) (gul tub))
969 =+ wag=$(p.tub p.vex, hom !hom, tub q.u.q.vex)
971 [p.wag [~ (peg p.u.q.vex p.u.q.wag) q.u.q.wag]]
978 ~zod/arvo=/hoon/hoon> (scan "->+" ven)
981 ~zod/arvo=/hoon/hoon> `@ub`(scan "->+" ven)
984 ~zod/arvo=/hoon/hoon> (peg (scan "->" ven) (scan "+" ven))
987 ~zod/arvo=/hoon/hoon> ->+:[[1 2 [3 4]] 5]
997Parse a standard base64 digit.
1002 ++ vit :: base64 digit
1004 (cook |=(a/@ (sub a 65)) (shim 'A' 'Z'))
1005 (cook |=(a/@ (sub a 71)) (shim 'a' 'z'))
1006 (cook |=(a/@ (add a 4)) (shim '0' '9'))
1007 (cold 62 (just '-'))
1008 (cold 63 (just '+'))
1015 ~zod/arvo=/hoon/hoon> (scan "C" vit)
1017 ~zod/arvo=/hoon/hoon> (scan "c" vit)
1019 ~zod/arvo=/hoon/hoon> (scan "2" vit)
1021 ~zod/arvo=/hoon/hoon> (scan "-" vit)
1033 ++ vul %+ cold ~ :: comments
1040Parse comments and produce a null. Note that a comment must be ended
1041with a newline character.
1046 > (scan "::this is a comment \0a" vul)
1048 > (scan "::this is a comment " vul)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list