From db899ce09f7f93a8987256ab96345c0b71229c07 Mon Sep 17 00:00:00 2001 From: fang Date: Fri, 3 Jun 2022 14:10:31 +0200 Subject: [PATCH] hoon: add ,/typed/path syntax Prefixing a path with a com will cause the path to be interpreted as a `$pith`, aka a typed path. Instead of interpreting every element as a string, we use hoon's atom syntaxes to read the values, and tag them with appropriate auras. For example, `,/hi/5/0x6` becomes `[[%tas %hi] [%ud 5] [%ux 0x6] ~]`. Dynamic elements via `()` and `[]` is also supported, and may optionally be tagged with `aura+(etc)` syntax. For example, `,/next/ud+[+(1)]`. Could _maybe_ be refactored to use `+nuck`, but we'd need to wrestle the output, and we're a little stricter here anyway. This shadows existing `,/some-wing` syntax, which... presumably does something, but is not in active use anywhere. We might consider removing that syntax. Eventually, we probably want this to be the primary urbit-native path type. Invalidating existing path syntax is very invasive though, so for now we piggy-back on "com changes the parsing mode" for a less disruptive addition. --- pkg/arvo/sys/hoon.hoon | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/pkg/arvo/sys/hoon.hoon b/pkg/arvo/sys/hoon.hoon index 43fee2f55..6e75e7e67 100644 --- a/pkg/arvo/sys/hoon.hoon +++ b/pkg/arvo/sys/hoon.hoon @@ -1996,12 +1996,23 @@ +$ knot @ta :: ASCII text +$ noun * :: any noun +$ path (list knot) :: like unix path ++$ pith (list iota) :: typed urbit path +$ stud :: standard name $@ mark=@tas :: auth=urbit $: auth=@tas :: standards authority type=path :: standard label == :: +$ tang (list tank) :: bottom-first error +:: :: ++$ iota :: typed path segment + $~ [%n ~] + $% [%ub @ub] [%uc @uc] [%ud @ud] [%ui @ui] + [%ux @ux] [%uv @uv] [%uw @uw] [%da @da] + [%dr @dr] [%f ?] [%if @if] [%is @is] + [%n ~] [%t @t] [%ta @ta] [%tas @tas] + [%p @p] [%q @q] [%rd @rd] [%rh @rh] + [%rq @rq] [%rs @rs] [%s @s] + == :: :: $tank: formatted print tree :: @@ -5970,6 +5981,22 @@ ~ ;~(pfix fas (most fas urs:ab)) :: +++ stip :: typed path parser + =- ;~(pfix fas (more fas -)) + |^ %- stew + ^. stet ^. limo + :~ :- 'a'^'z' (slot (stag %tas sym)) + :- '$' (cold [%tas %$] buc) + :- '0'^'9' (slot bisk:so) + :- '-' (slot tash:so) + :- '.' zust:so + :- '~' (slot ;~(pfix sig ;~(pose crub:so (easy [%n ~])))) + :- '\'' (stag %t qut) + == + :: + ++ slot |*(r=rule (sear (soft iota) r)) + -- +:: :::: 4n: virtualization :: :: +mack: untyped, scry-less, unitary virtualization @@ -11719,6 +11746,44 @@ (stag %clsg poor) == :: + ++ reed + ;~ pfix fas + (stag %clsg (more fas stem)) + == + :: + ++ stem !: + %+ knee *hoon |. ~+ + %+ cook + |= iota=$%([%hoon =hoon] iota) + ?: ?=(%hoon -.iota) hoon.iota + [%clhp [%rock %tas -.iota] [%sand iota]] + |^ %- stew + ^. stet ^. limo + :~ :- 'a'^'z' ;~ pose + (spit (stag %cncl (ifix [pal par] (most ace wide)))) + (spit (ifix [sel ser] wide)) + (slot (stag %tas sym)) + == + :- '$' (cold [%tas %$] buc) + :- '0'^'9' (slot bisk:so) + :- '-' (slot tash:so) + :- '.' zust:so + :- '~' (slot ;~(pfix sig ;~(pose crub:so (easy [%n ~])))) + :- '\'' (stag %t qut) + :- '[' (slip (ifix [sel ser] wide)) + :- '(' (slip (stag %cncl (ifix [pal par] (most ace wide)))) + == + :: + ++ slip |*(r=rule (stag %hoon r)) + ++ slot |*(r=rule (sear (soft iota) r)) + ++ spit + |* r=rule + %+ stag %hoon + %+ cook + |*([a=term b=*] `hoon`[%clhp [%rock %tas a] b]) + ;~((glue lus) sym r) + -- + :: ++ rupl %+ cook |= [a=? b=(list hoon) c=?] @@ -12794,6 +12859,7 @@ :~ :- ',' ;~ pose + ;~(pfix com reed) ::NOTE shadows /wing syntax, maybe re/move (stag %ktcl ;~(pfix com wyde)) (stag %wing rope) ==