Skip to content

Commit

Permalink
Merge pull request #805 from Golmote/prism-oz
Browse files Browse the repository at this point in the history
Add support for Oz
  • Loading branch information
Golmote committed Oct 17, 2015
2 parents a36bc4a + b7b1b6a commit 388c53f
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ var components = {
"title": "OCaml",
"owner": "Golmote"
},
"oz": {
"title": "Oz",
"owner": "Golmote"
},
"parigp": {
"title": "PARI/GP",
"owner": "Golmote"
Expand Down
21 changes: 21 additions & 0 deletions components/prism-oz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Prism.languages.oz = {
'comment': /\/\*[\s\S]*?\*\/|%.*/,
'string': /"(?:[^"\\]|\\[\s\S])*"/,
'atom': {
pattern: /'(?:[^'\\]|\\.)*'/,
alias: 'builtin'
},
'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/,
'function': [
/[a-z][A-Za-z\d]*(?=\()/,
{
pattern: /(\{)[A-Z][A-Za-z\d]*/,
lookbehind: true
}
],
'number': /\b(?:0[bx][\da-f]+|\d+\.?\d*(?:e~?\d+)?\b)|&(?:[^\\]|\\(?:\d{3}|.))/i,
'variable': /\b[A-Z][A-Za-z\d]*|`(?:[^`\\]|\\.)+`/,
'attr-name': /\w+(?=:)/,
'operator': /:(?:=|::?)|<[-:=]?|=(?:=|<?:?)|>=?:?|\\=:?|!!?|[|#+\-*\/,~^@]|\b(?:andthen|div|mod|orelse)\b/,
'punctuation': /[\[\](){}.:;?]/
};
1 change: 1 addition & 0 deletions components/prism-oz.min.js

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

107 changes: 107 additions & 0 deletions examples/prism-oz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<h1>Oz</h1>
<p>To use this language, use the class "language-oz".</p>

<h2>Comments</h2>
<pre><code>%
% Foobar

/* Foo
bar */</code></pre>

<h2>Strings</h2>
<pre><code>""
"Foo \"bar\" baz"</code></pre>

<h2>Numbers</h2>
<pre><code>0
42
0154
0xBadFace
0B0101
3.14159
2e8
3.E~7
4.8E12
&0
&a
&\n
&\124</code></pre>

<h2>Functions and procedures</h2>
<pre><code>proc {Max X Y Z}
{Browse Z}
f(M Y)</code></pre>

<h2>Full example</h2>
<pre><code>proc {DisMember X Ys}
dis Ys = X|_ [] Yr in Ys = _|Yr {DisMember X Yr} end
end

class DataBase from BaseObject
attr d
meth init
d := {NewDictionary}
end
meth dic($) @d end
meth tell(I)
case {IsFree I.1} then
raise database(nonground(I)) end
else
Is = {Dictionary.condGet @d I.1 nil} in
{Dictionary.put @d I.1 {Append Is [I]}}
end
end
meth ask(I)
case {IsFree I} orelse {IsFree I.1} then
{DisMember I {Flatten {Dictionary.items @d}}}
else
{DisMember I {Dictionary.condGet @d I.1 nil}}
end
end
meth entries($)
{Dictionary.entries @d}
end
end

declare
proc {Dynamic ?Pred}
Pred = {New DataBase init}
end
proc {Assert P I}
{P tell(I)}
end
proc {Query P I}
{P ask(I)}
end

EdgeP = {Dynamic}
{ForAll
[edge(1 2)
edge(2 1) % Cycle
edge(2 3)
edge(3 4)
edge(2 5)
edge(5 6)
edge(4 6)
edge(6 7)
edge(6 8)
edge(1 5)
edge(5 1) % Cycle
]
proc {$ I} {Assert EdgeP I} end
}</code></pre>

<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
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.
</p>

<h3>Comment-like substrings</h3>
<pre><code>"foo /* bar */ baz"
"foo % bar"</code></pre>

<h3>Atoms containing comment chars</h3>
<pre><code>'foo /* bar */ baz'
'foo % bar'</code></pre>
16 changes: 16 additions & 0 deletions tests/languages/oz/atom_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
''
'fo\'obar'
'foo
bar'

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

[
["atom", "''"],
["atom", "'fo\\'obar'"],
["atom", "'foo\r\nbar'"]
]

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

Checks for atoms.
14 changes: 14 additions & 0 deletions tests/languages/oz/attr-name_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
menubutton(text:'Test' underline:0)

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

[
["function", "menubutton"], ["punctuation", "("],
["attr-name", "text"], ["punctuation", ":"], ["atom", "'Test'"],
["attr-name", "underline"], ["punctuation", ":"], ["number", "0"],
["punctuation", ")"]
]

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

Checks for parameter names.
18 changes: 18 additions & 0 deletions tests/languages/oz/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%
% Foobar
/**/
/* Foo
bar */

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

[
["comment", "%"],
["comment", "% Foobar"],
["comment", "/**/"],
["comment", "/* Foo\r\nbar */"]
]

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

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/oz/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
foobar()
{Foobar}

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

[
["function", "foobar"], ["punctuation", "("], ["punctuation", ")"],
["punctuation", "{"], ["function", "Foobar"], ["punctuation", "}"]
]

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

Checks for functions and procedures.
103 changes: 103 additions & 0 deletions tests/languages/oz/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
$
_
[]
at
attr
case
catch
choice
class
cond
declare
define
dis
else
elsecase
elseif
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

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

[
["keyword", "$"],
["keyword", "_"],
["keyword", "[]"],
["keyword", "at"],
["keyword", "attr"],
["keyword", "case"],
["keyword", "catch"],
["keyword", "choice"],
["keyword", "class"],
["keyword", "cond"],
["keyword", "declare"],
["keyword", "define"],
["keyword", "dis"],
["keyword", "else"],
["keyword", "elsecase"],
["keyword", "elseif"],
["keyword", "end"],
["keyword", "export"],
["keyword", "fail"],
["keyword", "false"],
["keyword", "feat"],
["keyword", "finally"],
["keyword", "from"],
["keyword", "fun"],
["keyword", "functor"],
["keyword", "if"],
["keyword", "import"],
["keyword", "in"],
["keyword", "local"],
["keyword", "lock"],
["keyword", "meth"],
["keyword", "nil"],
["keyword", "not"],
["keyword", "of"],
["keyword", "or"],
["keyword", "prepare"],
["keyword", "proc"],
["keyword", "prop"],
["keyword", "raise"],
["keyword", "require"],
["keyword", "self"],
["keyword", "skip"],
["keyword", "then"],
["keyword", "thread"],
["keyword", "true"],
["keyword", "try"],
["keyword", "unit"]
]

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

Checks for keywords.
35 changes: 35 additions & 0 deletions tests/languages/oz/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
0
42
0154
0xBadFace
0B0101
3.14159
2e8
3.E~7
4.8E12
&0
&a
&\n
&\124

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

[
["number", "0"],
["number", "42"],
["number", "0154"],
["number", "0xBadFace"],
["number", "0B0101"],
["number", "3.14159"],
["number", "2e8"],
["number", "3.E~7"],
["number", "4.8E12"],
["number", "&0"],
["number", "&a"],
["number", "&\\n"],
["number", "&\\124"]
]

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

Checks for numbers.
35 changes: 35 additions & 0 deletions tests/languages/oz/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
:= :: :::
< <- <: <=
= == =: =< =<:
> >= >: >=:
\= \=:
! !!
| # + -
* / , ~
^ @
andthen
div
mod
orelse

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

[
["operator", ":="], ["operator", "::"], ["operator", ":::"],
["operator", "<"], ["operator", "<-"], ["operator", "<:"], ["operator", "<="],
["operator", "="], ["operator", "=="], ["operator", "=:"], ["operator", "=<"], ["operator", "=<:"],
["operator", ">"], ["operator", ">="], ["operator", ">:"], ["operator", ">=:"],
["operator", "\\="], ["operator", "\\=:"],
["operator", "!"], ["operator", "!!"],
["operator", "|"], ["operator", "#"], ["operator", "+"], ["operator", "-"],
["operator", "*"], ["operator", "/"], ["operator", ","], ["operator", "~"],
["operator", "^"], ["operator", "@"],
["operator", "andthen"],
["operator", "div"],
["operator", "mod"],
["operator", "orelse"]
]

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

Checks for operators.
Loading

0 comments on commit 388c53f

Please sign in to comment.