Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

components: add hoon programming language #2978

Merged
merged 15 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@
"require": "c",
"owner": "RunDevelopment"
},
"hoon": {
"title": "Hoon",
"owner": "matildepark"
},
"http": {
"title": "HTTP",
"optional": [
Expand Down
21 changes: 21 additions & 0 deletions components/prism-hoon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Prism.languages.hoon = {
'constant': /%(?:\.[ny]|[\w-]+)/,
'comment': {
pattern: /::.*/,
lookahead: true,
matildepark marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
},
'function': /(?:\+[-+] {2})?(?:[a-z]([a-z0-9-]*[a-z0-9])?)/,
matildepark marked this conversation as resolved.
Show resolved Hide resolved
'class-name': [
{
pattern: /@(?:[A-Za-z0-9-]*[A-Za-z0-9])?/,
lookahead: true,
},
/\*/
],
'string': {
pattern: /"[^"]*"|'[^']*'/,
greedy: true
},
'keyword': /:_|\.[\^\+\*=\?]|![><:\.=\?!]|=[>|:,\.\-\^<+;/~\*\?]|\?[>|:\.\-\^<\+&~=@!]|\|[\$_%:\.\-\^~\*=@\?]|\+[|\$\+\*]|:[_\-\^\+~\*]|%[_:\.\-\^\+~\*=]|\^[|:\.\-\+&~\*=\?]|\$[|_%:<>\-\^&~@=\?]|;[:<\+;\/~\*=]|~[>|\$_%<\+\/&=\?!]|--|==/
};
1 change: 1 addition & 0 deletions components/prism-hoon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/prism-hoon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h2>Caesar cipher</h2>

<pre><code>|= [a=@ b=tape]
^- tape
?: (gth a 25)
$(a (sub a 26))
%+ turn b
|= c=@tD
?: &((gte c 'A') (lte c 'Z'))
=. c (add c a)
?. (gth c 'Z') c
(sub c 26)
?: &((gte c 'a') (lte c 'z'))
=. c (add c a)
?. (gth c 'z') c
(sub c 26)
c</code></pre>
58 changes: 58 additions & 0 deletions tests/languages/hoon/comments_and_leaves.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
:: Arvo formal interface
::
:: this lifecycle wrapper makes the arvo door (multi-armed core)
:: look like a gate (function or single-armed core), to fit
:: urbit's formal lifecycle function. a practical interpreter
:: can ignore it.
::
|= [now=@da ovo=*]
^- *
~> %slog.[0 leaf+"arvo-event"]
.(+> +:(poke now ovo))

----------------------------------------------------

[
["comment", ":: Arvo formal interface"],

["comment", "::"],

["comment", ":: this lifecycle wrapper makes the arvo door (multi-armed core)"],

["comment", ":: look like a gate (function or single-armed core), to fit"],

["comment", ":: urbit's formal lifecycle function. a practical interpreter"],

["comment", ":: can ignore it."],

["comment", "::"],

["keyword", "|="],
" [",
["function-name", "now"],
"=",
["class-name", "@da"],
["function-name", "ovo"],
"=",
["class-name", "*"],
"]\r\n ",

["keyword", "^-"],
["class-name", "*"],

["keyword", "~>"],
["constant", "%slog"],
".[0 ",
["function-name", "leaf"],
"+",
["string", "\"arvo-event\""],
"]\r\n .(+> +:(",
["function-name", "poke"],
["function-name", "now"],
["function-name", "ovo"],
"))"
]

----------------------------------------------------

Tests for block comments and the inclusion of tapes and leaves inline in cells.
83 changes: 83 additions & 0 deletions tests/languages/hoon/core_with_arms.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
|%
:: # %math
:: unsigned arithmetic
+| %math
++ add
~/ %add
:: unsigned addition
::
:: a: augend
:: b: addend
|= [a=@ b=@]
:: sum
^- @
?: =(0 a) b
$(a (dec a), b +(b))
::
++ dec

----------------------------------------------------

[
["keyword", "|%"],

["comment", ":: # %math"],

["comment", ":: unsigned arithmetic"],

["keyword", "+|"],
["constant", "%math"],

["function-name", "++ add"],

["keyword", "~/"],
["constant", "%add"],

["comment", ":: unsigned addition"],

["comment", "::"],

["comment", ":: a: augend"],

["comment", ":: b: addend"],

["keyword", "|="],
" [",
["function-name", "a"],
"=",
["class-name", "@"],
["function-name", "b"],
"=",
["class-name", "@"],
"]\r\n ",

["comment", ":: sum"],

["keyword", "^-"],
["class-name", "@"],

["keyword", "?:"],
" =(0 ",
["function-name", "a"],
") ",
["function-name", "b"],

"\r\n $(",
["function-name", "a"],
" (",
["function-name", "dec"],
["function-name", "a"],
"), ",
["function-name", "b"],
" +(",
["function-name", "b"],
"))\r\n",

["comment", "::"],

["function-name", "++ dec"]
]

----------------------------------------------------

Tests for a sample definition of a core with an arm.
122 changes: 122 additions & 0 deletions tests/languages/hoon/nested_strings.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
|= [a=@ b=tape]
^- tape
?: (gth a 25)
$(a (sub a 26))
%+ turn b
|= c=@tD
?: &((gte c 'A') (lte c 'Z'))
=. c (add c a)
?. (gth c 'Z') c
(sub c 26)
?: &((gte c 'a') (lte c 'z'))
=. c (add c a)
?. (gth c 'z') c
(sub c 26)
c

----------------------------------------------------

[
["keyword", "|="],
" [",
["function-name", "a"],
"=",
["class-name", "@"],
["function-name", "b"],
"=",
["function-name", "tape"],
"]\r\n",

["keyword", "^-"],
["function-name", "tape"],

["keyword", "?:"],
" (",
["function-name", "gth"],
["function-name", "a"],
" 25)\r\n $(",
["function-name", "a"],
" (",
["function-name", "sub"],
["function-name", "a"],
" 26))\r\n",

["keyword", "%+"],
["function-name", "turn"],
["function-name", "b"],

["keyword", "|="],
["function-name", "c"],
"=",
["class-name", "@tD"],

["keyword", "?:"],
" &((",
["function-name", "gte"],
["function-name", "c"],
["string", "'A'"],
") (",
["function-name", "lte"],
["function-name", "c"],
["string", "'Z'"],
"))\r\n ",

["keyword", "=."],
["function-name", "c"],
" (",
["function-name", "add"],
["function-name", "c"],
["function-name", "a"],
")\r\n ",

["keyword", "?."],
" (",
["function-name", "gth"],
["function-name", "c"],
["string", "'Z'"],
") ",
["function-name", "c"],

"\r\n (",
["function-name", "sub"],
["function-name", "c"],
" 26)\r\n",

["keyword", "?:"],
" &((",
["function-name", "gte"],
["function-name", "c"],
["string", "'a'"],
") (",
["function-name", "lte"],
["function-name", "c"],
["string", "'z'"],
"))\r\n ",

["keyword", "=."],
["function-name", "c"],
" (",
["function-name", "add"],
["function-name", "c"],
["function-name", "a"],
")\r\n ",

["keyword", "?."],
" (",
["function-name", "gth"],
["function-name", "c"],
["string", "'z'"],
") ",
["function-name", "c"],

"\r\n (",
["function-name", "sub"],
["function-name", "c"],
" 26)\r\n",

["function-name", "c"]
]

----------------------------------------------------

Tests using the Caesar cipher to demonstrate multiple occasions of cords and tapes on the same line, correcting avoiding clobbering two cord and tape definitions into one.