summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/mllike
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/mode/mllike
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/mode/mllike')
-rwxr-xr-xpublic/vendor/codemirror/mode/mllike/index.html179
-rwxr-xr-xpublic/vendor/codemirror/mode/mllike/mllike.js205
2 files changed, 384 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/mllike/index.html b/public/vendor/codemirror/mode/mllike/index.html
new file mode 100755
index 00000000..5923af8f
--- /dev/null
+++ b/public/vendor/codemirror/mode/mllike/index.html
@@ -0,0 +1,179 @@
+<!doctype html>
+
+<title>CodeMirror: ML-like mode</title>
+<meta charset="utf-8"/>
+<link rel=stylesheet href="../../doc/docs.css">
+
+<link rel=stylesheet href=../../lib/codemirror.css>
+<script src=../../lib/codemirror.js></script>
+<script src=../../addon/edit/matchbrackets.js></script>
+<script src=mllike.js></script>
+<style type=text/css>
+ .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
+</style>
+<div id=nav>
+ <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
+
+ <ul>
+ <li><a href="../../index.html">Home</a>
+ <li><a href="../../doc/manual.html">Manual</a>
+ <li><a href="https://github.com/codemirror/codemirror">Code</a>
+ </ul>
+ <ul>
+ <li><a href="../index.html">Language modes</a>
+ <li><a class=active href="#">ML-like</a>
+ </ul>
+</div>
+
+<article>
+<h2>OCaml mode</h2>
+
+
+<textarea id="ocamlCode">
+(* Summing a list of integers *)
+let rec sum xs =
+ match xs with
+ | [] -&gt; 0
+ | x :: xs' -&gt; x + sum xs'
+
+(* Quicksort *)
+let rec qsort = function
+ | [] -&gt; []
+ | pivot :: rest -&gt;
+ let is_less x = x &lt; pivot in
+ let left, right = List.partition is_less rest in
+ qsort left @ [pivot] @ qsort right
+
+(* Fibonacci Sequence *)
+let rec fib_aux n a b =
+ match n with
+ | 0 -&gt; a
+ | _ -&gt; fib_aux (n - 1) (a + b) a
+let fib n = fib_aux n 0 1
+
+(* Birthday paradox *)
+let year_size = 365.
+
+let rec birthday_paradox prob people =
+ let prob' = (year_size -. float people) /. year_size *. prob in
+ if prob' &lt; 0.5 then
+ Printf.printf "answer = %d\n" (people+1)
+ else
+ birthday_paradox prob' (people+1) ;;
+
+birthday_paradox 1.0 1
+
+(* Church numerals *)
+let zero f x = x
+let succ n f x = f (n f x)
+let one = succ zero
+let two = succ (succ zero)
+let add n1 n2 f x = n1 f (n2 f x)
+let to_string n = n (fun k -&gt; "S" ^ k) "0"
+let _ = to_string (add (succ two) two)
+
+(* Elementary functions *)
+let square x = x * x;;
+let rec fact x =
+ if x &lt;= 1 then 1 else x * fact (x - 1);;
+
+(* Automatic memory management *)
+let l = 1 :: 2 :: 3 :: [];;
+[1; 2; 3];;
+5 :: l;;
+
+(* Polymorphism: sorting lists *)
+let rec sort = function
+ | [] -&gt; []
+ | x :: l -&gt; insert x (sort l)
+
+and insert elem = function
+ | [] -&gt; [elem]
+ | x :: l -&gt;
+ if elem &lt; x then elem :: x :: l else x :: insert elem l;;
+
+(* Imperative features *)
+let add_polynom p1 p2 =
+ let n1 = Array.length p1
+ and n2 = Array.length p2 in
+ let result = Array.create (max n1 n2) 0 in
+ for i = 0 to n1 - 1 do result.(i) &lt;- p1.(i) done;
+ for i = 0 to n2 - 1 do result.(i) &lt;- result.(i) + p2.(i) done;
+ result;;
+add_polynom [| 1; 2 |] [| 1; 2; 3 |];;
+
+(* We may redefine fact using a reference cell and a for loop *)
+let fact n =
+ let result = ref 1 in
+ for i = 2 to n do
+ result := i * !result
+ done;
+ !result;;
+fact 5;;
+
+(* Triangle (graphics) *)
+let () =
+ ignore( Glut.init Sys.argv );
+ Glut.initDisplayMode ~double_buffer:true ();
+ ignore (Glut.createWindow ~title:"OpenGL Demo");
+ let angle t = 10. *. t *. t in
+ let render () =
+ GlClear.clear [ `color ];
+ GlMat.load_identity ();
+ GlMat.rotate ~angle: (angle (Sys.time ())) ~z:1. ();
+ GlDraw.begins `triangles;
+ List.iter GlDraw.vertex2 [-1., -1.; 0., 1.; 1., -1.];
+ GlDraw.ends ();
+ Glut.swapBuffers () in
+ GlMat.mode `modelview;
+ Glut.displayFunc ~cb:render;
+ Glut.idleFunc ~cb:(Some Glut.postRedisplay);
+ Glut.mainLoop ()
+
+(* A Hundred Lines of Caml - http://caml.inria.fr/about/taste.en.html *)
+(* OCaml page on Wikipedia - http://en.wikipedia.org/wiki/OCaml *)
+</textarea>
+
+<h2>F# mode</h2>
+<textarea id="fsharpCode">
+module CodeMirror.FSharp
+
+let rec fib = function
+ | 0 -> 0
+ | 1 -> 1
+ | n -> fib (n - 1) + fib (n - 2)
+
+type Point =
+ {
+ x : int
+ y : int
+ }
+
+type Color =
+ | Red
+ | Green
+ | Blue
+
+[0 .. 10]
+|> List.map ((+) 2)
+|> List.fold (fun x y -> x + y) 0
+|> printf "%i"
+</textarea>
+
+
+<script>
+ var ocamlEditor = CodeMirror.fromTextArea(document.getElementById('ocamlCode'), {
+ mode: 'text/x-ocaml',
+ lineNumbers: true,
+ matchBrackets: true
+ });
+
+ var fsharpEditor = CodeMirror.fromTextArea(document.getElementById('fsharpCode'), {
+ mode: 'text/x-fsharp',
+ lineNumbers: true,
+ matchBrackets: true
+ });
+</script>
+
+<p><strong>MIME types defined:</strong> <code>text/x-ocaml</code> (OCaml) and <code>text/x-fsharp</code> (F#).</p>
+</article>
diff --git a/public/vendor/codemirror/mode/mllike/mllike.js b/public/vendor/codemirror/mode/mllike/mllike.js
new file mode 100755
index 00000000..bf0b8a67
--- /dev/null
+++ b/public/vendor/codemirror/mode/mllike/mllike.js
@@ -0,0 +1,205 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.defineMode('mllike', function(_config, parserConfig) {
+ var words = {
+ 'let': 'keyword',
+ 'rec': 'keyword',
+ 'in': 'keyword',
+ 'of': 'keyword',
+ 'and': 'keyword',
+ 'if': 'keyword',
+ 'then': 'keyword',
+ 'else': 'keyword',
+ 'for': 'keyword',
+ 'to': 'keyword',
+ 'while': 'keyword',
+ 'do': 'keyword',
+ 'done': 'keyword',
+ 'fun': 'keyword',
+ 'function': 'keyword',
+ 'val': 'keyword',
+ 'type': 'keyword',
+ 'mutable': 'keyword',
+ 'match': 'keyword',
+ 'with': 'keyword',
+ 'try': 'keyword',
+ 'open': 'builtin',
+ 'ignore': 'builtin',
+ 'begin': 'keyword',
+ 'end': 'keyword'
+ };
+
+ var extraWords = parserConfig.extraWords || {};
+ for (var prop in extraWords) {
+ if (extraWords.hasOwnProperty(prop)) {
+ words[prop] = parserConfig.extraWords[prop];
+ }
+ }
+
+ function tokenBase(stream, state) {
+ var ch = stream.next();
+
+ if (ch === '"') {
+ state.tokenize = tokenString;
+ return state.tokenize(stream, state);
+ }
+ if (ch === '(') {
+ if (stream.eat('*')) {
+ state.commentLevel++;
+ state.tokenize = tokenComment;
+ return state.tokenize(stream, state);
+ }
+ }
+ if (ch === '~') {
+ stream.eatWhile(/\w/);
+ return 'variable-2';
+ }
+ if (ch === '`') {
+ stream.eatWhile(/\w/);
+ return 'quote';
+ }
+ if (ch === '/' && parserConfig.slashComments && stream.eat('/')) {
+ stream.skipToEnd();
+ return 'comment';
+ }
+ if (/\d/.test(ch)) {
+ stream.eatWhile(/[\d]/);
+ if (stream.eat('.')) {
+ stream.eatWhile(/[\d]/);
+ }
+ return 'number';
+ }
+ if ( /[+\-*&%=<>!?|]/.test(ch)) {
+ return 'operator';
+ }
+ stream.eatWhile(/\w/);
+ var cur = stream.current();
+ return words.hasOwnProperty(cur) ? words[cur] : 'variable';
+ }
+
+ function tokenString(stream, state) {
+ var next, end = false, escaped = false;
+ while ((next = stream.next()) != null) {
+ if (next === '"' && !escaped) {
+ end = true;
+ break;
+ }
+ escaped = !escaped && next === '\\';
+ }
+ if (end && !escaped) {
+ state.tokenize = tokenBase;
+ }
+ return 'string';
+ };
+
+ function tokenComment(stream, state) {
+ var prev, next;
+ while(state.commentLevel > 0 && (next = stream.next()) != null) {
+ if (prev === '(' && next === '*') state.commentLevel++;
+ if (prev === '*' && next === ')') state.commentLevel--;
+ prev = next;
+ }
+ if (state.commentLevel <= 0) {
+ state.tokenize = tokenBase;
+ }
+ return 'comment';
+ }
+
+ return {
+ startState: function() {return {tokenize: tokenBase, commentLevel: 0};},
+ token: function(stream, state) {
+ if (stream.eatSpace()) return null;
+ return state.tokenize(stream, state);
+ },
+
+ blockCommentStart: "(*",
+ blockCommentEnd: "*)",
+ lineComment: parserConfig.slashComments ? "//" : null
+ };
+});
+
+CodeMirror.defineMIME('text/x-ocaml', {
+ name: 'mllike',
+ extraWords: {
+ 'succ': 'keyword',
+ 'trace': 'builtin',
+ 'exit': 'builtin',
+ 'print_string': 'builtin',
+ 'print_endline': 'builtin',
+ 'true': 'atom',
+ 'false': 'atom',
+ 'raise': 'keyword'
+ }
+});
+
+CodeMirror.defineMIME('text/x-fsharp', {
+ name: 'mllike',
+ extraWords: {
+ 'abstract': 'keyword',
+ 'as': 'keyword',
+ 'assert': 'keyword',
+ 'base': 'keyword',
+ 'class': 'keyword',
+ 'default': 'keyword',
+ 'delegate': 'keyword',
+ 'downcast': 'keyword',
+ 'downto': 'keyword',
+ 'elif': 'keyword',
+ 'exception': 'keyword',
+ 'extern': 'keyword',
+ 'finally': 'keyword',
+ 'global': 'keyword',
+ 'inherit': 'keyword',
+ 'inline': 'keyword',
+ 'interface': 'keyword',
+ 'internal': 'keyword',
+ 'lazy': 'keyword',
+ 'let!': 'keyword',
+ 'member' : 'keyword',
+ 'module': 'keyword',
+ 'namespace': 'keyword',
+ 'new': 'keyword',
+ 'null': 'keyword',
+ 'override': 'keyword',
+ 'private': 'keyword',
+ 'public': 'keyword',
+ 'return': 'keyword',
+ 'return!': 'keyword',
+ 'select': 'keyword',
+ 'static': 'keyword',
+ 'struct': 'keyword',
+ 'upcast': 'keyword',
+ 'use': 'keyword',
+ 'use!': 'keyword',
+ 'val': 'keyword',
+ 'when': 'keyword',
+ 'yield': 'keyword',
+ 'yield!': 'keyword',
+
+ 'List': 'builtin',
+ 'Seq': 'builtin',
+ 'Map': 'builtin',
+ 'Set': 'builtin',
+ 'int': 'builtin',
+ 'string': 'builtin',
+ 'raise': 'builtin',
+ 'failwith': 'builtin',
+ 'not': 'builtin',
+ 'true': 'builtin',
+ 'false': 'builtin'
+ },
+ slashComments: true
+});
+
+});