Skip to content

Commit 388c53f

Browse files
committed
Merge pull request #805 from Golmote/prism-oz
Add support for Oz
2 parents a36bc4a + b7b1b6a commit 388c53f

13 files changed

+398
-0
lines changed

components.js

+4
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ var components = {
333333
"title": "OCaml",
334334
"owner": "Golmote"
335335
},
336+
"oz": {
337+
"title": "Oz",
338+
"owner": "Golmote"
339+
},
336340
"parigp": {
337341
"title": "PARI/GP",
338342
"owner": "Golmote"

components/prism-oz.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Prism.languages.oz = {
2+
'comment': /\/\*[\s\S]*?\*\/|%.*/,
3+
'string': /"(?:[^"\\]|\\[\s\S])*"/,
4+
'atom': {
5+
pattern: /'(?:[^'\\]|\\.)*'/,
6+
alias: 'builtin'
7+
},
8+
'keyword': /[$_]|\[\]|\b(?:at|attr|case|catch|choice|class|cond|declare|define|dis|else(?:case|if)?|end|export|fail|false|feat|finally|from|fun|functor|if|import|in|local|lock|meth|nil|not|of|or|prepare|proc|prop|raise|require|self|skip|then|thread|true|try|unit)\b/,
9+
'function': [
10+
/[a-z][A-Za-z\d]*(?=\()/,
11+
{
12+
pattern: /(\{)[A-Z][A-Za-z\d]*/,
13+
lookbehind: true
14+
}
15+
],
16+
'number': /\b(?:0[bx][\da-f]+|\d+\.?\d*(?:e~?\d+)?\b)|&(?:[^\\]|\\(?:\d{3}|.))/i,
17+
'variable': /\b[A-Z][A-Za-z\d]*|`(?:[^`\\]|\\.)+`/,
18+
'attr-name': /\w+(?=:)/,
19+
'operator': /:(?:=|::?)|<[-:=]?|=(?:=|<?:?)|>=?:?|\\=:?|!!?|[|#+\-*\/,~^@]|\b(?:andthen|div|mod|orelse)\b/,
20+
'punctuation': /[\[\](){}.:;?]/
21+
};

components/prism-oz.min.js

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

examples/prism-oz.html

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<h1>Oz</h1>
2+
<p>To use this language, use the class "language-oz".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code>%
6+
% Foobar
7+
8+
/* Foo
9+
bar */</code></pre>
10+
11+
<h2>Strings</h2>
12+
<pre><code>""
13+
"Foo \"bar\" baz"</code></pre>
14+
15+
<h2>Numbers</h2>
16+
<pre><code>0
17+
42
18+
0154
19+
0xBadFace
20+
0B0101
21+
3.14159
22+
2e8
23+
3.E~7
24+
4.8E12
25+
&0
26+
&a
27+
&\n
28+
&\124</code></pre>
29+
30+
<h2>Functions and procedures</h2>
31+
<pre><code>proc {Max X Y Z}
32+
{Browse Z}
33+
f(M Y)</code></pre>
34+
35+
<h2>Full example</h2>
36+
<pre><code>proc {DisMember X Ys}
37+
dis Ys = X|_ [] Yr in Ys = _|Yr {DisMember X Yr} end
38+
end
39+
40+
class DataBase from BaseObject
41+
attr d
42+
meth init
43+
d := {NewDictionary}
44+
end
45+
meth dic($) @d end
46+
meth tell(I)
47+
case {IsFree I.1} then
48+
raise database(nonground(I)) end
49+
else
50+
Is = {Dictionary.condGet @d I.1 nil} in
51+
{Dictionary.put @d I.1 {Append Is [I]}}
52+
end
53+
end
54+
meth ask(I)
55+
case {IsFree I} orelse {IsFree I.1} then
56+
{DisMember I {Flatten {Dictionary.items @d}}}
57+
else
58+
{DisMember I {Dictionary.condGet @d I.1 nil}}
59+
end
60+
end
61+
meth entries($)
62+
{Dictionary.entries @d}
63+
end
64+
end
65+
66+
declare
67+
proc {Dynamic ?Pred}
68+
Pred = {New DataBase init}
69+
end
70+
proc {Assert P I}
71+
{P tell(I)}
72+
end
73+
proc {Query P I}
74+
{P ask(I)}
75+
end
76+
77+
EdgeP = {Dynamic}
78+
{ForAll
79+
[edge(1 2)
80+
edge(2 1) % Cycle
81+
edge(2 3)
82+
edge(3 4)
83+
edge(2 5)
84+
edge(5 6)
85+
edge(4 6)
86+
edge(6 7)
87+
edge(6 8)
88+
edge(1 5)
89+
edge(5 1) % Cycle
90+
]
91+
proc {$ I} {Assert EdgeP I} end
92+
}</code></pre>
93+
94+
<h2>Known failures</h2>
95+
<p>There are certain edge cases where Prism will fail.
96+
There are always such cases in every regex-based syntax highlighter.
97+
However, Prism dares to be open and honest about them.
98+
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
99+
</p>
100+
101+
<h3>Comment-like substrings</h3>
102+
<pre><code>"foo /* bar */ baz"
103+
"foo % bar"</code></pre>
104+
105+
<h3>Atoms containing comment chars</h3>
106+
<pre><code>'foo /* bar */ baz'
107+
'foo % bar'</code></pre>

tests/languages/oz/atom_feature.test

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
''
2+
'fo\'obar'
3+
'foo
4+
bar'
5+
6+
----------------------------------------------------
7+
8+
[
9+
["atom", "''"],
10+
["atom", "'fo\\'obar'"],
11+
["atom", "'foo\r\nbar'"]
12+
]
13+
14+
----------------------------------------------------
15+
16+
Checks for atoms.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
menubutton(text:'Test' underline:0)
2+
3+
----------------------------------------------------
4+
5+
[
6+
["function", "menubutton"], ["punctuation", "("],
7+
["attr-name", "text"], ["punctuation", ":"], ["atom", "'Test'"],
8+
["attr-name", "underline"], ["punctuation", ":"], ["number", "0"],
9+
["punctuation", ")"]
10+
]
11+
12+
----------------------------------------------------
13+
14+
Checks for parameter names.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%
2+
% Foobar
3+
/**/
4+
/* Foo
5+
bar */
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "%"],
11+
["comment", "% Foobar"],
12+
["comment", "/**/"],
13+
["comment", "/* Foo\r\nbar */"]
14+
]
15+
16+
----------------------------------------------------
17+
18+
Checks for comments.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
foobar()
2+
{Foobar}
3+
4+
----------------------------------------------------
5+
6+
[
7+
["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
8+
["punctuation", "{"], ["function", "Foobar"], ["punctuation", "}"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for functions and procedures.
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
$
2+
_
3+
[]
4+
at
5+
attr
6+
case
7+
catch
8+
choice
9+
class
10+
cond
11+
declare
12+
define
13+
dis
14+
else
15+
elsecase
16+
elseif
17+
end
18+
export
19+
fail
20+
false
21+
feat
22+
finally
23+
from
24+
fun
25+
functor
26+
if
27+
import
28+
in
29+
local
30+
lock
31+
meth
32+
nil
33+
not
34+
of
35+
or
36+
prepare
37+
proc
38+
prop
39+
raise
40+
require
41+
self
42+
skip
43+
then
44+
thread
45+
true
46+
try
47+
unit
48+
49+
----------------------------------------------------
50+
51+
[
52+
["keyword", "$"],
53+
["keyword", "_"],
54+
["keyword", "[]"],
55+
["keyword", "at"],
56+
["keyword", "attr"],
57+
["keyword", "case"],
58+
["keyword", "catch"],
59+
["keyword", "choice"],
60+
["keyword", "class"],
61+
["keyword", "cond"],
62+
["keyword", "declare"],
63+
["keyword", "define"],
64+
["keyword", "dis"],
65+
["keyword", "else"],
66+
["keyword", "elsecase"],
67+
["keyword", "elseif"],
68+
["keyword", "end"],
69+
["keyword", "export"],
70+
["keyword", "fail"],
71+
["keyword", "false"],
72+
["keyword", "feat"],
73+
["keyword", "finally"],
74+
["keyword", "from"],
75+
["keyword", "fun"],
76+
["keyword", "functor"],
77+
["keyword", "if"],
78+
["keyword", "import"],
79+
["keyword", "in"],
80+
["keyword", "local"],
81+
["keyword", "lock"],
82+
["keyword", "meth"],
83+
["keyword", "nil"],
84+
["keyword", "not"],
85+
["keyword", "of"],
86+
["keyword", "or"],
87+
["keyword", "prepare"],
88+
["keyword", "proc"],
89+
["keyword", "prop"],
90+
["keyword", "raise"],
91+
["keyword", "require"],
92+
["keyword", "self"],
93+
["keyword", "skip"],
94+
["keyword", "then"],
95+
["keyword", "thread"],
96+
["keyword", "true"],
97+
["keyword", "try"],
98+
["keyword", "unit"]
99+
]
100+
101+
----------------------------------------------------
102+
103+
Checks for keywords.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
0
2+
42
3+
0154
4+
0xBadFace
5+
0B0101
6+
3.14159
7+
2e8
8+
3.E~7
9+
4.8E12
10+
&0
11+
&a
12+
&\n
13+
&\124
14+
15+
----------------------------------------------------
16+
17+
[
18+
["number", "0"],
19+
["number", "42"],
20+
["number", "0154"],
21+
["number", "0xBadFace"],
22+
["number", "0B0101"],
23+
["number", "3.14159"],
24+
["number", "2e8"],
25+
["number", "3.E~7"],
26+
["number", "4.8E12"],
27+
["number", "&0"],
28+
["number", "&a"],
29+
["number", "&\\n"],
30+
["number", "&\\124"]
31+
]
32+
33+
----------------------------------------------------
34+
35+
Checks for numbers.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
:= :: :::
2+
< <- <: <=
3+
= == =: =< =<:
4+
> >= >: >=:
5+
\= \=:
6+
! !!
7+
| # + -
8+
* / , ~
9+
^ @
10+
andthen
11+
div
12+
mod
13+
orelse
14+
15+
----------------------------------------------------
16+
17+
[
18+
["operator", ":="], ["operator", "::"], ["operator", ":::"],
19+
["operator", "<"], ["operator", "<-"], ["operator", "<:"], ["operator", "<="],
20+
["operator", "="], ["operator", "=="], ["operator", "=:"], ["operator", "=<"], ["operator", "=<:"],
21+
["operator", ">"], ["operator", ">="], ["operator", ">:"], ["operator", ">=:"],
22+
["operator", "\\="], ["operator", "\\=:"],
23+
["operator", "!"], ["operator", "!!"],
24+
["operator", "|"], ["operator", "#"], ["operator", "+"], ["operator", "-"],
25+
["operator", "*"], ["operator", "/"], ["operator", ","], ["operator", "~"],
26+
["operator", "^"], ["operator", "@"],
27+
["operator", "andthen"],
28+
["operator", "div"],
29+
["operator", "mod"],
30+
["operator", "orelse"]
31+
]
32+
33+
----------------------------------------------------
34+
35+
Checks for operators.

0 commit comments

Comments
 (0)