Skip to content

Commit

Permalink
Added Hoon programming language (#2978)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Schmidt <mitchi5000.ms@googlemail.com>
  • Loading branch information
matildepark and RunDevelopment authored Jul 3, 2021
1 parent 158f25d commit ea77675
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 1 deletion.
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
19 changes: 19 additions & 0 deletions components/prism-hoon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Prism.languages.hoon = {
'constant': /%(?:\.[ny]|[\w-]+)/,
'comment': {
pattern: /::.*/,
greedy: true
},
'function': /(?:\+[-+] {2})?(?:[a-z](?:[a-z0-9-]*[a-z0-9])?)/,
'class-name': [
{
pattern: /@(?:[A-Za-z0-9-]*[A-Za-z0-9])?/,
},
/\*/
],
'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>
5 changes: 5 additions & 0 deletions tests/identifier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const testOptions = {
word: false,
template: false
},
// Hoon uses _ in its keywords
'hoon': {
word: false,
template: false
},

// LilyPond doesn't tokenize based on words
'lilypond': {
Expand Down
59 changes: 59 additions & 0 deletions tests/languages/hoon/comments_and_leaves.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
:: 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", "now"],
"=",
["class-name", "@"],
["function", "da"],
["function", "ovo"],
"=",
["class-name", "*"],
"]\r\n ",

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

["keyword", "~>"],
["constant", "%slog"],
".[0 ",
["function", "leaf"],
"+",
["string", "\"arvo-event\""],
"]\r\n .(+> +:(",
["function", "poke"],
["function", "now"],
["function", "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", "++ add"],

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

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

["comment", "::"],

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

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

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

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

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

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

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

["comment", "::"],

["function", "++ dec"]
]

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

Tests for a sample definition of a core with an arm.
124 changes: 124 additions & 0 deletions tests/languages/hoon/nested_strings.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
|= [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", "a"],
"=",
["class-name", "@"],
["function", "b"],
"=",
["function", "tape"],
"]\r\n",

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

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

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

["keyword", "|="],
["function", "c"],
"=",
["class-name", "@"],
["function", "t"],
"D\r\n",

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

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

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

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

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

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

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

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

["function", "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.

0 comments on commit ea77675

Please sign in to comment.