From 8b8bc2cc48f789b7d1c746e5eebfb3c9af9da4db Mon Sep 17 00:00:00 2001 From: Sigilante Date: Fri, 2 Jan 2026 15:20:54 -0600 Subject: [PATCH 1/8] Add first round of parser changes for beta. --- common/hoon/lib/jock.hoon | 203 +++++++++++++++++++++++++++++++------- 1 file changed, 167 insertions(+), 36 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index 7bc966e..f64776a 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -58,12 +58,16 @@ $? %let %func %lambda - %class + %struct + %impl + %trait + %union + %alias + %object %if %else %crash %assert - %object %compose %loop %defer @@ -85,15 +89,25 @@ %'(' %')' %'{' %'}' %'[' %']' %'=' %'<' %'>' %'#' %'+' %'-' %'*' %'/' %'%' %'_' + ::%'->' TODO decide if necessary or to do in two steps == :: +$ jatom $+ jatom $~ [[%loobean p=%.n] q=%.n] - $: $% [%string p=cord] + $: $% [%chars p=cord] + [%string p=tape] [%number p=@ud] - [%hexadecimal p=@ux] - [%loobean p=?] + [%sint p=@sd] + [%hex p=@x] + [%real p=@rd] + [%real16 p=@rh] + [%real32 p=@rs] + [%real128 p=@rq] + [%logical p=?] + [%date p=@da] + [%span p=@dr] + [%path p=path] == q=?(%.y %.n) :: constant flag == @@ -121,21 +135,135 @@ == ++ gav (cold ~ (star ;~(pose val var gah))) ++ gae ;~(pose gav (easy ~)) +:: '1_234_567' -> 0i1234567 +:: ++ dep (ape:ag (bass 1.000 ;~(plug ted:ab (star ;~(pfix ;~(plug cab gay) tid:ab))))) +++ dep (ape:ag (bass 1.000 ;~(plug ted:ab (star ;~(pfix cab tid:ab))))) +:: +++ roy + =/ moo + |= a=tape + :- (lent a) + (scan a (bass 10 (plus sid:ab))) + ;~ pose + ;~ plug + (easy %d) + ;~(pose (cold | hep) (cold & lus) (easy &)) + ;~ plug dim:ag + ;~ pose + ;~(pfix dot (cook moo (plus (shim '0' '9')))) + (easy [0 0]) + == + ;~ pose + ;~ pfix + (just 'e') + ;~(plug ;~(pose (cold | hep) (easy &)) dim:ag) + == + (easy [& 0]) + == + == + == + :: + ;~ plug + (easy %i) + ;~ sfix + ;~(pose (cold | hep) (easy &)) + (jest 'inf') + == + == + :: + ;~ plug + (easy %n) + (cold ~ (jest 'nan')) + == + == :: ++ tokenize =| fun=?(%.y %.n) |% - ++ string (stag %string (cook crip (ifix [soq soq] (star ;~(less soq prn))))) - ++ number (stag %number dem:ag) - ++ hexadecimal (stag %hexadecimal ;~(pfix (jest %'0x') hex)) - ++ loobean - %+ stag %loobean - ;~(pose (cold %.y (jest %true)) (cold %.n (jest %false))) + :: Single-quoted cord: 'foo' -> @t + ++ chars + %+ stag %chars + (cook crip (ifix [soq soq] (star ;~(less soq prn)))) + :: Double-quoted tape: "foo" -> (list @tD) + ++ string + %+ stag %string + (cook crip (ifix [doq doq] (star ;~(less soq prn)))) + :: Numeric literal: 1234, 1_234 -> @ud + ++ number + %+ stag %number + ;~(pose dep dem) + :: Signed numeric literal: -1234, +1_234 -> @sd + ++ sint + %+ stag %sint + ;~ pose + (cook |=(n=@ud (new:si & n)) ;~(pfix lus dem:ag)) + (cook |=(n=@ud (new:si | n)) ;~(pfix hep dem:ag)) + == + :: TODO switch to dep when fixed + :: Hexadecimal literal: 0xBA1A3F, 0xba1a3f -> @x + ++ hex + %+ stag %hex + ;~(pfix (jest %'0x') ^hex) + :: Real 64-bit float: 3.14, +3.14, -0.001 -> @rd + ++ real + %+ stag %real + (cook ryld (cook royl-cell:so roy)) + :: Real 16-bit float: 3.14, +3.14, -0.001 -> @rh + ++ real16 + %+ stag %real16 + (cook rylh (cook royl-cell:so roy)) + :: Real 32-bit float: 3.14, +3.14, -0.001 -> @rs + ++ real32 + %+ stag %real32 + (cook ryls (cook royl-cell:so roy)) + :: Real 128-bit float: 3.14, +3.14, -0.001 -> @rq + ++ real128 + %+ stag %real128 + (cook rylq (cook royl-cell:so roy)) + :: Real 64-bit float alias + ++ real64 real + :: Logical loobean: %true, %false -> ? + ++ logical + %+ stag %logical + ;~ pose + (cold %.y (jest %true)) + (cold %.n (jest %false)) + == + :: Date: @2026.1.1..12.0.0..ffff -> @da + ++ date + %+ stag %date + ;~(pfix pat (cook year when:so)) + :: Span: ~d15h23m45s -> @dr + ++ span + %+ stag %span + crub:so + :: Path: /foo/bar/baz -> path + ++ jpath + %+ stag %path + stap :: - ++ tagged-literal (stag %literal (hart literal %.n)) - ++ literal ;~(pose loobean hexadecimal number string) - ++ tagged-symbol (stag %literal (hart symbol %.y)) - ++ symbol ;~(pfix cen literal) + ++ tagged-literal + %+ stag %literal + (hart literal %.n) + ++ literal + ;~ pose + chars + string + number + sint + hex + real + real16 + real32 + real128 + date + span + jpath + == + ++ tagged-symbol + %+ stag %literal + (hart symbol %.y) + ++ symbol ;~(pfix cen literal) :: add a suffix label ++ hart |* [sef=rule gob=*] @@ -150,37 +278,40 @@ :: the goal is to parse a function call into the pseudo-punctuator '(('. :: This only happens if there is a name or type immediately preceding '(', :: e.g. foo(bar) -> 'foo' '((' 'bar' ')' - ++ tagged-name (stag %name name) :: [%name term] - ++ name snek :: term with _ - ++ snek %+ cook - |=(a=tape (rap 3 ^-((list @) a))) - ;~(plug low (star ;~(pose nud low cab))) + ++ tagged-name (stag %name sym) :: - ++ tagged-type (stag %type type) :: [%type 'Cord'] - ++ type aul :: Cord - ++ aul %+ cook :: Ulll - |=(a=tape (rap 3 ^-((list @) a))) - ;~(plug hig (star low)) + ++ tagged-type + %+ stag %type + nik + :: PascalCase identifier (type names) + ++ nik + %+ cook + |=(a=tape (rap 3 ^-((list @) a))) + ;~(plug hig (star ;~(pose hig low))) :: ++ tagged-keyword (stag %keyword keyword) ++ keyword %- perk - :~ %let %func %lambda %class - %if %else %crash %assert - %object %compose %loop %defer + :~ %let %func %lambda + %struct %impl %trait %union %alias + %object %if %else %crash %assert + %compose %loop %defer %recur %match %switch %eval %with %this %import %as %print == :: - ++ tagged-punctuator %+ cook - |= =token - ^- ^token - ?. &(fun =([%punctuator %'('] token)) - token - :: =. fun %.n - [%punctuator `jpunc`%'(('] - (stag %punctuator punctuator) + ++ tagged-punctuator + %+ cook + |= =token + ^- ^token + ?. &(fun =([%punctuator %'('] token)) + token + :: =. fun %.n + [%punctuator `jpunc`%'(('] + (stag %punctuator punctuator) ++ punctuator + :: ;~ pose + :: (cold %'->' (jest '->')) :: must come before solo '-' %- perk :~ %'.' %';' %',' %':' %'&' %'$' %'@' %'?' %'!' :: XXX exclude %'((' which is a pseudo-punctuator From 244805d71676f305fe316fae63d453b71ed3570f Mon Sep 17 00:00:00 2001 From: Sigilante Date: Fri, 2 Jan 2026 16:19:37 -0600 Subject: [PATCH 2/8] Fix parser for current usage. --- common/hoon/lib/jock.hoon | 54 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index f64776a..4f215f5 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -89,12 +89,12 @@ %'(' %')' %'{' %'}' %'[' %']' %'=' %'<' %'>' %'#' %'+' %'-' %'*' %'/' %'%' %'_' - ::%'->' TODO decide if necessary or to do in two steps + %'->' == :: +$ jatom $+ jatom - $~ [[%loobean p=%.n] q=%.n] + $~ [[%logical p=%.n] q=%.n] $: $% [%chars p=cord] [%string p=tape] [%number p=@ud] @@ -104,7 +104,7 @@ [%real16 p=@rh] [%real32 p=@rs] [%real128 p=@rq] - [%logical p=?] + [%logical p=?(%.y %.n)] [%date p=@da] [%span p=@dr] [%path p=path] @@ -187,7 +187,7 @@ :: Double-quoted tape: "foo" -> (list @tD) ++ string %+ stag %string - (cook crip (ifix [doq doq] (star ;~(less soq prn)))) + (ifix [doq doq] (star ;~(less doq prn))) :: Numeric literal: 1234, 1_234 -> @ud ++ number %+ stag %number @@ -196,8 +196,8 @@ ++ sint %+ stag %sint ;~ pose - (cook |=(n=@ud (new:si & n)) ;~(pfix lus dem:ag)) - (cook |=(n=@ud (new:si | n)) ;~(pfix hep dem:ag)) + (cook |=(n=@ud (new:si & n)) ;~(pfix lus dem:ag)) + (cook |=(n=@ud (new:si | n)) ;~(pfix hep dem:ag)) == :: TODO switch to dep when fixed :: Hexadecimal literal: 0xBA1A3F, 0xba1a3f -> @x @@ -236,7 +236,28 @@ :: Span: ~d15h23m45s -> @dr ++ span %+ stag %span - crub:so + %+ cook + |= [a=(list [p=?(%d %h %m %s) q=@]) b=(list @)] + =+ rop=`tarp`[0 0 0 0 b] + |- ^- @dr + ?~ a (yule rop) + ?- p.i.a + %d $(a t.a, d.rop (add q.i.a d.rop)) + %h $(a t.a, h.rop (add q.i.a h.rop)) + %m $(a t.a, m.rop (add q.i.a m.rop)) + %s $(a t.a, s.rop (add q.i.a s.rop)) + == + ;~ plug + %+ most + dot + ;~ pose + ;~(pfix (just 'd') (stag %d dim:ag)) + ;~(pfix (just 'h') (stag %h dim:ag)) + ;~(pfix (just 'm') (stag %m dim:ag)) + ;~(pfix (just 's') (stag %s dim:ag)) + == + ;~(pose ;~(pfix ;~(plug dot dot) (most dot qix:ab)) (easy ~)) + == :: Path: /foo/bar/baz -> path ++ jpath %+ stag %path @@ -256,6 +277,7 @@ real16 real32 real128 + logical date span jpath @@ -310,15 +332,15 @@ [%punctuator `jpunc`%'(('] (stag %punctuator punctuator) ++ punctuator - :: ;~ pose - :: (cold %'->' (jest '->')) :: must come before solo '-' - %- perk - :~ %'.' %';' %',' %':' %'&' %'$' - %'@' %'?' %'!' :: XXX exclude %'((' which is a pseudo-punctuator - %'(' %')' %'{' %'}' %'[' %']' - %'=' %'<' %'>' %'#' - %'+' %'-' %'*' %'/' %'%' %'_' - == + ;~ pose + (cold %'->' (jest '->')) :: must come before solo '-' + %- perk + :~ %'.' %';' %',' %':' %'&' %'$' + %'@' %'?' %'!' :: XXX exclude %'((' which is a pseudo-punctuator + %'(' %')' %'{' %'}' %'[' %']' + %'=' %'<' %'>' %'#' + %'+' %'-' %'*' %'/' %'%' %'_' + == == :: :: The parser's precedence rules: :: 1. Keywords From 5512bf0a4666179543b5d84c1327248384960f09 Mon Sep 17 00:00:00 2001 From: Sigilante Date: Fri, 2 Jan 2026 18:26:02 -0600 Subject: [PATCH 3/8] Remove 1_234 notation for now. --- common/hoon/lib/jock.hoon | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index 4f215f5..a7a1931 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -135,9 +135,6 @@ == ++ gav (cold ~ (star ;~(pose val var gah))) ++ gae ;~(pose gav (easy ~)) -:: '1_234_567' -> 0i1234567 -:: ++ dep (ape:ag (bass 1.000 ;~(plug ted:ab (star ;~(pfix ;~(plug cab gay) tid:ab))))) -++ dep (ape:ag (bass 1.000 ;~(plug ted:ab (star ;~(pfix cab tid:ab))))) :: ++ roy =/ moo @@ -188,10 +185,10 @@ ++ string %+ stag %string (ifix [doq doq] (star ;~(less doq prn))) - :: Numeric literal: 1234, 1_234 -> @ud + :: Numeric literal: 1234 -> @ud ++ number %+ stag %number - ;~(pose dep dem) + dem :: Signed numeric literal: -1234, +1_234 -> @sd ++ sint %+ stag %sint From eebc8962c10b5ac8719614fd73c73943af8bb43b Mon Sep 17 00:00:00 2001 From: Sigilante Date: Mon, 5 Jan 2026 10:19:25 -0600 Subject: [PATCH 4/8] Made parser happy --- Makefile | 2 +- common/hoon/lib/jock.hoon | 263 ++++++++++++++++++++++---------------- 2 files changed, 152 insertions(+), 113 deletions(-) diff --git a/Makefile b/Makefile index 09a6b2b..98c4267 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ help: PROFILE_DEV_DEBUG = --profile dev PROFILE_RELEASE = --profile release -HOONC = hoonc +HOONC = ~/.cargo/bin/hoonc .PHONY: build build: build-dev-debug diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index a7a1931..d79ffd9 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -96,7 +96,6 @@ $+ jatom $~ [[%logical p=%.n] q=%.n] $: $% [%chars p=cord] - [%string p=tape] [%number p=@ud] [%sint p=@sd] [%hex p=@x] @@ -107,16 +106,21 @@ [%logical p=?(%.y %.n)] [%date p=@da] [%span p=@dr] - [%path p=path] == q=?(%.y %.n) :: constant flag == :: ++$ jnoun + $+ jnoun + $% [%string p=tape] + [%path p=path] + == +:: +$ token $+ token $% [%keyword keyword] [%punctuator jpunc] - [%literal jatom] + [%literal ?([%atom jatom] [%noun jnoun])] [%name cord] [%type cord] == @@ -177,14 +181,45 @@ ++ tokenize =| fun=?(%.y %.n) |% + :: + ++ tagged-keyword (stag %keyword keyword) + ++ keyword + %- perk + :~ %let %func %lambda + %struct %impl %trait %union %alias + %object %if %else %crash %assert + %compose %loop %defer + %recur %match %switch %eval %with %this + %import %as %print + == + :: + ++ tagged-symbol + %+ stag %literal + %+ stag %atom + (hart ;~(pfix cen literal-atom) %.y) + :: + ++ tagged-literal-atom + %+ stag %literal + %+ stag %atom + (hart literal-atom %.n) + ++ literal-atom + ;~ pose + chars + number + sint + hex + real + real16 + real32 + real128 + logical + date + span + == :: Single-quoted cord: 'foo' -> @t ++ chars %+ stag %chars (cook crip (ifix [soq soq] (star ;~(less soq prn)))) - :: Double-quoted tape: "foo" -> (list @tD) - ++ string - %+ stag %string - (ifix [doq doq] (star ;~(less doq prn))) :: Numeric literal: 1234 -> @ud ++ number %+ stag %number @@ -255,34 +290,21 @@ == ;~(pose ;~(pfix ;~(plug dot dot) (most dot qix:ab)) (easy ~)) == - :: Path: /foo/bar/baz -> path - ++ jpath - %+ stag %path - stap - :: - ++ tagged-literal + ++ tagged-literal-noun %+ stag %literal - (hart literal %.n) - ++ literal + %+ stag %noun ;~ pose - chars string - number - sint - hex - real - real16 - real32 - real128 - logical - date - span jpath == - ++ tagged-symbol - %+ stag %literal - (hart symbol %.y) - ++ symbol ;~(pfix cen literal) + :: Double-quoted tape: "foo" -> (list @tD) + ++ string + %+ stag %string + (ifix [doq doq] (star ;~(less doq prn))) + :: Path: /foo/bar/baz -> path + ++ jpath + %+ stag %path + stap :: add a suffix label ++ hart |* [sef=rule gob=*] @@ -308,17 +330,6 @@ |=(a=tape (rap 3 ^-((list @) a))) ;~(plug hig (star ;~(pose hig low))) :: - ++ tagged-keyword (stag %keyword keyword) - ++ keyword - %- perk - :~ %let %func %lambda - %struct %impl %trait %union %alias - %object %if %else %crash %assert - %compose %loop %defer - %recur %match %switch %eval %with %this - %import %as %print - == - :: ++ tagged-punctuator %+ cook |= =token @@ -351,7 +362,8 @@ ;~ pose (knee *(list token) |.(~+(;~(plug tagged-keyword ;~(pfix gav tokens(fun %.n)))))) (knee *(list token) |.(~+(;~(plug tagged-symbol ;~(pfix gav tokens(fun %.n)))))) - (knee *(list token) |.(~+(;~(plug tagged-literal ;~(pfix gav tokens(fun %.n)))))) + (knee *(list token) |.(~+(;~(plug tagged-literal-atom ;~(pfix gav tokens(fun %.n)))))) + (knee *(list token) |.(~+(;~(plug tagged-literal-noun ;~(pfix gav tokens(fun %.n)))))) (knee *(list token) |.(~+(;~(plug tagged-name ;~(pfix gav tokens(fun %.y)))))) (knee *(list token) |.(~+(;~(plug tagged-punctuator ;~(pfix gav tokens(fun %.n)))))) (knee *(list token) |.(~+(;~(plug tagged-type ;~(pfix gav tokens(fun %.y)))))) @@ -389,32 +401,40 @@ $+ jock $^ [p=jock q=jock] $% [%let type=jype val=jock next=jock] + [%edit limb=(list jlimb) val=jock next=jock] [%func type=jype body=jock next=jock] + [%lambda p=lambda] + :: [%struct] + :: [%impl] + :: [%trait] + :: [%union] + :: [%alias] [%class state=jype arms=(map term jock)] [%method type=jype body=jock] - [%edit limb=(list jlimb) val=jock next=jock] - [%increment val=jock] - [%cell-check val=jock] - [%compose p=jock q=jock] + :: [%object name=term p=(map term jock) q=(unit jock)] - [%eval p=jock q=jock] - [%loop next=jock] - [%defer next=jock] if-expression [%assert cond=jock then=jock] + [%compose p=jock q=jock] + [%loop next=jock] + [%defer next=jock] [%match value=jock cases=(map jock jock) default=(unit jock)] [%cases value=jock cases=(map jock jock) default=(unit jock)] + [%eval p=jock q=jock] + [%print body=?([%jock jock]) next=jock] + :: + [%operator op=operator a=jock b=(unit jock)] + [%increment val=jock] + [%cell-check val=jock] [%call func=jock arg=(unit jock)] [%compare comp=comparator a=jock b=jock] - [%operator op=operator a=jock b=(unit jock)] - [%lambda p=lambda] [%limb p=(list jlimb)] [%atom p=jatom] + [%noun p=jnoun] [%list type=jype-leaf val=(list jock)] [%set type=jype-leaf val=(set jock)] [%import name=jype next=jock] - [%print body=?([%jock jock]) next=jock] - [%crash ~] + [%crash ~] :: keep last for Hoon type bunting == :: +$ if-expression @@ -511,10 +531,18 @@ :: Jype atom base types; corresponds to jatom tags +$ jatom-type $+ jatom-type - $? %string + $? %chars %number - %hexadecimal - %loobean + %sint + %hex + %real + %real16 + %real32 + %real128 + %logical + %date + %span + %path == :: Jype core executable, either a direct lambda or a regular core +$ core-body (each lambda-argument (map term jype)) @@ -587,7 +615,7 @@ ^- [jock (list token)] ?: =(~ tokens) ~|("expect inner-jock. token: ~" !!) ?: ?| (has-keyword -.tokens %object) - (has-keyword -.tokens %class) + :: (has-keyword -.tokens %class) (has-keyword -.tokens %with) (has-keyword -.tokens %this) (has-keyword -.tokens %crash) @@ -890,6 +918,7 @@ ?: !=(%type -<.tokens) ~|("expect type. token: {<-.tokens>}" !!) =/ type=cord + :: Short-circuits on built-in container types ?: =([%type 'List'] -.tokens) %list ?: =([%type 'Set'] -.tokens) %set :: ?: =([%type 'Map'] -.tokens) %map @@ -897,12 +926,20 @@ ->.tokens =/ nom (get-name -.tokens) ?~ nom ~|("expect name. token: {<-.tokens>}" !!) - :: Short-circuit on built-in primitive types - ?: =('Atom' u.nom) [[%atom %number %.n]^u.nom +.tokens] - ?: =('Uint' u.nom) [[%atom %number %.n]^u.nom +.tokens] - ?: =('Uhex' u.nom) [[%atom %hexadecimal %.n]^u.nom +.tokens] - ?: =('String' u.nom) [[%atom %string %.n]^u.nom +.tokens] - ?: =('Loob' u.nom) [[%atom %loobean %.n]^u.nom +.tokens] + :: Short-circuits on built-in primitive types + ?: =('Atom' u.nom) [[%atom %number %.n]^u.nom +.tokens] + ?: =('Uint' u.nom) [[%atom %number %.n]^u.nom +.tokens] + ?: =('Int' u.nom) [[%atom %sint %.n]^u.nom +.tokens] + ?: =('Hex' u.nom) [[%atom %hex %.n]^u.nom +.tokens] + ?: =('Real' u.nom) [[%atom %real %.n]^u.nom +.tokens] + ?: =('Real16' u.nom) [[%atom %real16 %.n]^u.nom +.tokens] + ?: =('Real32' u.nom) [[%atom %real32 %.n]^u.nom +.tokens] + ?: =('Real128' u.nom) [[%atom %real128 %.n]^u.nom +.tokens] + ?: =('Logical' u.nom) [[%atom %logical %.n]^u.nom +.tokens] + ?: =('Date' u.nom) [[%atom %date %.n]^u.nom +.tokens] + ?: =('Span' u.nom) [[%atom %span %.n]^u.nom +.tokens] + ?: =('String' u.nom) [[%noun %string]^u.nom +.tokens] + ?: =('Path' u.nom) [[%noun %path]^u.nom +.tokens] :: =. tokens +.tokens ?. =([%punctuator %'(('] -.tokens) @@ -988,54 +1025,54 @@ [[%call [%lambda lambda] `arg] tokens] :: :: [%class state=jype arms=(map term jock)] - %class - =^ state tokens - (match-jype tokens) - :: mask out reserved types - ?: =([%type 'List'] name.state) ~|('Shadowing reserved type List is not allowed.' !!) - ?: =([%type 'Set'] name.state) ~|('Shadowing reserved type Set is not allowed.' !!) - :: ?: =([%type 'Map'] name.state) ~|('Shadowing reserved type Map is not allowed.' !!) - ?> (got-punctuator -.tokens %'{') - =| arms=(map term jock) - =. tokens +.tokens - =^ arms tokens - |- - ?: (has-punctuator -.tokens %'}') - [arms +.tokens] - :: Retrieve the name of the method. - =^ type tokens - (match-jype tokens) - :: Gather the arguments and output type. - =^ inp tokens - ?> (got-punctuator -.tokens %'((') - =^ r=(pair jype (unit jype)) tokens - =^ jyp-one tokens (match-jype +.tokens) - ?: (has-punctuator -.tokens %')') - :: short-circuit if single element in cell - [[jyp-one ~] tokens] - =^ jyp-two tokens (match-jype tokens) - :: TODO: support implicit right-association (what's a good test case?) - [[jyp-one `jyp-two] tokens] - [?~(q.r `jype`p.r `jype`[[p.r u.q.r] %$]) tokens] - ?> (got-punctuator -.tokens %')') - =. tokens +.tokens - ?> (got-punctuator -.tokens %'-') - ?> (got-punctuator +<.tokens %'>') - =. tokens +>.tokens - =^ out tokens - (match-jype tokens) - =. type - :- [%core [%& [`inp out]] ~] - name.type - :: Retrieve the body of the method. - =^ body tokens - (match-block [tokens %'{' %'}'] match-jock) - =. body - :- %lambda - [[`inp out] body ~] - $(arms (~(put by arms) name.type [%method type body])) - :_ tokens - [%class state=state arms=arms] + :: %class + :: =^ state tokens + :: (match-jype tokens) + :: :: mask out reserved types + :: ?: =([%type 'List'] name.state) ~|('Shadowing reserved type List is not allowed.' !!) + :: ?: =([%type 'Set'] name.state) ~|('Shadowing reserved type Set is not allowed.' !!) + :: :: ?: =([%type 'Map'] name.state) ~|('Shadowing reserved type Map is not allowed.' !!) + :: ?> (got-punctuator -.tokens %'{') + :: =| arms=(map term jock) + :: =. tokens +.tokens + :: =^ arms tokens + :: |- + :: ?: (has-punctuator -.tokens %'}') + :: [arms +.tokens] + :: :: Retrieve the name of the method. + :: =^ type tokens + :: (match-jype tokens) + :: :: Gather the arguments and output type. + :: =^ inp tokens + :: ?> (got-punctuator -.tokens %'((') + :: =^ r=(pair jype (unit jype)) tokens + :: =^ jyp-one tokens (match-jype +.tokens) + :: ?: (has-punctuator -.tokens %')') + :: :: short-circuit if single element in cell + :: [[jyp-one ~] tokens] + :: =^ jyp-two tokens (match-jype tokens) + :: :: TODO: support implicit right-association (what's a good test case?) + :: [[jyp-one `jyp-two] tokens] + :: [?~(q.r `jype`p.r `jype`[[p.r u.q.r] %$]) tokens] + :: ?> (got-punctuator -.tokens %')') + :: =. tokens +.tokens + :: ?> (got-punctuator -.tokens %'-') + :: ?> (got-punctuator +<.tokens %'>') + :: =. tokens +>.tokens + :: =^ out tokens + :: (match-jype tokens) + :: =. type + :: :- [%core [%& [`inp out]] ~] + :: name.type + :: :: Retrieve the body of the method. + :: =^ body tokens + :: (match-block [tokens %'{' %'}'] match-jock) + :: =. body + :: :- %lambda + :: [[`inp out] body ~] + :: $(arms (~(put by arms) name.type [%method type body])) + :: :_ tokens + :: [%class state=state arms=arms] :: :: if (a < b) { +(a) } else { +(b) } :: [%if cond=jock then=jock after-if=after-if-expression] @@ -1368,10 +1405,12 @@ :: ++ match-literal |= =tokens - ^- [[%atom jatom] (list token)] + ^- [?([%atom jatom] [%noun jnoun]) (list token)] ?: =(~ tokens) ~|("expect literal. token: ~" !!) ?. ?=(%literal -<.tokens) ~|("expect literal. token: {<-<.tokens>}" !!) + ?: ?=(%noun -<.tokens) + [[%noun -<.tokens] +.tokens] [[%atom ->.tokens] +.tokens] :: ++ match-name From 2d305a5d05f2f6926ec3880bb2d656f4e612f7f6 Mon Sep 17 00:00:00 2001 From: Sigilante Date: Mon, 5 Jan 2026 10:31:17 -0600 Subject: [PATCH 5/8] Switch to atom/noun divide. --- common/hoon/lib/jock.hoon | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index d79ffd9..c40d804 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -512,6 +512,8 @@ [%fork p=jype q=jype] :: %list [%list type=jype] + :: %noun + [%noun p=jnoun-type] :: %set [%set type=jype] :: %hoon is a vase for the supplied subject (presumably hoon or tiny) @@ -544,6 +546,12 @@ %span %path == +:: Jype noun base types; corresponds to jnoun tags ++$ jnoun-type + $+ jnoun-type + $? %string + %path + == :: Jype core executable, either a direct lambda or a regular core +$ core-body (each lambda-argument (map term jype)) :: Lambda executable @@ -1271,7 +1279,7 @@ [[%atom %number %.n] +.tokens] :: Match on loobean type a:? ?: (has-punctuator -.tokens %'?') - [[%atom %loobean %.n] +.tokens] + [[%atom %logical %.n] +.tokens] :: Match on noun type a:* ?: (has-punctuator -.tokens %'*') [[%none ~] +.tokens] @@ -1409,9 +1417,9 @@ ?: =(~ tokens) ~|("expect literal. token: ~" !!) ?. ?=(%literal -<.tokens) ~|("expect literal. token: {<-<.tokens>}" !!) - ?: ?=(%noun -<.tokens) - [[%noun -<.tokens] +.tokens] - [[%atom ->.tokens] +.tokens] + ?: ?=(%noun ->-.tokens) + [[%noun ->+.tokens] +.tokens] + [[%atom ->+.tokens] +.tokens] :: ++ match-name |= =tokens @@ -1467,7 +1475,9 @@ ?: =(~ tokens) ~|("expect literal. token: ~" !!) ?. ?=(%literal -<.tokens) ~|("expect literal or symbol. token: {<-<.tokens>}" !!) - =/ p=jatom ->.tokens + ?. ?=(%atom ->-.tokens) + ~|("expect literal or symbol. token: {<-.tokens>}" !!) + =/ p=jatom ->+.tokens ?. ?=(%number -<.p) ~|("expect number or symbol. token: {<-.p>}" !!) ->.p @@ -1983,7 +1993,7 @@ %cell-check ~| %cell-check =^ val jyp $(j val.j) - [[%3 val] [%atom %loobean %.n]^%$] + [[%3 val] [%atom %logical %.n]^%$] :: %compose ~| %compose-p @@ -2340,7 +2350,7 @@ == :: %compare - :_ [%atom %loobean %.n]^%$ + :_ [%atom %logical %.n]^%$ ?- comp.j %'==' =+ [a a-jyp]=$(j a.j) @@ -2665,7 +2675,7 @@ %string %ta %number %ud %hexadecimal %ux - %loobean %f + %logical %f == p.p.arg :: @@ -2727,7 +2737,7 @@ %t %string %ta %string %tas %string - %f %loobean + %f %logical == =(~ q.t) :: @@ -2819,7 +2829,7 @@ %atom %- crip ?- ->-.jype - %loobean + %logical "{<;;(? +.nock)>}" :: %number From 2f2031fe267cb07b77398a11c5d5221ef5ed002c Mon Sep 17 00:00:00 2001 From: Sigilante Date: Mon, 5 Jan 2026 11:08:53 -0600 Subject: [PATCH 6/8] Compiles with new atom and jnoun types. --- common/hoon/lib/jock.hoon | 69 +++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index c40d804..7724743 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -30,14 +30,14 @@ |= txt=@ ^- * =/ jok (jeam (cat 3 'import hoon;\0a' txt)) - =+ [nok jyp]=(~(mint cj:~(. +> libs) [%atom %string %.n]^%$) jok) + =+ [nok jyp]=(~(mint cj:~(. +> libs) [%atom %chars %.n]^%$) jok) nok :: ++ jypist |= txt=@ ^- jype =/ jok (jeam (cat 3 'import hoon;\0a' txt)) - =+ [nok jyp]=(~(mint cj:~(. +> libs) [%atom %string %.n]^%$) jok) + =+ [nok jyp]=(~(mint cj:~(. +> libs) [%atom %chars %.n]^%$) jok) jyp -- => @@ -113,7 +113,7 @@ +$ jnoun $+ jnoun $% [%string p=tape] - [%path p=path] + [%path p=path] == :: +$ token @@ -544,7 +544,6 @@ %logical %date %span - %path == :: Jype noun base types; corresponds to jnoun tags +$ jnoun-type @@ -1857,7 +1856,7 @@ ++ mint |= j=jock ^- [nock jype] - ?- -.j + ?+ -.j ~|("cj: unimplmented jock: {<-.j>}" !!) ^ ~| %pair-p =+ [p p-jyp]=$(j p.j) @@ -2630,6 +2629,8 @@ $(j p.p.u.lim) :: %fork $(j p.p.j) + :: + %noun [%1 0] :: %list [%1 0] :: @@ -2672,10 +2673,17 @@ ;; hoon :+ ?:(q.p.arg %rock %sand) ?- -<.p.arg - %string %ta + %chars %ta %number %ud - %hexadecimal %ux + %sint %sd + %hex %ux + %real %rd + %real16 %rh + %real32 %rs + %real128 %rq %logical %f + %date %da + %span %dr == p.p.arg :: @@ -2684,11 +2692,36 @@ :: [%limb p=(list jlimb)] ~| %limb ~ + :: + %noun + :: What we call nouns are specific types. + :: [%noun p=jnoun] + ?- -.p.arg + :: a string is simply a tape, (list @tD) + %string + ~| %string + ;; (list hoon) + :_ ~ + :- %knit + ^- * + p.p.arg + :: a path is a (list @t) + %path + ~| %path + :_ ~ + :- %clsg + %+ turn + p.p.arg + |= =cord + ^- hoon + [%sand %t cord] + == :: %list :: Lists are composed of a series of values, which we unpack. :: [%list type=jype-leaf val=(list jock)] ~| %list + ;; (list hoon) :_ ~ :- %clsg %- snip :: spurious ~ from Jock representation @@ -2732,12 +2765,20 @@ ^- jype-leaf :+ %atom ?+ p.t ~|("cannot convert atom type {} to jatom" !!) + %t %chars + %ta %chars + %tas %chars %ud %number - %ux %hexadecimal - %t %string - %ta %string - %tas %string + %sd %sint + %ux %hex + %x %hex + %rd %real + %rh %real16 + %rs %real32 + %rq %real128 %f %logical + %da %date + %dr %span == =(~ q.t) :: @@ -2828,17 +2869,17 @@ :: %atom %- crip - ?- ->-.jype + ?+ ->-.jype "{<(* +.nock)>}" %logical "{<;;(? +.nock)>}" :: %number "{<;;(@ud +.nock)>}" :: - %hexadecimal + %hex "{<;;(@ux +.nock)>}" :: - %string + %chars "{<;;(@t +.nock)>}" :: == From 5fbf967fcbdf302337db5b994fab09f7f737e4ea Mon Sep 17 00:00:00 2001 From: Sigilante Date: Mon, 5 Jan 2026 13:38:29 -0600 Subject: [PATCH 7/8] Post --- common/hoon/lib/jock.hoon | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index 7724743..415deba 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -1856,7 +1856,7 @@ ++ mint |= j=jock ^- [nock jype] - ?+ -.j ~|("cj: unimplmented jock: {<-.j>}" !!) + ?- -.j ::~|("cj: unimplemented jock: {<-.j>}" !!) ^ ~| %pair-p =+ [p p-jyp]=$(j p.j) @@ -2542,9 +2542,16 @@ == :: %atom + :: [%atom [type value] flag] ~| [%atom +<+.j] :- [%1 +<+.j] [^-(jype-leaf [%atom +<-.j +>.j]) %$] + :: + %noun + :: [%noun [type value]] + ~| [%noun +>.j] + :- [%1 +>.j] + [^-(jype-leaf [%noun +<.j]) %$] :: %import ~| %import @@ -2708,6 +2715,7 @@ :: a path is a (list @t) %path ~| %path + ~& "here in path" :_ ~ :- %clsg %+ turn @@ -2820,7 +2828,7 @@ ~|((crip "hunt: can't match {<`@tas`-<.jype>}") !!) :: %atom - ?> +.+.-.jype + ?> ->+.jype ::+.+.-.jype [%5 [%1 q.p.jype] %0 axis] :: %fork From 73477288b6de2b7e9e6286ffcdeca3112a607b5e Mon Sep 17 00:00:00 2001 From: Sigilante Date: Mon, 5 Jan 2026 16:26:33 -0600 Subject: [PATCH 8/8] Paths works correctly; Aliases stubbed in. --- common/hoon/lib/jock.hoon | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/common/hoon/lib/jock.hoon b/common/hoon/lib/jock.hoon index 415deba..ec124a7 100644 --- a/common/hoon/lib/jock.hoon +++ b/common/hoon/lib/jock.hoon @@ -191,6 +191,7 @@ %compose %loop %defer %recur %match %switch %eval %with %this %import %as %print + :: %for == :: ++ tagged-symbol @@ -224,14 +225,14 @@ ++ number %+ stag %number dem - :: Signed numeric literal: -1234, +1_234 -> @sd + :: Signed numeric literal: -1234, +1234 -> @sd ++ sint %+ stag %sint ;~ pose (cook |=(n=@ud (new:si & n)) ;~(pfix lus dem:ag)) (cook |=(n=@ud (new:si | n)) ;~(pfix hep dem:ag)) == - :: TODO switch to dep when fixed + :: TODO switch to dep when fixed for +1_234_678 support :: Hexadecimal literal: 0xBA1A3F, 0xba1a3f -> @x ++ hex %+ stag %hex @@ -408,7 +409,7 @@ :: [%impl] :: [%trait] :: [%union] - :: [%alias] + [%alias name=cord target=cord] [%class state=jype arms=(map term jock)] [%method type=jype body=jock] :: @@ -622,7 +623,7 @@ ^- [jock (list token)] ?: =(~ tokens) ~|("expect inner-jock. token: ~" !!) ?: ?| (has-keyword -.tokens %object) - :: (has-keyword -.tokens %class) + (has-keyword -.tokens %alias) (has-keyword -.tokens %with) (has-keyword -.tokens %this) (has-keyword -.tokens %crash) @@ -1031,6 +1032,17 @@ :: %')' consumed by +match-pair-inner-jock [[%call [%lambda lambda] `arg] tokens] :: + :: [%alias name=term target=term] + %alias + =/ name=cord + (got-name -.tokens) + =. tokens +.tokens + =/ target=cord + (got-name -.tokens) + =. tokens +.tokens + =- ~&(- -) + [[%alias name target] tokens] + :: :: [%class state=jype arms=(map term jock)] :: %class :: =^ state tokens @@ -1143,8 +1155,8 @@ :_ tokens [%compose p q] :: - %match :: [%match value=jock cases=(map jock jock) default=(unit jock)] + %match =^ value tokens (match-inner-jock tokens) =^ pairs tokens @@ -1152,8 +1164,8 @@ :_ tokens [%match value -.pairs +.pairs] :: - %switch :: [%cases value=jock cases=(map jock jock) default=(unit jock)] + %switch =^ value tokens (match-inner-jock tokens) =^ pairs tokens @@ -1931,6 +1943,11 @@ ~| ['have:' val-jyp 'need:' type.j] !! [val val-jyp] + :: + %alias + :: Look up the type being aliased in the current subject. + ~& "alias not implemented yet" + ~|("cj: unimplemented alias: {}" !!) :: %class ~| %class