Permalink
Browse files

Add support for Reason. Fix #1046

  • Loading branch information...
1 parent 07b81ac commit 3cae6ce887c9f70c9421188cd310da1afa8018d3 @Golmote Golmote committed Nov 19, 2016
View
@@ -453,6 +453,11 @@ var components = {
"require": ["markup", "javascript"],
"owner": "vkbansal"
},
+ "reason": {
+ "title": "Reason",
+ "require": "clike",
+ "owner": "Golmote"
+ },
"rest": {
"title": "reST (reStructuredText)",
"owner": "Golmote"
@@ -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;
@@ -0,0 +1 @@
+Prism.languages.reason=Prism.languages.extend("clike",{comment:{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},string:{pattern:/"(\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,greedy:!0},"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:{pattern:/\b[A-Z]\w*\b(?!\s*\.)/,alias:"variable"},label:{pattern:/\b[a-z]\w*(?=::)/,alias:"symbol"}}),delete Prism.languages.reason.function;
@@ -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>
@@ -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 = {};
@@ -1 +1 @@
-!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={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"},c={},a="none",s=Prism.plugins.autoloader={languages_path:"components/",use_minified:!0},n=function(e,c,a){var s=document.createElement("script");s.src=e,s.async=!0,s.onload=function(){document.body.removeChild(s),c&&c()},s.onerror=function(){document.body.removeChild(s),a&&a()},document.body.appendChild(s)},r=function(e){return s.languages_path+"prism-"+e+(s.use_minified?".min":"")+".js"},i=function(e,a){var s=c[e];s||(s=c[e]={});var n=a.getAttribute("data-dependencies");!n&&a.parentNode&&"pre"===a.parentNode.tagName.toLowerCase()&&(n=a.parentNode.getAttribute("data-dependencies")),n=n?n.split(/\s*,\s*/g):[],t(n,function(){l(e,function(){Prism.highlightElement(a)})})},t=function(e,c,a){"string"==typeof e&&(e=[e]);var s=0,n=e.length,r=function(){n>s?l(e[s],function(){s++,r()},function(){a&&a(e[s])}):s===n&&c&&c(e)};r()},l=function(a,s,i){var l=function(){var e=!1;a.indexOf("!")>=0&&(e=!0,a=a.replace("!",""));var t=c[a];if(t||(t=c[a]={}),s&&(t.success_callbacks||(t.success_callbacks=[]),t.success_callbacks.push(s)),i&&(t.error_callbacks||(t.error_callbacks=[]),t.error_callbacks.push(i)),!e&&Prism.languages[a])o(a);else if(!e&&t.error)u(a);else if(e||!t.loading){t.loading=!0;var l=r(a);n(l,function(){t.loading=!1,o(a)},function(){t.loading=!1,t.error=!0,u(a)})}},p=e[a];p&&p.length?t(p,l):l()},o=function(e){c[e]&&c[e].success_callbacks&&c[e].success_callbacks.length&&c[e].success_callbacks.forEach(function(c){c(e)})},u=function(e){c[e]&&c[e].error_callbacks&&c[e].error_callbacks.length&&c[e].error_callbacks.forEach(function(c){c(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==a&&i(e.language,e.element)})}}();
+!function(){if("undefined"!=typeof self&&self.Prism&&self.document&&document.createElement){var e={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"},c={},a="none",s=Prism.plugins.autoloader={languages_path:"components/",use_minified:!0},n=function(e,c,a){var s=document.createElement("script");s.src=e,s.async=!0,s.onload=function(){document.body.removeChild(s),c&&c()},s.onerror=function(){document.body.removeChild(s),a&&a()},document.body.appendChild(s)},r=function(e){return s.languages_path+"prism-"+e+(s.use_minified?".min":"")+".js"},i=function(e,a){var s=c[e];s||(s=c[e]={});var n=a.getAttribute("data-dependencies");!n&&a.parentNode&&"pre"===a.parentNode.tagName.toLowerCase()&&(n=a.parentNode.getAttribute("data-dependencies")),n=n?n.split(/\s*,\s*/g):[],l(n,function(){t(e,function(){Prism.highlightElement(a)})})},l=function(e,c,a){"string"==typeof e&&(e=[e]);var s=0,n=e.length,r=function(){n>s?t(e[s],function(){s++,r()},function(){a&&a(e[s])}):s===n&&c&&c(e)};r()},t=function(a,s,i){var t=function(){var e=!1;a.indexOf("!")>=0&&(e=!0,a=a.replace("!",""));var l=c[a];if(l||(l=c[a]={}),s&&(l.success_callbacks||(l.success_callbacks=[]),l.success_callbacks.push(s)),i&&(l.error_callbacks||(l.error_callbacks=[]),l.error_callbacks.push(i)),!e&&Prism.languages[a])o(a);else if(!e&&l.error)u(a);else if(e||!l.loading){l.loading=!0;var t=r(a);n(t,function(){l.loading=!1,o(a)},function(){l.loading=!1,l.error=!0,u(a)})}},p=e[a];p&&p.length?l(p,t):t()},o=function(e){c[e]&&c[e].success_callbacks&&c[e].success_callbacks.length&&c[e].success_callbacks.forEach(function(c){c(e)})},u=function(e){c[e]&&c[e].error_callbacks&&c[e].error_callbacks.length&&c[e].error_callbacks.forEach(function(c){c(e)})};Prism.hooks.add("complete",function(e){e.element&&e.language&&!e.grammar&&e.language!==a&&i(e.language,e.element)})}}();
@@ -0,0 +1,19 @@
+'a'
+'\''
+'\\'
+'\xff'
+'\o214'
+
+----------------------------------------------------
+
+[
+ ["character", "'a'"],
+ ["character", "'\\''"],
+ ["character", "'\\\\'"],
+ ["character", "'\\xff'"],
+ ["character", "'\\o214'"]
+]
+
+----------------------------------------------------
+
+Checks for characters.
@@ -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.
@@ -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.
@@ -0,0 +1,15 @@
+Yes
+Foo_bar
+A
+
+----------------------------------------------------
+
+[
+ ["constructor", "Yes"],
+ ["constructor", "Foo_bar"],
+ ["constructor", "A"]
+]
+
+----------------------------------------------------
+
+Checks for constructors.
@@ -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.
@@ -0,0 +1,13 @@
+foo::bar
+a::baz
+
+----------------------------------------------------
+
+[
+ ["label", "foo"], ["operator", "::"], "bar\r\n",
+ ["label", "a"], ["operator", "::"], "baz"
+]
+
+----------------------------------------------------
+
+Checks for labels.
@@ -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.
@@ -0,0 +1,13 @@
+""
+"foo\"bar"
+
+----------------------------------------------------
+
+[
+ ["string", "\"\""],
+ ["string", "\"foo\\\"bar\""]
+]
+
+----------------------------------------------------
+
+Checks for strings.

0 comments on commit 3cae6ce

Please sign in to comment.