-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from Golmote/prism-ocaml
Add support for OCaml
- Loading branch information
Showing
14 changed files
with
341 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Prism.languages.ocaml = { | ||
'comment': /\(\*[\s\S]*?\*\)/, | ||
'string': [ | ||
/"(?:\\.|[^\\\r\n"])*"/, | ||
/(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i | ||
], | ||
'number': /\b-?(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*\.?[\d_]*(?:e[+-]?[\d_]+)?)/i, | ||
'type': { | ||
pattern: /\B['`][a-z\d_]*/i, | ||
alias: 'variable' | ||
}, | ||
'directive': { | ||
pattern: /\B#[a-z\d_]+/i, | ||
alias: 'function' | ||
}, | ||
'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|object|of|open|prefix|private|rec|then|sig|struct|to|try|type|val|value|virtual|where|while|with)\b/, | ||
'boolean': /\b(?:false|true)\b/, | ||
// Custom operators are allowed | ||
'operator': /:=|[=<>@^|&+\-*\/$%!?~][!$%&\*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lxor|lsl|lsr|mod|nor|or)\b/, | ||
'punctuation': /[(){}\[\]|_.,:;]/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<h1>OCaml</h1> | ||
<p>To use this language, use the class "language-ocaml".</p> | ||
|
||
<h2>Comments</h2> | ||
<pre><code>(* Simple comment *) | ||
(* Multi-line | ||
comment *)</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>42 | ||
3.14159 | ||
42. | ||
2.4E+2 | ||
10_452_102 | ||
0xf4 0xff_10_41 | ||
0o427 | ||
0b1100_1111_0000</code></pre> | ||
|
||
<h2>Strings and characters</h2> | ||
<pre><code>"Simple string." | ||
"String with \"quotes\" in it." | ||
'c' `c` | ||
'\'' `\`` | ||
'\123' `\123` | ||
'\xf4'</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code>module Make_interval(Endpoint : Comparable) = struct | ||
|
||
type t = | Interval of Endpoint.t * Endpoint.t | ||
| Empty | ||
|
||
(** [create low high] creates a new interval from [low] to | ||
[high]. If [low > high], then the interval is empty *) | ||
let create low high = | ||
if Endpoint.compare low high > 0 then Empty | ||
else Interval (low,high) | ||
|
||
(** Returns true iff the interval is empty *) | ||
let is_empty = function | ||
| Empty -> true | ||
| Interval _ -> false | ||
|
||
(** [contains t x] returns true iff [x] is contained in the | ||
interval [t] *) | ||
let contains t x = | ||
match t with | ||
| Empty -> false | ||
| Interval (l,h) -> | ||
Endpoint.compare x l >= 0 && Endpoint.compare x h <= 0 | ||
|
||
(** [intersect t1 t2] returns the intersection of the two input | ||
intervals *) | ||
let intersect t1 t2 = | ||
let min x y = if Endpoint.compare x y <= 0 then x else y in | ||
let max x y = if Endpoint.compare x y >= 0 then x else y in | ||
match t1,t2 with | ||
| Empty, _ | _, Empty -> Empty | ||
| Interval (l1,h1), Interval (l2,h2) -> | ||
create (max l1 l2) (min h1 h2) | ||
|
||
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"</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
false | ||
true | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "false"], | ||
["boolean", "true"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(**) | ||
(* foo | ||
bar *) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "(**)"], | ||
["comment", "(* foo\r\nbar *)"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#quit | ||
#load | ||
#load_rec | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["directive", "#quit"], | ||
["directive", "#load"], | ||
["directive", "#load_rec"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for directives. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
as | ||
assert | ||
begin | ||
class | ||
constraint | ||
do | ||
done | ||
downto | ||
else | ||
end | ||
exception | ||
external | ||
for | ||
fun | ||
function | ||
functor | ||
if | ||
in | ||
include | ||
inherit | ||
initializer | ||
lazy | ||
let | ||
match | ||
method | ||
module | ||
mutable | ||
new | ||
object | ||
of | ||
open | ||
prefix | ||
private | ||
rec | ||
then | ||
sig | ||
struct | ||
to | ||
try | ||
type | ||
val | ||
value | ||
virtual | ||
where | ||
while | ||
with | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "as"], | ||
["keyword", "assert"], | ||
["keyword", "begin"], | ||
["keyword", "class"], | ||
["keyword", "constraint"], | ||
["keyword", "do"], | ||
["keyword", "done"], | ||
["keyword", "downto"], | ||
["keyword", "else"], | ||
["keyword", "end"], | ||
["keyword", "exception"], | ||
["keyword", "external"], | ||
["keyword", "for"], | ||
["keyword", "fun"], | ||
["keyword", "function"], | ||
["keyword", "functor"], | ||
["keyword", "if"], | ||
["keyword", "in"], | ||
["keyword", "include"], | ||
["keyword", "inherit"], | ||
["keyword", "initializer"], | ||
["keyword", "lazy"], | ||
["keyword", "let"], | ||
["keyword", "match"], | ||
["keyword", "method"], | ||
["keyword", "module"], | ||
["keyword", "mutable"], | ||
["keyword", "new"], | ||
["keyword", "object"], | ||
["keyword", "of"], | ||
["keyword", "open"], | ||
["keyword", "prefix"], | ||
["keyword", "private"], | ||
["keyword", "rec"], | ||
["keyword", "then"], | ||
["keyword", "sig"], | ||
["keyword", "struct"], | ||
["keyword", "to"], | ||
["keyword", "try"], | ||
["keyword", "type"], | ||
["keyword", "val"], | ||
["keyword", "value"], | ||
["keyword", "virtual"], | ||
["keyword", "where"], | ||
["keyword", "while"], | ||
["keyword", "with"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for keywords. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
0xBad_Face | ||
0o754_672 | ||
0b1010_1111 | ||
42_000 | ||
3.14_15_9 | ||
3.2e8 | ||
6.1E-7 | ||
0.4e+12_415 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "0xBad_Face"], | ||
["number", "0o754_672"], | ||
["number", "0b1010_1111"], | ||
["number", "42_000"], | ||
["number", "3.14_15_9"], | ||
["number", "3.2e8"], | ||
["number", "6.1E-7"], | ||
["number", "0.4e+12_415"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for numbers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
and asr land | ||
lor lxor lsl lsr | ||
mod nor or | ||
|
||
:= | ||
= < > @ | ||
^ | & ~ | ||
+ - * / | ||
$ % ! ? | ||
|
||
~=~ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "and"], ["operator", "asr"], ["operator", "land"], | ||
["operator", "lor"], ["operator", "lxor"], ["operator", "lsl"], ["operator", "lsr"], | ||
["operator", "mod"], ["operator", "nor"], ["operator", "or"], | ||
|
||
["operator", ":="], | ||
["operator", "="], ["operator", "<"], ["operator", ">"], ["operator", "@"], | ||
["operator", "^"], ["operator", "|"], ["operator", "&"], ["operator", "~"], | ||
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "/"], | ||
["operator", "$"], ["operator", "%"], ["operator", "!"], ["operator", "?"], | ||
|
||
["operator", "~=~"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"" | ||
"Fo\"obar" | ||
'\'' | ||
'\123' | ||
'\xf4' | ||
`\`` | ||
`\123` | ||
`\xf4` | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", "\"\""], | ||
["string", "\"Fo\\\"obar\""], | ||
["string", "'\\''"], | ||
["string", "'\\123'"], | ||
["string", "'\\xf4'"], | ||
["string", "`\\``"], | ||
["string", "`\\123`"], | ||
["string", "`\\xf4`"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'Foo | ||
'bar_42 | ||
`Foo | ||
`bar_42 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["type", "'Foo"], | ||
["type", "'bar_42"], | ||
["type", "`Foo"], | ||
["type", "`bar_42"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for types. |