2title = "4i: Parsing (Useful Idioms)"
10Parse alphabetic characters, both upper and lowercase.
15 ++ alf ;~(pose low hig) :: alphabetic
27 > (scan "AaBbCc" (star alf))
35Alphanumeric characters
37Parse alphanumeric characters - both alphabetic characters and numbers.
42 ++ aln ;~(pose low hig nud) :: alphanumeric
51 > (scan "alf42" (star aln))
54 > (scan "0123456789abcdef" (star aln))
64Parse alphanumeric strings and hep, "-".
69 ++ alp ;~(pose low hig nud hep) :: alphanumeric and -
81 > (scan "123abc-" (star alp))
92Parse the hep and lus axis syntax.
97 ++ bet ;~(pose (cold 2 hep) (cold 3 lus)) :: axis syntax - +
116Parse a tape of binary (0s and 1s) and produce its atomic representation.
121 ++ bin (bass 2 (most gon but)) :: binary to atom
136 > (scan "100000001111" bin)
146Parse a single binary digit.
151 ++ but (cook |=(a=@ (sub a '0')) (shim '0' '1')) :: binary digit
165 > (scan "01" (star but))
175Parse a single octal digit.
180 ++ cit (cook |=(a=@ (sub a '0')) (shim '0' '7')) :: octal digit
194 > (scan "60" (star cit))
204Parse a decimal number to an atom.
209 ++ dem (bass 10 (most gon dit)) :: decimal to atom
219 > (scan "150000000" dem)
231Parse a single decimal digit.
236 ++ dit (cook |=(a=@ (sub a '0')) (shim '0' '9')) :: decimal digit
244 > (scan "42" (star dit))
246 > (scan "26000" (star dit))
256Dot followed by an optional gap, used with numbers.
261 ++ dog ;~(plug dot gay) ::
271 > (scan "a. " ;~(pfix alf dog))
281Phonetic base phrase separator
286 ++ doh ;~(plug ;~(plug hep hep) gay) ::
292 /> ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
293 ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
294 /> ~nopfel-botduc-nilnev-dolfyn--
295 haspub-natlun-lodmur-holtyd
296 ~nopfel-botduc-nilnev-dolfyn--haspub-natlun-lodmur-holtyd
309Parse phep, `--`, to null, `~`.
314 ++ dun (cold ~ ;~(plug hep hep)) :: -- (phep) to ~
323 [p=[p=1 q=3] q=[~ u=[p=~ q=[p=[p=1 q=3] q=""]]]]
333Parse stet, `==`, to null `~`.
338 ++ duz (cold ~ ;~(plug tis tis)) :: == (stet) to ~
346 > (duz [[1 1] "== |=..."])
347 [p=[p=1 q=3] q=[~ u=[p=~ q=[p=[p=1 q=3] q=" |=..."]]]]
357Whitespace component, either newline or space.
362 ++ gah (mask [`@`10 ' ' ~]) :: newline or ace
368 /> ^- * :: show spaces
374 [32 32 32 45 10 32 45 10 32 32 45 0]
379 [32 32 32 10 32 10 32 32 0]
381 %- scan :_ (star gah)
385 ~[32 32 32 10 32 10 32 32]
399 ++ gap (cold ~ ;~(plug gaq (star ;~(pose vul gah)))) :: plural whitespace
408Two spaces, a newline, or comment.
413 ++ gaq ;~ pose :: end of line
415 ;~(plug gah ;~(pose gah vul))
432 ++ gaw (cold ~ (star ;~(pose vul gah))) :: classic white
446 ++ gay ;~(pose gap (easy ~)) ::
454Parse long numbers - Numbers which wrap around the shell with the line
459 ++ gon ;~(pose ;~(plug bas gay fas) (easy ~)) :: long numbers \ /
468 > (gon [[1 1] "\\/"])
469 [p=[p=1 q=3] q=[~ u=[p=[~~~5c. ~ ~~~2f.] q=[p=[p=1 q=3] q=""]]]]
476Axis syntax `<` or `>`
478Parse the axis gal and gar axis syntax.
483 ++ gul ;~(pose (cold 2 gal) (cold 3 gar)) :: axis syntax < >
502Parse any hexadecimal number to an atom.
507 ++ hex (bass 16 (most gon hit)) :: hex to atom
523 > (scan "1EE7F7" hex)
525 > `@ux`(scan "1EE7F7" hex)
534Parse a single uppercase letter.
539 ++ hig (shim 'A' 'Z') :: uppercase
548 > `cord`(scan "G" hig)
551 > (scan "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (star hig))
552 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
555 [p=[p=1 q=2] q=[~ [p=~~~47. q=[p=[p=1 q=2] q=""]]]]
564Parse a single hexadecimal digit.
569 ++ hit ;~ pose :: hex digits
571 (cook |=(a=char (sub a 87)) (shim 'a' 'f'))
572 (cook |=(a=char (sub a 55)) (shim 'A' 'F'))
584 [p=[p=1 q=2] q=[~ [p=10 q=[p=[p=1 q=2] q=""]]]]
585 > (scan "2A" (star hit))
594Apply `++rule` to indented block starting at current column number, omitting
595the leading whitespace.
608 ++ inde |* sef/rule :: indentation block
610 =+ [har tap]=[p q]:+<
611 =+ lev=(fil 3 (dec q.har) ' ')
613 =+ =- roq=((star ;~(pose prn ;~(sfix eol (jest lev)) -)) har tap)
614 ;~(simu ;~(plug eol eol) eol)
616 =+ vex=(sef har(q 1) p.u.q.roq)
617 =+ fur=p.vex(q (add (dec q.har) q.p.vex))
621 &4.vex(q.p (add (dec q.har) q.p.&4.vex))
624 ?. =(10 -.res) [-.res $(res +.res)]
625 (welp [`@t`10 (trip lev)] $(res +.res))
632 > (scan "abc" (iny (star ;~(pose prn (just `@`10)))))
634 > (scan "abc" (star ;~(pose prn (just `@`10))))
636 > (scan " abc\0ade" ;~(pfix ace ace (star ;~(pose prn (just `@`10)))))
639 > (scan " abc\0ade" ;~(pfix ace ace (iny (star ;~(pose prn (just `@`10))))))
642 > (scan " abc\0a de" ;~(pfix ace ace (iny (star ;~(pose prn (just `@`10))))))
653Parse a single lowercase letter.
658 ++ low (shim 'a' 'z') :: lowercase
666 > `cord`(scan "g" low)
668 > (scan "abcdefghijklmnopqrstuvwxyz" (star low))
669 "abcdefghijklmnopqrstuvwxyz"
671 [p=[p=1 q=2] q=[~ [p=~~g q=[p=[p=1 q=2] q=""]]]]
685 ++ mes %+ cook :: hexbyte
686 |=({a/@ b/@} (add (mul 16 a) b))
696 [p=[p=1 q=3] q=[~ u=[p=42 q=[p=[p=1 q=3] q=""]]]]
707Parse Letters and `-`.
712 ++ nix (boss 256 (star ;~(pose aln cab))) ::
721 > `@t`(scan "as_me" nix)
732Parse a numeric character - A number.
737 ++ nud (shim '0' '9') :: numeric
748 [p=[p=1 q=2] q=[~ [p=~~1 q=[p=[p=1 q=2] q=""]]]]
749 > (scan "0123456789" (star nud))
758Parse any printable character.
763 ++ prn ;~(less (just `@`127) (shim 32 256))
784Parse an individual character to its cord atom representation.
789 ++ qit ;~ pose :: chars in a cord
791 ;~(pfix bas ;~(pose bas soq mes)) :: escape chars
810 > `@ux`(scan "\\0a" qit)
812 > (scan "cord" (star qit))
822Parse an individual character to its cord atom representation.
827 ++ qit ;~ pose :: chars in a cord
829 ;~(pfix bas ;~(pose bas soq mes)) :: escape chars
848 > `@ux`(scan "\\0a" qit)
850 > (scan "cord" (star qit))
861Parse single-soq cord with `\{gap}/` anywhere in the middle, or triple-single
862quote (aka triple-soq) cord, between which must be in an indented block.
867 ++ qut ;~ pose :: cord
869 (ifix [soq soq] (boss 256 (more gon qit)))
873 ;~(pose ;~(plug (plus ace) vul) (just '\0a'))
875 ;~(plug (just '\0a') soqs)
876 (boss 256 (star qat))
884 > (scan "'cord'" qut)
891 Heredoc isn't prohibited from containing quotes
893 'Heredoc isn't prohibited from containing quotes'
902Parse a triple-single quote, used for multiline strings.
907 ++ soz ;~(plug soq soq soq) :: delimiting '''
914 [~~~27. ~~~27. ~~~27.]
926A term: a letter(lowercase), followed by letters, numbers, or `-`.
933 |=(a=tape (rap 3 ^-((list ,@) a)))
934 ;~(plug low (star ;~(pose nud low hep)))
943 > `@t`(scan "sam-2" sym)
960 ++ ven ;~ (comp |=({a/@ b/@} (peg a b))) :: +>- axis syntax
965 =+ vex=?:(hom (bet tub) (gul tub))
968 =+ wag=$(p.tub p.vex, hom !hom, tub q.u.q.vex)
970 [p.wag [~ (peg p.u.q.vex p.u.q.wag) q.u.q.wag]]
977 ~zod/arvo=/hoon/hoon> (scan "->+" ven)
980 ~zod/arvo=/hoon/hoon> `@ub`(scan "->+" ven)
983 ~zod/arvo=/hoon/hoon> (peg (scan "->" ven) (scan "+" ven))
986 ~zod/arvo=/hoon/hoon> ->+:[[1 2 [3 4]] 5]
996Parse a standard base64 digit.
1001 ++ vit :: base64 digit
1003 (cook |=(a/@ (sub a 65)) (shim 'A' 'Z'))
1004 (cook |=(a/@ (sub a 71)) (shim 'a' 'z'))
1005 (cook |=(a/@ (add a 4)) (shim '0' '9'))
1006 (cold 62 (just '-'))
1007 (cold 63 (just '+'))
1014 ~zod/arvo=/hoon/hoon> (scan "C" vit)
1016 ~zod/arvo=/hoon/hoon> (scan "c" vit)
1018 ~zod/arvo=/hoon/hoon> (scan "2" vit)
1020 ~zod/arvo=/hoon/hoon> (scan "-" vit)
1032 ++ vul %+ cold ~ :: comments
1039Parse comments and produce a null. Note that a comment must be ended
1040with a newline character.
1045 > (scan "::this is a comment \0a" vul)
1047 > (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