Skip to content

Commit

Permalink
Add support for Reason. Fix #1046
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Nov 19, 2016
1 parent 07b81ac commit 3cae6ce
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 2 deletions.
5 changes: 5 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ var components = {
"require": ["markup", "javascript"],
"owner": "vkbansal"
},
"reason": {
"title": "Reason",
"require": "clike",
"owner": "Golmote"
},
"rest": {
"title": "reST (reStructuredText)",
"owner": "Golmote"
Expand Down
32 changes: 32 additions & 0 deletions components/prism-reason.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Prism.languages.reason = Prism.languages.extend('clike', {
'comment': {
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
lookbehind: true
},
'string': {
pattern: /"(\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,
greedy: true
},
// 'class-name' must be matched *after* 'constructor' defined below
'class-name': /\b[A-Z]\w*/,
'keyword': /\b(?:and|as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|method|module|mutable|new|nonrec|object|of|open|or|private|rec|sig|struct|switch|then|to|try|type|val|virtual|when|while|with)\b/,
'operator': /\.{3}|:[:=]|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:mod|land|lor|lxor|lsl|lsr|asr)\b/
});
Prism.languages.insertBefore('reason', 'class-name', {
'character': {
pattern: /'(?:\\x[\da-f]{2}|\\o[0-3][0-7][0-7]|\\\d{3}|\\.|[^'])'/,
alias: 'string'
},
'constructor': {
// Negative look-ahead prevents from matching things like String.capitalize
pattern: /\b[A-Z]\w*\b(?!\s*\.)/,
alias: 'variable'
},
'label': {
pattern: /\b[a-z]\w*(?=::)/,
alias: 'symbol'
}
});

// We can't match functions property, so let's not even try.
delete Prism.languages.reason.function;
1 change: 1 addition & 0 deletions components/prism-reason.min.js

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

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

<h2>Comments</h2>
<pre><code>/* This is a comment */</code></pre>

<h2>Strings and characters</h2>
<pre><code>"This is a \"string\""
'a'
'\\'
'\o123'
'\x4a'</code></pre>

<h2>Constructors</h2>
<pre><code>type response =
| Yes
| No
| PrettyMuch;</code></pre>

<h2>Example</h2>
<pre><code>type car = {maker: string, model: string};
type carList =
| List car carList
| NoMore;

let chevy = {maker: "Chevy", model: "Suburban"};
let toyota = {maker: "Toyota", model: "Tacoma"};
let myCarList = List chevy (List toyota NoMore);

let hasExactlyTwoCars = fun lst =>
switch lst {
| NoMore => false /* 0 */
| List p NoMore => false /* 1 */
| List p (List p2 NoMore) => true /* 2 */
| List p (List p2 (List p3 theRest)) => false /* 3+ */
};

let justTwo = hasExactlyTwoCars myCarList; /* true! */</code></pre>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;

var lang_data = {};

Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

19 changes: 19 additions & 0 deletions tests/languages/reason/character_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'a'
'\''
'\\'
'\xff'
'\o214'

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

[
["character", "'a'"],
["character", "'\\''"],
["character", "'\\\\'"],
["character", "'\\xff'"],
["character", "'\\o214'"]
]

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

Checks for characters.
15 changes: 15 additions & 0 deletions tests/languages/reason/class-name_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
String.foo
Foo_bar.baz
A.bar

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

[
["class-name", "String"], ["punctuation", "."], "foo\r\n",
["class-name", "Foo_bar"], ["punctuation", "."], "baz\r\n",
["class-name", "A"], ["punctuation", "."], "bar"
]

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

Checks for class names.
20 changes: 20 additions & 0 deletions tests/languages/reason/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**/
/* Single line comment */
/* Multiline
comment */
/**
Doc comment
*/

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

[
["comment", "/**/"],
["comment", "/* Single line comment */"],
["comment", "/* Multiline\r\ncomment */"],
["comment", "/**\r\nDoc comment\r\n*/"]
]

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

Checks for comments.
15 changes: 15 additions & 0 deletions tests/languages/reason/constructor_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Yes
Foo_bar
A

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

[
["constructor", "Yes"],
["constructor", "Foo_bar"],
["constructor", "A"]
]

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

Checks for constructors.
103 changes: 103 additions & 0 deletions tests/languages/reason/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
and
as
assert
begin
class
constraint
do
done
downto
else
end
exception
external
for
fun
function
functor
if
in
include
inherit
initializer
lazy
let
method
module
mutable
new
nonrec
object
of
open
or
private
rec
sig
struct
switch
then
to
try
type
val
virtual
when
while
with

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

[
["keyword", "and"],
["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", "method"],
["keyword", "module"],
["keyword", "mutable"],
["keyword", "new"],
["keyword", "nonrec"],
["keyword", "object"],
["keyword", "of"],
["keyword", "open"],
["keyword", "or"],
["keyword", "private"],
["keyword", "rec"],
["keyword", "sig"],
["keyword", "struct"],
["keyword", "switch"],
["keyword", "then"],
["keyword", "to"],
["keyword", "try"],
["keyword", "type"],
["keyword", "val"],
["keyword", "virtual"],
["keyword", "when"],
["keyword", "while"],
["keyword", "with"]
]

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

Checks for keywords.
13 changes: 13 additions & 0 deletions tests/languages/reason/label_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
foo::bar
a::baz

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

[
["label", "foo"], ["operator", "::"], "bar\r\n",
["label", "a"], ["operator", "::"], "baz"
]

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

Checks for labels.
29 changes: 29 additions & 0 deletions tests/languages/reason/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
...
:: :=
= == ===
< <= > >=
| ^ ? '
# ! ~ `
+ - * /
+. -. *. /.
mod land lor lxor
lsl lsr asr

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

[
["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", "mod"], ["operator", "land"], ["operator", "lor"], ["operator", "lxor"],
["operator", "lsl"], ["operator", "lsr"], ["operator", "asr"]
]

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

Checks for operators.
13 changes: 13 additions & 0 deletions tests/languages/reason/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
""
"foo\"bar"

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

[
["string", "\"\""],
["string", "\"foo\\\"bar\""]
]

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

Checks for strings.

0 comments on commit 3cae6ce

Please sign in to comment.