Skip to content

Commit ea77675

Browse files
Added Hoon programming language (#2978)
Co-authored-by: Michael Schmidt <[email protected]>
1 parent 158f25d commit ea77675

9 files changed

+313
-1
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@
518518
"require": "c",
519519
"owner": "RunDevelopment"
520520
},
521+
"hoon": {
522+
"title": "Hoon",
523+
"owner": "matildepark"
524+
},
521525
"http": {
522526
"title": "HTTP",
523527
"optional": [

components/prism-hoon.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Prism.languages.hoon = {
2+
'constant': /%(?:\.[ny]|[\w-]+)/,
3+
'comment': {
4+
pattern: /::.*/,
5+
greedy: true
6+
},
7+
'function': /(?:\+[-+] {2})?(?:[a-z](?:[a-z0-9-]*[a-z0-9])?)/,
8+
'class-name': [
9+
{
10+
pattern: /@(?:[A-Za-z0-9-]*[A-Za-z0-9])?/,
11+
},
12+
/\*/
13+
],
14+
'string': {
15+
pattern: /"[^"]*"|'[^']*'/,
16+
greedy: true
17+
},
18+
'keyword': /:_|\.[\^\+\*=\?]|![><:\.=\?!]|=[>|:,\.\-\^<+;/~\*\?]|\?[>|:\.\-\^<\+&~=@!]|\|[\$_%:\.\-\^~\*=@\?]|\+[|\$\+\*]|:[_\-\^\+~\*]|%[_:\.\-\^\+~\*=]|\^[|:\.\-\+&~\*=\?]|\$[|_%:<>\-\^&~@=\?]|;[:<\+;\/~\*=]|~[>|\$_%<\+\/&=\?!]|--|==/
19+
};

components/prism-hoon.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-hoon.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Caesar cipher</h2>
2+
3+
<pre><code>|= [a=@ b=tape]
4+
^- tape
5+
?: (gth a 25)
6+
$(a (sub a 26))
7+
%+ turn b
8+
|= c=@tD
9+
?: &((gte c 'A') (lte c 'Z'))
10+
=. c (add c a)
11+
?. (gth c 'Z') c
12+
(sub c 26)
13+
?: &((gte c 'a') (lte c 'z'))
14+
=. c (add c a)
15+
?. (gth c 'z') c
16+
(sub c 26)
17+
c</code></pre>

tests/identifier-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ const testOptions = {
3939
word: false,
4040
template: false
4141
},
42+
// Hoon uses _ in its keywords
43+
'hoon': {
44+
word: false,
45+
template: false
46+
},
4247

4348
// LilyPond doesn't tokenize based on words
4449
'lilypond': {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:: Arvo formal interface
2+
::
3+
:: this lifecycle wrapper makes the arvo door (multi-armed core)
4+
:: look like a gate (function or single-armed core), to fit
5+
:: urbit's formal lifecycle function. a practical interpreter
6+
:: can ignore it.
7+
::
8+
|= [now=@da ovo=*]
9+
^- *
10+
~> %slog.[0 leaf+"arvo-event"]
11+
.(+> +:(poke now ovo))
12+
13+
----------------------------------------------------
14+
15+
[
16+
["comment", ":: Arvo formal interface"],
17+
18+
["comment", "::"],
19+
20+
["comment", ":: this lifecycle wrapper makes the arvo door (multi-armed core)"],
21+
22+
["comment", ":: look like a gate (function or single-armed core), to fit"],
23+
24+
["comment", ":: urbit's formal lifecycle function. a practical interpreter"],
25+
26+
["comment", ":: can ignore it."],
27+
28+
["comment", "::"],
29+
30+
["keyword", "|="],
31+
" [",
32+
["function", "now"],
33+
"=",
34+
["class-name", "@"],
35+
["function", "da"],
36+
["function", "ovo"],
37+
"=",
38+
["class-name", "*"],
39+
"]\r\n ",
40+
41+
["keyword", "^-"],
42+
["class-name", "*"],
43+
44+
["keyword", "~>"],
45+
["constant", "%slog"],
46+
".[0 ",
47+
["function", "leaf"],
48+
"+",
49+
["string", "\"arvo-event\""],
50+
"]\r\n .(+> +:(",
51+
["function", "poke"],
52+
["function", "now"],
53+
["function", "ovo"],
54+
"))"
55+
]
56+
57+
----------------------------------------------------
58+
59+
Tests for block comments and the inclusion of tapes and leaves inline in cells.
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
|%
2+
:: # %math
3+
:: unsigned arithmetic
4+
+| %math
5+
++ add
6+
~/ %add
7+
:: unsigned addition
8+
::
9+
:: a: augend
10+
:: b: addend
11+
|= [a=@ b=@]
12+
:: sum
13+
^- @
14+
?: =(0 a) b
15+
$(a (dec a), b +(b))
16+
::
17+
++ dec
18+
19+
----------------------------------------------------
20+
21+
[
22+
["keyword", "|%"],
23+
24+
["comment", ":: # %math"],
25+
26+
["comment", ":: unsigned arithmetic"],
27+
28+
["keyword", "+|"],
29+
["constant", "%math"],
30+
31+
["function", "++ add"],
32+
33+
["keyword", "~/"],
34+
["constant", "%add"],
35+
36+
["comment", ":: unsigned addition"],
37+
38+
["comment", "::"],
39+
40+
["comment", ":: a: augend"],
41+
42+
["comment", ":: b: addend"],
43+
44+
["keyword", "|="],
45+
" [",
46+
["function", "a"],
47+
"=",
48+
["class-name", "@"],
49+
["function", "b"],
50+
"=",
51+
["class-name", "@"],
52+
"]\r\n ",
53+
54+
["comment", ":: sum"],
55+
56+
["keyword", "^-"],
57+
["class-name", "@"],
58+
59+
["keyword", "?:"],
60+
" =(0 ",
61+
["function", "a"],
62+
") ",
63+
["function", "b"],
64+
65+
"\r\n $(",
66+
["function", "a"],
67+
" (",
68+
["function", "dec"],
69+
["function", "a"],
70+
"), ",
71+
["function", "b"],
72+
" +(",
73+
["function", "b"],
74+
"))\r\n",
75+
76+
["comment", "::"],
77+
78+
["function", "++ dec"]
79+
]
80+
81+
----------------------------------------------------
82+
83+
Tests for a sample definition of a core with an arm.
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
|= [a=@ b=tape]
2+
^- tape
3+
?: (gth a 25)
4+
$(a (sub a 26))
5+
%+ turn b
6+
|= c=@tD
7+
?: &((gte c 'A') (lte c 'Z'))
8+
=. c (add c a)
9+
?. (gth c 'Z') c
10+
(sub c 26)
11+
?: &((gte c 'a') (lte c 'z'))
12+
=. c (add c a)
13+
?. (gth c 'z') c
14+
(sub c 26)
15+
c
16+
17+
----------------------------------------------------
18+
19+
[
20+
["keyword", "|="],
21+
" [",
22+
["function", "a"],
23+
"=",
24+
["class-name", "@"],
25+
["function", "b"],
26+
"=",
27+
["function", "tape"],
28+
"]\r\n",
29+
30+
["keyword", "^-"],
31+
["function", "tape"],
32+
33+
["keyword", "?:"],
34+
" (",
35+
["function", "gth"],
36+
["function", "a"],
37+
" 25)\r\n $(",
38+
["function", "a"],
39+
" (",
40+
["function", "sub"],
41+
["function", "a"],
42+
" 26))\r\n",
43+
44+
["keyword", "%+"],
45+
["function", "turn"],
46+
["function", "b"],
47+
48+
["keyword", "|="],
49+
["function", "c"],
50+
"=",
51+
["class-name", "@"],
52+
["function", "t"],
53+
"D\r\n",
54+
55+
["keyword", "?:"],
56+
" &((",
57+
["function", "gte"],
58+
["function", "c"],
59+
["string", "'A'"],
60+
") (",
61+
["function", "lte"],
62+
["function", "c"],
63+
["string", "'Z'"],
64+
"))\r\n ",
65+
66+
["keyword", "=."],
67+
["function", "c"],
68+
" (",
69+
["function", "add"],
70+
["function", "c"],
71+
["function", "a"],
72+
")\r\n ",
73+
74+
["keyword", "?."],
75+
" (",
76+
["function", "gth"],
77+
["function", "c"],
78+
["string", "'Z'"],
79+
") ",
80+
["function", "c"],
81+
82+
"\r\n (",
83+
["function", "sub"],
84+
["function", "c"],
85+
" 26)\r\n",
86+
87+
["keyword", "?:"],
88+
" &((",
89+
["function", "gte"],
90+
["function", "c"],
91+
["string", "'a'"],
92+
") (",
93+
["function", "lte"],
94+
["function", "c"],
95+
["string", "'z'"],
96+
"))\r\n ",
97+
98+
["keyword", "=."],
99+
["function", "c"],
100+
" (",
101+
["function", "add"],
102+
["function", "c"],
103+
["function", "a"],
104+
")\r\n ",
105+
106+
["keyword", "?."],
107+
" (",
108+
["function", "gth"],
109+
["function", "c"],
110+
["string", "'z'"],
111+
") ",
112+
["function", "c"],
113+
114+
"\r\n (",
115+
["function", "sub"],
116+
["function", "c"],
117+
" 26)\r\n",
118+
119+
["function", "c"]
120+
]
121+
122+
----------------------------------------------------
123+
124+
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 commit comments

Comments
 (0)