2title = "4i: Parsing (Useful Idioms)"
11Parse alphabetic characters, both upper and lowercase.
16++ alf ;~(pose low hig)
28> `tape`(scan "AaBbCc" (star alf))
36Alphanumeric characters
38Parse alphanumeric characters - both alphabetic characters and numbers.
43++ aln ;~(pose low hig nud)
52> `tape`(scan "alf42" (star aln))
62Parse alphanumeric strings and hep, "-".
67++ alp ;~(pose low hig nud hep)
79> `tape`(scan "123abc-" (star alp))
89Parse the hep and lus axis syntax.
94++ bet ;~(pose (cold 2 hep) (cold 3 lus))
113Parse a tape of binary (0s and 1s) and produce its atomic representation.
118++ bin (bass 2 (most gon but))
133> (scan "100000001111" bin)
143Parse a single binary digit.
148++ but (cook |=(a=@ (sub a '0')) (shim '0' '1'))
165> (scan "01" (star but))
175Parse a single octal digit.
180++ cit (cook |=(a=@ (sub a '0')) (shim '0' '7'))
194> (scan "60" (star cit))
204Parse a decimal number to an atom.
209++ dem (bass 10 (most gon dit))
221> (scan "150000000" dem)
234Parse a single decimal digit.
239++ dit (cook |=(a=@ (sub a '0')) (shim '0' '9'))
248> (scan "42" (star dit))
251> (scan "26000" (star dit))
261Dot followed by an optional gap, used with numbers.
266++ dog ;~(plug dot gay)
275> (scan "a. " ;~(pfix alf dog))
285Hep followed by an optional gap, used with `@p` & `@q` syntax.
290++ dof ;~(plug hep gay)
309Phonetic base phrase separator
314++ doh ;~(plug ;~(plug hep hep) gay)
333Parse phep, `--`, to null, `~`.
338++ dun (cold ~ ;~(plug hep hep))
354Parse stet, `==`, to null `~`.
359++ duz (cold ~ ;~(plug tis tis))
375Whitespace component, either newline or space.
380++ gah (mask [`@`10 ' ' ~])
386> `tape`(scan " \0a \0a" (star gah))
401++ gap (cold ~ ;~(plug gaq (star ;~(pose vul gah))))
407> `tape`(scan " \0a \0a" gap)
410> (scan "\0a \0a XYZ" ;~(pfix gap (jest 'XYZ')))
420Two spaces, a newline, or comment.
427 ;~(plug gah ;~(pose gah vul))
435> (scan "123\0a" ;~(sfix dem gaq))
438> (scan "123 :: foo\0a" ;~(sfix dem gaq))
453++ gaw (cold ~ (star ;~(pose vul gah)))
459> (scan " \0a :: foo \0a" gaw)
480++ gay ;~(pose gap (easy ~))
505Parse long numbers - Numbers which wrap around the shell with the line
510++ gon ;~(pose ;~(plug bas gay fas) (easy ~))
528Axis syntax `<` or `>`
530Parse the axis gal and gar axis syntax.
535++ gul ;~(pose (cold 2 gal) (cold 3 gar))
554Parse any hexadecimal number to an atom.
559++ hex (bass 16 (most gon hit))
583> `@ux`(scan "1EE7F7" hex)
593Parse a single uppercase letter.
607> (scan "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (star hig))
608"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
617Parse a single hexadecimal digit.
624 (cook |=(a=char (sub a 87)) (shim 'a' 'f'))
625 (cook |=(a=char (sub a 55)) (shim 'A' 'F'))
638> (scan "2A" (star hit))
648Apply `rule` to indented block starting at current column number, omitting
649the leading whitespace.
665 =+ [har tap]=[p q]:+<
666 =+ lev=(fil 3 (dec q.har) ' ')
668 =+ =- roq=((star ;~(pose prn ;~(sfix eol (jest lev)) -)) har tap)
669 ;~(simu ;~(plug eol eol) eol)
671 =+ vex=(sef har(q 1) p.u.q.roq)
672 =+ fur=p.vex(q (add (dec q.har) q.p.vex))
676 &4.vex(q.p (add (dec q.har) q.p.&4.vex))
679 ?. =(10 -.res) [-.res $(res +.res)]
680 (welp [`@t`10 (trip lev)] $(res +.res))
686> `tape`(scan " foo\0a bar" ;~(pfix ace ace ace (iny (star ;~(pose prn (just '\0a'))))))
692Note the amount of indentation whitespace to be stripped from the beginning of
693each line is determined by the value of `q` (the column) in the `hair` when
694`++iny` is first called. This means something like the `pfix` expression in the
695example above is necessary to set the level of indentation. Additionally, the
696`rule` given to `++iny` must consume the whole line including the line ending.
704Parse a single lowercase letter.
731 |=({a/@ b/@} (add (mul 16 a) b))
749Letters and underscore
751Parse Letters and `_`.
756++ nix (boss 256 (star ;~(pose aln cab)))
762> `@t`(scan "as_me" nix)
772Parse a numeric character - A number.
796Parse any printable character.
801++ prn ;~(less (just `@`127) (shim 32 256))
824Parse a single character contained in a mult-line cord block.
831 ;~(less ;~(plug (just `@`10) soz) (just `@`10))
840 "'''\0aabc\0adef\0aghi\0a'''"
842 :- ;~(plug soz (just `@`10))
843 ;~(plug (just `@`10) soz)
854Parse an individual character to its cord atom representation. Escaped
855characters are converted to the value they represent.
860++ qit ;~ pose :: chars in a cord
862 ;~(pfix bas ;~(pose bas soq mes)) :: escape chars
872> `tape`(scan "cord" (star qit))
875> `tape`(scan "\\0a" (star qit))
885Parse single-soq cord with `\{gap}/` anywhere in the middle, or triple-single
886quote (aka triple-soq) cord, between which must be in an indented block.
894 (ifix [soq soq] (boss 256 (more gon qit)))
896 =+ hed=;~(pose ;~(plug (plus ace) vul) (just '\0a'))
899 ;~(plug (just '\0a') soz)
900 (boss 256 (star qat))
908> `@t`(scan "'cord'" qut)
911> `@t`(scan "'''\0aabc\0adef\0a'''" qut)
921Parse a triple-single quote, used for multiline strings.
926++ soz ;~(plug soq soq soq)
942A term: a lowercase letter, followed by letters, numbers, or `-`.
949 |=(a=tape (rap 3 ^-((list @) a)))
950 ;~(plug low (star ;~(pose nud low hep)))
956> `term`(scan "sam-2" sym)
962## `++mixed-case-symbol`
966The same as [`++sym`](#sym) but allowing uppercase letters.
973 |=(a=tape (rap 3 ^-((list @) a)))
974 ;~(plug alf (star alp))
980> `term`(scan "sAm-2" mixed-case-symbol)
995++ ven ;~ (comp |=([a=@ b=@] (peg a b)))
1000 =+ vex=?:(hom (bet tub) (gul tub))
1003 =+ wag=$(p.tub p.vex, hom !hom, tub q.u.q.vex)
1005 [p.wag [~ (peg p.u.q.vex p.u.q.wag) q.u.q.wag]]
1025Parse a standard base64 digit.
1032 (cook |=(a=@ (sub a 65)) (shim 'A' 'Z'))
1033 (cook |=(a=@ (sub a 71)) (shim 'a' 'z'))
1034 (cook |=(a=@ (add a 4)) (shim '0' '9'))
1035 (cold 62 (just '-'))
1036 (cold 63 (just '+'))
1062Parse comments and produce a null. Note that a comment must be ended
1063with a newline character.
1078> (scan "::this is a comment \0a" vul)
1081> (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