Skip to content

Commit

Permalink
hoon, dprint: change doccords syntax to ::
Browse files Browse the repository at this point in the history
this constitutes a pretty major rework of how whitespace is handled in
hoon in order to change the doccords syntax from :> and :< to ::.

in summary: throughout the hoon parser (+vast) many instances of +gap
have been replaced by +jump, which first tries to remove whitespace (+leap)
until it arrives at something that can be parsed as a prefix
doccord (+apex:docs:vast). if it does not encounter a doccord, it
instead uses +gap as normal.

if you follow along with the parser, you will notice that every time
jump is called, it then tries to call +apex:docs via +scye or +seam. if
apex:docs succeeds, it will end up consuming a newline at the end,
hiding the fact that there was valid whitespace from the parser. thus
+apex:docs then inserts a newline after successfully parsing a prefix
doccord, which will then be consumed by a subsequent invocation of +gap,
ensuring that there was proper whitespace if the doccord would have been
consumed by +gap instead of +leap.

there are a few other changes:

+hint in the compiler throws out doccords attached to %noun types. this
was already the behavior before doccords, and the change was made before
i understood what i was doing.

similarly for commenting out the %note case in +open:ap - this was an
earlier mistake

postfix comments for chapters are now enabled.

+expx was unused and removed in order to be rid of the
convention-defying +exp1. other unused +ex(p/q)* were commented out.

arms that handle batch comments (+glow and +whap) were refactored

+toad, which was used to change between tall and wide form, tries to
+jump before +gap. since +jump is ;~(pose leap:docs gap), i would have
thought that just using +jump there would be fine, but it fails for some
reason.

some parsers built with |@ were rewritten to use |*

|$ was made so that any doccords put on the spec are converted into hoon
doccords on the $ arm. it wouldn't compile otherwise. there's probably a
more principled way to do this but it works fine for now.
  • Loading branch information
drbeefsupreme committed Nov 15, 2022
1 parent 49420e2 commit 5fc3b3f
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 407 deletions.
172 changes: 85 additions & 87 deletions pkg/arvo/lib/dprint.hoon
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/- *sole
::> a library for printing doccords
:: a library for printing doccords
::
=/ debug |
=>
:> types used by doccords
:: types used by doccords
|% %dprint-types
:> $overview: an overview of all named things in the type.
:>
:> each element in the overview list is either a documentation for a sublist
:> or an association betwen a term and documentation for it
:: $overview: an overview of all named things in the type.
::
:: each element in the overview list is either a documentation for a sublist
:: or an association betwen a term and documentation for it
+$ overview (list overview-item)
::
:> $overview-item: an element of an overview
:: $overview-item: an element of an overview
+$ overview-item
$% [%header doc=what children=overview]
[%item name=tape doc=what]
==
::
:> $item: the part of a type being inspected
:: $item: the part of a type being inspected
+$ item
$%
:: overview of a type
Expand Down Expand Up @@ -56,18 +56,18 @@
==
::
--
:> core containing doccords search and printing utilities
:: core containing doccords search and printing utilities
|% %dprint
:> contains arms used for looking for docs inside of a type
:>
:> the entrypoint for finding docs within a type is +find-item-in-type.
:: contains arms used for looking for docs inside of a type
::
:: the entrypoint for finding docs within a type is +find-item-in-type.
+| %searching
:> +find-item-in-type: returns the item to print while searching through topic
:>
:> this gate is optionally called recursively to find the path (topic) in the
:> type (sut). once it finds the correct part of the type, it switches to
:> +signify to describe that part of the type. recursion is turned off (for some
:> cases) when a hint type is found, in case it is wrapping a match.
:: +find-item-in-type: returns the item to print while searching through topic
::
:: this gate is optionally called recursively to find the path (topic) in the
:: type (sut). once it finds the correct part of the type, it switches to
:: +signify to describe that part of the type. recursion is turned off (for some
:: cases) when a hint type is found, in case it is wrapping a match.
++ find-item-in-type
|= [topics=(list term) sut=type]
=/ rec=? %.y
Expand Down Expand Up @@ -158,10 +158,10 @@
`[%arm (trip name) adoc pdoc cdoc u.arm p.sut]
--
::
:> +signify: changes a type into a item without docs
:>
:> this does not actually assign the docs, since they usually come from a hint
:> wrapping the type.
:: +signify: changes a type into a item without docs
::
:: this does not actually assign the docs, since they usually come from a hint
:: wrapping the type.
++ signify
|= sut=type
^- (unit item)
Expand Down Expand Up @@ -205,7 +205,7 @@
%void ~
==
::
:> +unwrap-hint: checks if a hint type is a help hint and returns the docs if so
:: +unwrap-hint: checks if a hint type is a help hint and returns the docs if so
++ unwrap-hint
|= sut=type
^- what
Expand All @@ -214,11 +214,11 @@
~
?>(?=(%help -.q.p.sut) `crib.p.q.p.sut)
::
:> +emblazon: inserts docs into an item
:>
:> when matching for a core or a face type, the docs for that type will be in
:> a hint that wraps it. thus we end up producing an item for that type, then
:> need to add the docs to it.
:: +emblazon: inserts docs into an item
::
:: when matching for a core or a face type, the docs for that type will be in
:: a hint that wraps it. thus we end up producing an item for that type, then
:: need to add the docs to it.
++ emblazon
|= [=item =what]
~? >> debug %emblazon
Expand All @@ -227,7 +227,7 @@
?([%core *] [%face *]) item(docs what)
==
::
:> +find-arm-in-coil: looks for an arm in a coil and returns its hoon
:: +find-arm-in-coil: looks for an arm in a coil and returns its hoon
++ find-arm-in-coil
|= [arm-name=term con=coil]
~? >> debug %find-arm-in-coil
Expand All @@ -241,7 +241,7 @@
$(tomes t.tomes)
`u.gen
::
:> +help-from-hint: gets the help from a %help $hint and returns it as a unit
:: +help-from-hint: gets the help from a %help $hint and returns it as a unit
++ help-from-hint
|= sut=type
^- (unit help)
Expand All @@ -257,17 +257,17 @@
`p.q.p.sut
==
::
:> +arm-product-docs: returns 0, 1, or 2 whats for an arm
:>
:> this arm should be handed the compiled type of the hoon of an arm, as well
:> as the name of that arm. it checks for up to 2 nested hints on the outermost
:> layer of the type. if you have 2, it is presumed to be arm-doc followed by
:> product-doc. if you only have one, we check .cuff in the $help of the hint
:> to determine whether it is an arm doc or product doc.
:>
:> this returns ~ if there are no docs. if there are docs, the first one is the
:> arm-doc, and the second one is the product-doc.
:>
:: +arm-product-docs: returns 0, 1, or 2 whats for an arm
::
:: this arm should be handed the compiled type of the hoon of an arm, as well
:: as the name of that arm. it checks for up to 2 nested hints on the outermost
:: layer of the type. if you have 2, it is presumed to be arm-doc followed by
:: product-doc. if you only have one, we check .cuff in the $help of the hint
:: to determine whether it is an arm doc or product doc.
::
:: this returns ~ if there are no docs. if there are docs, the first one is the
:: arm-doc, and the second one is the product-doc.
::
++ arm-product-docs
|= [sut=type name=term]
^- (unit [what what])
Expand Down Expand Up @@ -301,19 +301,19 @@
?> =(name ->.cuff.u.doc-one)
[~ [`crib.u.doc-one `crib.u.doc-two]]
::
:> +all-arm-docs: grabs the docs for an arm.
:>
:> there are three possible places with relevant docs for an arm:
:> docs for the arm itself, docs for the product of the arm, and
:> if the arm builds a core, docs for the default arm of that core.
:>
:> arm-doc: docs written above the the arm
:> product-doc: docs for the product of the arm
:> core-doc: docs for the default arm of the core produced by the arm
:> this will be the first of the arm-doc or product-doc on the default
:> arm. maybe this should be recursive and/or give both but its a decision
:> ill leave for later
:>
:: +all-arm-docs: grabs the docs for an arm.
::
:: there are three possible places with relevant docs for an arm:
:: docs for the arm itself, docs for the product of the arm, and
:: if the arm builds a core, docs for the default arm of that core.
::
:: arm-doc: docs written above the the arm
:: product-doc: docs for the product of the arm
:: core-doc: docs for the default arm of the core produced by the arm
:: this will be the first of the arm-doc or product-doc on the default
:: arm. maybe this should be recursive and/or give both but its a decision
:: ill leave for later
::
++ all-arm-docs
|= [gen=hoon sut=type name=tape]
~? > debug %all-arm-docs
Expand All @@ -337,10 +337,10 @@
?> ?=([%hint *] q.hoon-type)
(extract q.q.hoon-type)
==
:> +extract: grabs the first doc for the default arm of a core
:>
:> this could end up being an arm doc or a product doc.
:>
:: +extract: grabs the first doc for the default arm of a core
::
:: this could end up being an arm doc or a product doc.
::
++ extract
|= sut=type
^- what
Expand All @@ -357,11 +357,11 @@
`what``crib.u.hel
--
::
:> +arm-and-chapter-overviews: returns an overview of a cores contents
:>
:> returns an overview for arms which are part of unnamed chapters, and
:> an overview of the named chapters
:>
:: +arm-and-chapter-overviews: returns an overview of a cores contents
::
:: returns an overview for arms which are part of unnamed chapters, and
:: an overview of the named chapters
::
++ arm-and-chapter-overviews
|= [sut=type con=coil core-name=tape]
^- [overview overview]
Expand All @@ -383,30 +383,30 @@
[%item :(weld "^" core-name "|" (trip -.current)) p.q.current]~
$(tomes t.tomes)
::
:> +arms-in-chapter: returns an overview of the arms in a specific chapter
:: +arms-in-chapter: returns an overview of the arms in a specific chapter
++ arms-in-chapter
|= [sut=type con=coil name=tape]
^- overview
=/ tom=tome (~(got by q.r.con) (crip name))
(sort-overview (arms-as-overview q.tom sut))
::
:> +sort-overview: sort items in an overview in alphabetical order
:: +sort-overview: sort items in an overview in alphabetical order
++ sort-overview
|= ovr=overview
^- overview
%+ sort ovr
|= [lhs=overview-item rhs=overview-item]
(aor (get-overview-name lhs) (get-overview-name rhs))
::
:> +get-overview-name: returns the name of an overview
:: +get-overview-name: returns the name of an overview
++ get-overview-name
|= ovr=overview-item
?- ovr
[%header *] ""
[%item *] name.ovr
==
::
:> +arms-as-overview: translate a tome into an overview
:: +arms-as-overview: translate a tome into an overview
++ arms-as-overview
|= [a=(map term hoon) sut=type]
^- overview
Expand All @@ -415,16 +415,14 @@
=+ [adoc pdoc cdoc]=(all-arm-docs q.ar sut (trip p.ar))
[%item (weld "+" (trip p.ar)) adoc]
::
:> +item-as-overview: changes an item into an overview
:: +item-as-overview: changes an item into an overview
++ item-as-overview
|= uit=(unit item)
~? >> debug %item-as-overview
^- overview
?~ uit ~
=+ itm=(need uit)
?- itm
::
::
[%view *] items.itm
::
[%core *]
Expand All @@ -445,17 +443,17 @@
[%item (weld "." name.itm) docs.itm]~
==
::
:> +join-items: combines two (unit items) together
:: +join-items: combines two (unit items) together
++ join-items
|= [lhs=(unit item) rhs=(unit item)]
^- (unit item)
?~ lhs rhs
?~ rhs lhs
`[%view (weld (item-as-overview lhs) (item-as-overview rhs))]
::
:> contains arms using for printing doccords items
:: contains arms using for printing doccords items
+| %printing
:> +print-item: prints a doccords item
:: +print-item: prints a doccords item
++ print-item
|= =item
~? >> debug %print-item
Expand All @@ -468,7 +466,7 @@
[%face *] (print-face +.item)
==
::
:> +print-core: renders documentation for a full core
:: +print-core: renders documentation for a full core
++ print-core
|= [name=tape docs=what sut=type con=coil uit=(unit item)]
^- (list sole-effect)
Expand All @@ -491,7 +489,7 @@
(print-overview [%header `['compiled against: ' ~] compiled]~ styles)
==
::
:> +print-chapter: renders documentation for a single chapter
:: +print-chapter: renders documentation for a single chapter
++ print-chapter
|= [name=tape doc=what sut=type con=coil]
^- (list sole-effect)
Expand All @@ -506,7 +504,7 @@
(print-overview [%header `['arms:' ~] arms]~ styles)
==
::
:> +print-arm: renders documentation for a single arm in a core
:: +print-arm: renders documentation for a single arm in a core
++ print-arm
|= [name=tape adoc=what pdoc=what cdoc=what gen=hoon sut=type]
^- (list sole-effect)
Expand All @@ -521,7 +519,7 @@
(print-header "" cdoc)
==
::
:> +print-face: renders documentation for a face
:: +print-face: renders documentation for a face
++ print-face
|= [name=tape doc=what children=(unit item)]
^- (list sole-effect)
Expand All @@ -534,7 +532,7 @@
(print-item u.children)
==
::
:> +print-header: prints name and docs only
:: +print-header: prints name and docs only
++ print-header
|= [name=tape doc=what]
^- (list sole-effect)
Expand All @@ -551,10 +549,10 @@
== ==
==
::
:> +print-overview: prints summaries of several items
:>
:> the (list styl) provides styles for each generation of child
:> items
:: +print-overview: prints summaries of several items
::
:: the (list styl) provides styles for each generation of child
:: items
++ print-overview
|= [=overview styles=(pair styl styl)]
~? >> debug %print-overview
Expand Down Expand Up @@ -591,9 +589,9 @@
==
==
::
:> +print-sections: renders a list of sections as tang
:>
:> prints the longform documentation
:: +print-sections: renders a list of sections as tang
::
:: prints the longform documentation
++ print-sections
|= sections=(list sect)
^- tang
Expand All @@ -608,7 +606,7 @@
==
$(sections t.sections)
::
:> +print-section: renders a sect as a tang
:: +print-section: renders a sect as a tang
++ print-section
|= section=sect
^- tang
Expand All @@ -619,7 +617,7 @@
[%leaf (trip q.pica)]
[%leaf " {(trip q.pica)}"]
::
:> +styled: makes $sole-effects out of $styls and $cords
:: +styled: makes $sole-effects out of $styls and $cords
++ styled
|= [in=(list (pair styl cord))]
^- (list sole-effect)
Expand Down

0 comments on commit 5fc3b3f

Please sign in to comment.