mirror of
https://github.com/urbit/shrub.git
synced 2024-10-26 21:09:47 +03:00
neo: doccords visualiser
This commit is contained in:
parent
10a722668d
commit
ccbb0a5896
@ -1,5 +1,165 @@
|
||||
=/ prelude !>(.)
|
||||
:- [%vase %$ %htmx]
|
||||
|= vax=vase
|
||||
|= =bowl:neo
|
||||
;/
|
||||
(of-wall:format (~(win re (sell vax)) 0 80))
|
||||
=/ depth=@ud 2
|
||||
=/ ty p.vax
|
||||
|- ^- manx
|
||||
=* loop $
|
||||
|^ ^- manx
|
||||
?: =(depth 0)
|
||||
;/ "Bottoming out"
|
||||
=/ arms (slow:neo ty)
|
||||
=/ items=(list item:dprint:neo)
|
||||
(zing (turn arms |=(ls=(list term) `(list item:dprint:neo)`(drop (find-item-in-type:dprint:neo ls ty)))))
|
||||
;div
|
||||
;* (turn items print-item)
|
||||
==
|
||||
++ print-item
|
||||
|= val=item:dprint:neo
|
||||
^- manx
|
||||
?+ -.val ;/ "Unsupported {(trip -.val)}"
|
||||
%core (print-core +.val)
|
||||
%chapter (print-chapter +.val)
|
||||
%arm (print-arm +.val)
|
||||
%view
|
||||
;div
|
||||
;* (turn items.val print-overview-item)
|
||||
==
|
||||
==
|
||||
++ print-overview-item
|
||||
|= tim=overview-item:dprint:neo
|
||||
^- manx
|
||||
?- -.tim
|
||||
%header (print-overview-header +.tim)
|
||||
%item (print-overview-item-actual +.tim)
|
||||
==
|
||||
++ print-overview-header
|
||||
|= [doc=what children=overview:dprint:neo]
|
||||
^- manx
|
||||
;div
|
||||
;* (print-what "" doc)
|
||||
:+ (print-overview children)
|
||||
==
|
||||
++ print-overview-item-actual
|
||||
|= [name=tape doc=what]
|
||||
;div
|
||||
;div: {name}
|
||||
;* (print-what "" doc)
|
||||
==
|
||||
++ print-core
|
||||
|= $: name=tape :: arm that built it
|
||||
docs=what ::
|
||||
sut=type :: [%core *]
|
||||
children=(unit item:dprint:neo) :: compiled against
|
||||
==
|
||||
^- manx
|
||||
;div
|
||||
;h3
|
||||
; Core
|
||||
; {name}
|
||||
==
|
||||
;div
|
||||
;* (print-what "" docs)
|
||||
;div: Children
|
||||
;+ loop(ty sut)
|
||||
==
|
||||
==
|
||||
++ print-chapter
|
||||
|= $: name=tape :: name of chapter
|
||||
docs=what ::
|
||||
sut=type :: [%core *]
|
||||
tom=tome :: tome of chapter
|
||||
==
|
||||
^- manx
|
||||
;div
|
||||
;h3
|
||||
; Chapter
|
||||
; {name}
|
||||
==
|
||||
;div
|
||||
;* (print-what "Overview" docs)
|
||||
;* (print-what "Tome" p.tom)
|
||||
;*
|
||||
%+ turn ~(tap by q.tom)
|
||||
|= [=term =hoon]
|
||||
^- manx
|
||||
;span: Arm {(trip term)}
|
||||
:: loop(vax (slap sut wing/~[term]), depth (dec depth))
|
||||
:: loop(ty (~(play ut sut) hoon), depth (dec depth))
|
||||
==
|
||||
==
|
||||
++ print-arm
|
||||
|= $:
|
||||
name=tape :: arm name
|
||||
adoc=what :: arm doc
|
||||
pdoc=what :: product doc
|
||||
cdoc=what :: $ arm/prod doc
|
||||
gen=hoon :: arm hoon AST
|
||||
sut=type :: subject of arm
|
||||
==
|
||||
=/ t (~(play ut sut) gen)
|
||||
|
||||
^- manx
|
||||
;div
|
||||
;h3
|
||||
; +
|
||||
; {name}
|
||||
==
|
||||
;div
|
||||
;details
|
||||
;summary: Signature
|
||||
;code
|
||||
;pre
|
||||
;*
|
||||
%+ turn (wash [0 80] ~(duck easy-print:neo t))
|
||||
|= tap=tape
|
||||
;div: {tap}
|
||||
==
|
||||
==
|
||||
==
|
||||
;div: Docs
|
||||
;* (print-what "" adoc)
|
||||
;* (print-what "Product" pdoc)
|
||||
;* (print-what "$" cdoc)
|
||||
==
|
||||
;div: Children
|
||||
;+
|
||||
loop(ty (~(play ut ty) gen), depth (dec depth))
|
||||
==
|
||||
::
|
||||
++ print-what
|
||||
|= [name=tape wat=what]
|
||||
^- (list manx)
|
||||
?~ wat
|
||||
~
|
||||
:_ ~
|
||||
?: =(~ q.u.wat)
|
||||
;div
|
||||
; {(trip p.u.wat)}
|
||||
==
|
||||
;details
|
||||
;summary
|
||||
; {(trip p.u.wat)}
|
||||
==
|
||||
;div
|
||||
;* (turn q.u.wat print-sect)
|
||||
==
|
||||
==
|
||||
++ print-sect
|
||||
|= sec=sect
|
||||
^- manx
|
||||
;div.p2
|
||||
;* (turn sec print-pica)
|
||||
==
|
||||
++ print-pica
|
||||
|= pic=pica
|
||||
^- manx
|
||||
?: p.pic
|
||||
;div.prose
|
||||
; {(trip q.pic)}
|
||||
==
|
||||
;code
|
||||
; {(trip q.pic)}
|
||||
==
|
||||
--
|
||||
|
@ -329,7 +329,7 @@
|
||||
:: ignored shrubs
|
||||
?=([[%p @] %cod %grab *] heer)
|
||||
?=([[%p @] %cod %grow *] heer)
|
||||
?=([[%p @] %cod %std %out *] heer)
|
||||
:: ?=([[%p @] %cod %std %out *] heer)
|
||||
?=([[%p @] %cod %std %pre *] heer)
|
||||
?=([[%p @] %out *] heer)
|
||||
?=([[%p @] %srv *] heer)
|
||||
|
@ -2,7 +2,6 @@
|
||||
/@ dm-diff
|
||||
/@ groupchat-diff
|
||||
/@ messenger-diff
|
||||
^- kook:neo
|
||||
=>
|
||||
|%
|
||||
++ send-invites
|
||||
@ -18,8 +17,21 @@
|
||||
::
|
||||
|%
|
||||
++ state pro/%messenger
|
||||
++ poke (sy %dm-diff %groupchat-diff %messenger-diff ~)
|
||||
:: +poke: The poke types
|
||||
::
|
||||
:: We allow for the three different kinds of diffs that we support
|
||||
::
|
||||
++ poke
|
||||
:: %dm-diff is for creating DMs
|
||||
(sy %dm-diff %groupchat-diff %messenger-diff ~)
|
||||
:: +kids: Children for messenger
|
||||
++ kids
|
||||
:: Child constraints
|
||||
::
|
||||
:: All children under this tree either are DMs, or groupchats
|
||||
:: Dms are identified by @p
|
||||
:: Groupchats are identified by [@p @t]
|
||||
::
|
||||
:+ ~ %y
|
||||
%- ~(gas by *lads:neo)
|
||||
:~ :- [&/%dms |/%p |]
|
||||
@ -29,7 +41,7 @@
|
||||
==
|
||||
++ deps *deps:neo
|
||||
++ form
|
||||
^- form:neo
|
||||
:: ^- form:neo
|
||||
|_ [=bowl:neo =aeon:neo state=pail:neo]
|
||||
++ init
|
||||
|= old=(unit pail:neo)
|
||||
|
189
pkg/arvo/neo/cod/std/src/lib/deco.hoon
Normal file
189
pkg/arvo/neo/cod/std/src/lib/deco.hoon
Normal file
@ -0,0 +1,189 @@
|
||||
:: Hoon doccords sample
|
||||
::
|
||||
:: this is a sample file designed to explain syntax and conventions
|
||||
:: for doccords
|
||||
::
|
||||
:: all lines must be under 80 characters. no blank lines.
|
||||
:: any line longer than 60 characters is probably too long.
|
||||
:: uppercase or non-ascii letters are strongly discouraged.
|
||||
::
|
||||
:: whenever possible, use formal decorations. {::} decorates
|
||||
:: the next expression when put on its own line, and the previous
|
||||
:: expression if written on the same line
|
||||
::
|
||||
:: there are two places to put decorations: in line with the
|
||||
:: code, and on the right margin.
|
||||
::
|
||||
:: the file below is a well-commented library, built around
|
||||
:: a typical two-core structure. the cores are labeled {%arch}
|
||||
:: (structures) and {%work} (productions).
|
||||
::
|
||||
:: this code is written to display the variety of formatting
|
||||
:: options the parser allows. a specific convention should pick
|
||||
:: one of these styles and stick to it.
|
||||
::
|
||||
:: there are three ways to mark the beginning of a formal comment:
|
||||
:: 1- {:: $foo:}
|
||||
:: 2- {:: +bar:}
|
||||
:: 3- {:: }
|
||||
::
|
||||
:: style 1 may optionally be followed by a series of paragraphs, where each
|
||||
:: paragraph is preceded by a line containing only {::} and whitespace, and
|
||||
:: each line of a given paragraph is preceded by four aces.
|
||||
:: {::}
|
||||
:: {:: more text}
|
||||
:: {:: even more text}
|
||||
:: {::}
|
||||
:: {:: |=(code=hoon !!)}
|
||||
::
|
||||
:: style 2 is much like style 1, but paragraphs are indented by two spaces
|
||||
:: instead of four.
|
||||
:: {::}
|
||||
:: {:: more text}
|
||||
:: {:: even more text}
|
||||
:: {::}
|
||||
:: {:: |=(code=hoon !!)}
|
||||
::
|
||||
:: code is indented a total of six aces, for either style.
|
||||
::
|
||||
:: style 3 is used to annotate the hoon or spec that immediately follows
|
||||
:: the comment. paragraphs are written with style 2.
|
||||
::
|
||||
:: the $foo and +bar above are examples of *lexical locations* for
|
||||
:: style and batch-commenting purposes. this tells the parser to attempt
|
||||
:: to attach the comment to the specified location. these locations
|
||||
:: may be written as follows:
|
||||
:: - `|foo` means a chapter
|
||||
:: - `%foo` means a constant
|
||||
:: - `.foo` means a face
|
||||
:: - `+foo` means an arm
|
||||
:: - `$foo` means a spec
|
||||
:: - `^foo` means a core
|
||||
:: - `_foo` means a door
|
||||
:: - `=foo` means a gate
|
||||
:: - `/foo` means a file path segment
|
||||
::
|
||||
:: thus /lib/foo^widget|initial=open means the =open gate in the |initial
|
||||
:: chapter of the ^widget core in the /foo library
|
||||
::
|
||||
:: at present, doccords does not support lexical locations in full.
|
||||
:: only single-element locations of the form `$foo` and `+foo` are supported,
|
||||
:: and must be written above an arm in the core to which they are to be
|
||||
:: attached, and after the chapter they are in (if the core has chapters).
|
||||
:: you may still write doccords for other locations in anticipation of the
|
||||
:: fully supported lexical location, but they will be thrown away before they
|
||||
:: make it to the compiler.
|
||||
::
|
||||
:: a postfix formal comment will either attach to hoon or spec on the
|
||||
:: current line, or the arm name if there is no hoon or spec on the
|
||||
:: line. the convention for +$ arms is that the comment attached to the
|
||||
:: arm is about the mold itself, while the comment attached to the spec
|
||||
:: is about the output type of the mold.
|
||||
::
|
||||
:: to inspect doccords in this file from dojo, try the following:
|
||||
::
|
||||
:: > =deco -build-file %/lib/deco/hoon
|
||||
:: > # deco
|
||||
:: > # deco/arch
|
||||
:: > # deco/arch/molds
|
||||
:: > # deco/arch/molds/goof
|
||||
::
|
||||
:: > ?? *goof:deco
|
||||
::
|
||||
=> ::
|
||||
:: structures for our imaginary hello, world generator.
|
||||
::
|
||||
:: nothing forces us to put structures in a separate core.
|
||||
:: but compile-time evaluation doesnt work in the current
|
||||
:: core; we often want to statically evaluate structures.
|
||||
::
|
||||
:: there are three kinds of structures: moldss (normalizing
|
||||
:: functions), mold builders (functions that build molds), and
|
||||
:: constants (static data).
|
||||
::
|
||||
:: most code will not need its own mold builders. but put them
|
||||
:: in a separate chapter (separated by {+|}).
|
||||
|%
|
||||
:: molds are functions that normalize nouns.
|
||||
::
|
||||
:: arms producing molds are introduced with {+$}. the
|
||||
:: compiler will copy the arm decoration onto its product
|
||||
+| %molds
|
||||
:: $jam: some delicious jam
|
||||
:: $jelly: different from jam?
|
||||
+$ spot [p=@ q=@] :: a coordinate
|
||||
+$ tops :: mold for coordinate
|
||||
[p=@ q=@] :: another coordinate
|
||||
+$ goof :: a simple tuple mold
|
||||
$: foo=@ :: something mysterious
|
||||
bar=@ :: go here for drink
|
||||
moo=(binary-tree juice) :: cows do this
|
||||
==
|
||||
+$ juice :: fruity beverage mold
|
||||
$% [%plum p=@] :: fresh prune
|
||||
[%pear p=@ q=@] :: good for cider
|
||||
[%acai p=@] :: aztec superfood
|
||||
==
|
||||
+$ jam @tas
|
||||
+$ jelly @tas
|
||||
:: mold builders are functions that build molds from other molds
|
||||
::
|
||||
:: other languages might call these "type constructors"
|
||||
:: or "higher-kinded types".
|
||||
+| %mold-builders
|
||||
++ binary-tree :: tree mold builder
|
||||
|* a=$-(* *)
|
||||
$@(~ [n=a l=(binary-tree a) r=(binary-tree a)])
|
||||
::
|
||||
:: if you have constants, put them in their own chapter.
|
||||
+| %constant
|
||||
++ answer :: answer to everything
|
||||
42
|
||||
--
|
||||
:: engines for our imaginary hello, world app.
|
||||
::
|
||||
|%
|
||||
:: +default-jam: bunts $jam
|
||||
:: +default-juice: bunts $juice
|
||||
++ say-hello :: say hi to someone
|
||||
:: friendly welcome message
|
||||
::
|
||||
|=
|
||||
:: .txt: friend to say hi to
|
||||
::
|
||||
txt=term
|
||||
^- tape
|
||||
"hello, {(rip 3 txt)}"
|
||||
:: +say-goodbye: say a really proper goodbye
|
||||
::
|
||||
:: some paragraphs about the goodbye algorithm, possibly
|
||||
:: including code indented by four extra spaces:
|
||||
::
|
||||
:: ?: =(%hello %world)
|
||||
:: %hello
|
||||
:: %world
|
||||
::
|
||||
++ say-goodbye
|
||||
:: describe product of function
|
||||
::
|
||||
|=
|
||||
:: .txt: departing friend
|
||||
:: .num: number of friends
|
||||
$: txt=term
|
||||
num=@
|
||||
==
|
||||
^- tape
|
||||
:: .foo: four
|
||||
:: .bar: forty-two
|
||||
=/ foo (add 2 2)
|
||||
=/ bar (add (mul num foo) 2)
|
||||
=/ moo (mul num bar) :: for all the cows
|
||||
"goodbye and {(scow %ud moo)}, {(rip 3 txt)}"
|
||||
::
|
||||
++ say-minimum :: minimal decoration
|
||||
|= txt=term
|
||||
"nothing to say to {(rip 3 txt)}"
|
||||
::
|
||||
++ default-jam *jam
|
||||
++ default-juice *juice
|
||||
--
|
@ -1,7 +1,5 @@
|
||||
|_ a=manx
|
||||
:: named
|
||||
::
|
||||
:: first child with name=tape, or null
|
||||
:: +named: first child with name=tape, or null
|
||||
::
|
||||
++ named
|
||||
|= name=tape
|
||||
@ -12,9 +10,7 @@
|
||||
=((~(gut by (malt a.g.manx)) %name "") name)
|
||||
?: =(0 (lent n)) ~
|
||||
`(snag 0 n)
|
||||
:: get
|
||||
::
|
||||
:: tape at attribute, or null
|
||||
:: +get: tape at attribute, or null
|
||||
::
|
||||
++ get
|
||||
|= =mane
|
||||
|
@ -1,3 +1,5 @@
|
||||
/+ dprint
|
||||
/+ easy-print=language-server-easy-print
|
||||
:: $neo: New Shrub
|
||||
::
|
||||
:: Urbit is a namespace, from a path -> data
|
||||
@ -1705,8 +1707,10 @@
|
||||
:: Ending with | indicates that the path match stops
|
||||
::
|
||||
+$ pish
|
||||
$+ pish
|
||||
$@(? [i=dita t=pish])
|
||||
+$ rail
|
||||
$+ rail
|
||||
$@(? [i=zeta t=rail])
|
||||
+$ conf (map term pith)
|
||||
+$ crew (map term pith)
|
||||
@ -2028,8 +2032,8 @@
|
||||
+$ deps band
|
||||
:: $band: Dependencies
|
||||
::
|
||||
+$ band (map term fief)
|
||||
+$ lads (map pish lash)
|
||||
+$ band $+(band (map term fief))
|
||||
+$ lads $+(lads (map pish lash))
|
||||
+$ dare ?(%y %z)
|
||||
+$ port (pair dare lads)
|
||||
+$ kids (unit port)
|
||||
@ -2255,4 +2259,20 @@
|
||||
?(%t %ta %tas) (aor q.a q.b)
|
||||
==
|
||||
::
|
||||
++ dprint ^dprint
|
||||
++ easy-print ^easy-print
|
||||
++ slow :: get arms in core
|
||||
|= typ=type
|
||||
^- (list (list term))
|
||||
?+ typ ~
|
||||
[%hold *] $(typ ~(repo ut typ))
|
||||
[%hint *] $(typ ~(repo ut typ))
|
||||
[%core *]
|
||||
%- zing
|
||||
%+ turn ~(tap by q.r.q.typ)
|
||||
|= [a=term b=tome]
|
||||
%+ turn ~(tap by q.b)
|
||||
|= [c=term *]
|
||||
~[a c]
|
||||
==
|
||||
--
|
||||
|
1
pkg/shrub/lib/dprint.hoon
Symbolic link
1
pkg/shrub/lib/dprint.hoon
Symbolic link
@ -0,0 +1 @@
|
||||
../../arvo/lib/dprint.hoon
|
@ -1 +1 @@
|
||||
../../base-dev/mar/txt.hoon
|
||||
../../arvo/mar/txt.hoon
|
Loading…
Reference in New Issue
Block a user