mirror of
https://github.com/urbit/shrub.git
synced 2024-12-14 11:08:45 +03:00
Merge pull request #1180 from urbit/validate-treap-order
validate map/set treap order with $|
This commit is contained in:
commit
02b844a144
238
sys/hoon.hoon
238
sys/hoon.hoon
@ -385,116 +385,6 @@
|
||||
:: type that was passed in.
|
||||
::
|
||||
$@(~ [~ u=item])
|
||||
::
|
||||
:: ::
|
||||
:::: 2o: containers ::
|
||||
:: ::
|
||||
::
|
||||
+* jar [key value] (map key (list value)) :: map of lists
|
||||
+* jug [key value] (map key (set value)) :: map of sets
|
||||
+* map [key value] (tree (pair key value)) :: table
|
||||
+* qeu [item] (tree item) :: queue
|
||||
+* set [item] (tree item) :: set
|
||||
::
|
||||
:::: 2q: molds and mold builders ::
|
||||
:: ::
|
||||
::
|
||||
+$ axis @ :: tree address
|
||||
+$ bean ? :: 0=&=yes, 1=|=no
|
||||
+$ flag ?
|
||||
+$ char @t :: UTF8 byte
|
||||
+$ cord @t :: UTF8, LSB first
|
||||
+$ byts [wid=@ud dat=@] :: bytes, MSB first
|
||||
+$ deco ?($bl $br $un $~) :: text decoration
|
||||
+$ date {{a/? y/@ud} m/@ud t/tarp} :: parsed date
|
||||
+$ knot @ta :: ASCII text
|
||||
+$ noun * :: any noun
|
||||
+$ path (list knot) :: like unix path
|
||||
+$ stud :: standard name
|
||||
$@ mark=@tas :: auth=urbit
|
||||
$: auth=@tas :: standards authority
|
||||
type=path :: standard label
|
||||
== ::
|
||||
+$ stub (list (pair stye (list @c))) :: styled unicode
|
||||
+$ stye (pair (set deco) (pair tint tint)) :: decos/bg/fg
|
||||
+$ styl :: cascading style
|
||||
%+ pair (unit deco) ::
|
||||
(pair (unit tint) (unit tint)) ::
|
||||
:: ::
|
||||
+$ styx (list $@(@t (pair styl styx))) :: styled text
|
||||
+$ tile :: XX: ?@(knot (pair styl knot))
|
||||
::
|
||||
cord
|
||||
+$ tint ?($r $g $b $c $m $y $k $w $~) :: text color
|
||||
::
|
||||
:: A `plum` is the intermediate representation for the pretty-printer. It
|
||||
:: encodes hoon-shaped data with the least amount of structured needed
|
||||
:: for formating.
|
||||
::
|
||||
:: A `plum` is either a
|
||||
::
|
||||
:: - `cord`: A simple cord
|
||||
:: - `[%para *]`: A wrappable paragraph.
|
||||
:: - `[%tree *]`: A formatted plum tree
|
||||
:: - `[%sbrk *]`: An indication of a nested subexpression.
|
||||
::
|
||||
:: The formatter will use the tall mode unless:
|
||||
::
|
||||
:: - A plum has only a `wide` style.
|
||||
:: - The plum is in `%sbrk` form and its subplum (`kid`), when
|
||||
:: formatted in wide mode, can fit on a single line.
|
||||
::
|
||||
+$ plum
|
||||
$@ cord
|
||||
$% [%para prefix=tile lines=(list @t)]
|
||||
[%tree fmt=plumfmt kids=(list plum)]
|
||||
[%sbrk kid=plum]
|
||||
==
|
||||
::
|
||||
:: A `plumfmt` is a description of how to render a `plum`. A `plumfmt`
|
||||
:: must include a `wide`, a `tall`, or both.
|
||||
::
|
||||
:: A `wide` is a description of how to render a plum in a single
|
||||
:: line. The nested (`kids`) sub-plums will be interleaved with `delimit`
|
||||
:: strings, and, if `enclose` is set, then the output will be enclosed
|
||||
:: with `p.u.enclose` abnd `q.u.enclose`.
|
||||
::
|
||||
:: For example, to build a plumfmt for string literals, we could write:
|
||||
::
|
||||
:: [wide=[~ '' [~ '"' '"']] tall=~]
|
||||
::
|
||||
:: A `tall` is a description of how to render a plum across multiple
|
||||
:: lines. The output will be prefixed by `intro`, suffixed by
|
||||
:: `final.u.indef`, and each subplum prefixed by `sigil.u.indef`.
|
||||
::
|
||||
:: For example, to build a plumfmt for cores, we could write:
|
||||
::
|
||||
:: [wide=~ tall=`['' `['++' '--']]]
|
||||
::
|
||||
+$ plumfmt
|
||||
$: wide=(unit [delimit=tile enclose=(unit (pair tile tile))])
|
||||
tall=(unit [intro=tile indef=(unit [sigil=tile final=tile])])
|
||||
==
|
||||
::
|
||||
++ tang (list tank) :: bottom-first error
|
||||
++ tank $~ [%leaf ~] ::
|
||||
$% {$leaf p/tape} :: printing formats
|
||||
{$plum p/plum} ::
|
||||
$: $palm :: backstep list
|
||||
p/{p/tape q/tape r/tape s/tape} ::
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
$: $rose :: flat list
|
||||
p/{p/tape q/tape r/tape} :: mid open close
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
== ::
|
||||
++ tape (list @tD) :: utf8 string as list
|
||||
++ tour (list @c) :: utf32 clusters
|
||||
++ tarp {d/@ud h/@ud m/@ud s/@ud f/(list @ux)} :: parsed time
|
||||
++ term @tas :: ascii symbol
|
||||
++ wain (list cord) :: text lines
|
||||
++ wall (list tape) :: text lines
|
||||
-- =>
|
||||
:: ::
|
||||
:::: 2: layer two ::
|
||||
@ -1833,6 +1723,14 @@
|
||||
++ to :: queue engine
|
||||
=| a/(tree) :: (qeu)
|
||||
|@
|
||||
++ apt :: check correctness
|
||||
^- ?
|
||||
?~ a &
|
||||
|- ^- ?
|
||||
?~ l.a &
|
||||
?~ r.a &
|
||||
&((mor n.l.a n.r.a) $(a l.a) $(a r.a))
|
||||
::
|
||||
++ bal
|
||||
|- ^+ a
|
||||
?~ a ~
|
||||
@ -1899,7 +1797,25 @@
|
||||
?~ a ~
|
||||
?~(r.a [~ n.a] $(a r.a))
|
||||
--
|
||||
:: ::
|
||||
::
|
||||
:::: 2o: containers ::
|
||||
:: ::
|
||||
::
|
||||
+* jar [key value] (map key (list value)) :: map of lists
|
||||
+* jug [key value] (map key (set value)) :: map of sets
|
||||
::
|
||||
+* map [key value] :: table
|
||||
$| (tree (pair key value))
|
||||
|=(a=(tree (pair)) ~(apt by a))
|
||||
::
|
||||
+* qeu [item] :: queue
|
||||
$| (tree item)
|
||||
|=(a=(tree) ~(apt to a))
|
||||
::
|
||||
+* set [item] :: set
|
||||
$| (tree item)
|
||||
|=(a=(tree) ~(apt in a))
|
||||
::
|
||||
:::: 2l: container from container ::
|
||||
:: ::
|
||||
::
|
||||
@ -1965,6 +1881,106 @@
|
||||
[i=i.a t=$(a t.a)]
|
||||
--
|
||||
::
|
||||
:::: 2q: molds and mold builders ::
|
||||
:: ::
|
||||
::
|
||||
+$ axis @ :: tree address
|
||||
+$ bean ? :: 0=&=yes, 1=|=no
|
||||
+$ flag ?
|
||||
+$ char @t :: UTF8 byte
|
||||
+$ cord @t :: UTF8, LSB first
|
||||
+$ byts [wid=@ud dat=@] :: bytes, MSB first
|
||||
+$ deco ?($bl $br $un $~) :: text decoration
|
||||
+$ date {{a/? y/@ud} m/@ud t/tarp} :: parsed date
|
||||
+$ knot @ta :: ASCII text
|
||||
+$ noun * :: any noun
|
||||
+$ path (list knot) :: like unix path
|
||||
+$ stud :: standard name
|
||||
$@ mark=@tas :: auth=urbit
|
||||
$: auth=@tas :: standards authority
|
||||
type=path :: standard label
|
||||
== ::
|
||||
+$ stub (list (pair stye (list @c))) :: styled unicode
|
||||
+$ stye (pair (set deco) (pair tint tint)) :: decos/bg/fg
|
||||
+$ styl :: cascading style
|
||||
%+ pair (unit deco) ::
|
||||
(pair (unit tint) (unit tint)) ::
|
||||
:: ::
|
||||
+$ styx (list $@(@t (pair styl styx))) :: styled text
|
||||
+$ tile :: XX: ?@(knot (pair styl knot))
|
||||
::
|
||||
cord
|
||||
+$ tint ?($r $g $b $c $m $y $k $w $~) :: text color
|
||||
::
|
||||
:: A `plum` is the intermediate representation for the pretty-printer. It
|
||||
:: encodes hoon-shaped data with the least amount of structured needed
|
||||
:: for formating.
|
||||
::
|
||||
:: A `plum` is either a
|
||||
::
|
||||
:: - `cord`: A simple cord
|
||||
:: - `[%para *]`: A wrappable paragraph.
|
||||
:: - `[%tree *]`: A formatted plum tree
|
||||
:: - `[%sbrk *]`: An indication of a nested subexpression.
|
||||
::
|
||||
:: The formatter will use the tall mode unless:
|
||||
::
|
||||
:: - A plum has only a `wide` style.
|
||||
:: - The plum is in `%sbrk` form and its subplum (`kid`), when
|
||||
:: formatted in wide mode, can fit on a single line.
|
||||
::
|
||||
+$ plum
|
||||
$@ cord
|
||||
$% [%para prefix=tile lines=(list @t)]
|
||||
[%tree fmt=plumfmt kids=(list plum)]
|
||||
[%sbrk kid=plum]
|
||||
==
|
||||
::
|
||||
:: A `plumfmt` is a description of how to render a `plum`. A `plumfmt`
|
||||
:: must include a `wide`, a `tall`, or both.
|
||||
::
|
||||
:: A `wide` is a description of how to render a plum in a single
|
||||
:: line. The nested (`kids`) sub-plums will be interleaved with `delimit`
|
||||
:: strings, and, if `enclose` is set, then the output will be enclosed
|
||||
:: with `p.u.enclose` abnd `q.u.enclose`.
|
||||
::
|
||||
:: For example, to build a plumfmt for string literals, we could write:
|
||||
::
|
||||
:: [wide=[~ '' [~ '"' '"']] tall=~]
|
||||
::
|
||||
:: A `tall` is a description of how to render a plum across multiple
|
||||
:: lines. The output will be prefixed by `intro`, suffixed by
|
||||
:: `final.u.indef`, and each subplum prefixed by `sigil.u.indef`.
|
||||
::
|
||||
:: For example, to build a plumfmt for cores, we could write:
|
||||
::
|
||||
:: [wide=~ tall=`['' `['++' '--']]]
|
||||
::
|
||||
+$ plumfmt
|
||||
$: wide=(unit [delimit=tile enclose=(unit (pair tile tile))])
|
||||
tall=(unit [intro=tile indef=(unit [sigil=tile final=tile])])
|
||||
==
|
||||
::
|
||||
++ tang (list tank) :: bottom-first error
|
||||
++ tank $~ [%leaf ~] ::
|
||||
$% {$leaf p/tape} :: printing formats
|
||||
{$plum p/plum} ::
|
||||
$: $palm :: backstep list
|
||||
p/{p/tape q/tape r/tape s/tape} ::
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
$: $rose :: flat list
|
||||
p/{p/tape q/tape r/tape} :: mid open close
|
||||
q/(list tank) ::
|
||||
== ::
|
||||
== ::
|
||||
++ tape (list @tD) :: utf8 string as list
|
||||
++ tour (list @c) :: utf32 clusters
|
||||
++ tarp {d/@ud h/@ud m/@ud s/@ud f/(list @ux)} :: parsed time
|
||||
++ term @tas :: ascii symbol
|
||||
++ wain (list cord) :: text lines
|
||||
++ wall (list tape) :: text lines
|
||||
::
|
||||
:::: 2p: serialization ::
|
||||
:: ::
|
||||
::
|
||||
|
35
tests/sys/hoon/molds.hoon
Normal file
35
tests/sys/hoon/molds.hoon
Normal file
@ -0,0 +1,35 @@
|
||||
/+ *test
|
||||
|%
|
||||
++ test-set
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> (some (sy 1 2 ~))
|
||||
!> ((soft (set)) [2 [1 ~ ~] ~])
|
||||
::
|
||||
%+ expect-eq
|
||||
!> ~
|
||||
!> ((soft (set)) [2 ~ [1 ~ ~]])
|
||||
==
|
||||
::
|
||||
++ test-map
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> (some (my [1 2] [3 4] ~))
|
||||
!> ((soft (map)) [[1 2] ~ [[3 4] ~ ~]])
|
||||
::
|
||||
%+ expect-eq
|
||||
!> ~
|
||||
!> ((soft (map)) [[1 2] [[3 4] ~ ~] ~])
|
||||
==
|
||||
::
|
||||
++ test-qeu
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> (some (~(gas to *(qeu)) "abcd"))
|
||||
!> ((soft (qeu)) [98 [100 ~ [99 ~ ~]] [97 ~ ~]])
|
||||
::
|
||||
%+ expect-eq
|
||||
!> ~
|
||||
!> ((soft (qeu)) [98 [97 ~ ~] [100 ~ [99 ~ ~]]])
|
||||
==
|
||||
--
|
Loading…
Reference in New Issue
Block a user