summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/mathematica
diff options
context:
space:
mode:
authorWu Cheng-Han2015-07-04 11:31:01 +0800
committerWu Cheng-Han2015-07-04 11:31:01 +0800
commit01685c255fda6e13f1cd2980130d2e388d52125c (patch)
treec329610e7011c0d77c55ef54f371181aeb362d13 /public/vendor/codemirror/mode/mathematica
parent1d843c8ac257d512a96cf054ab24e6a3c2f34e26 (diff)
Updated codemirror to 5.4.0
Diffstat (limited to 'public/vendor/codemirror/mode/mathematica')
-rwxr-xr-xpublic/vendor/codemirror/mode/mathematica/index.html72
-rwxr-xr-xpublic/vendor/codemirror/mode/mathematica/mathematica.js175
2 files changed, 247 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/mathematica/index.html b/public/vendor/codemirror/mode/mathematica/index.html
new file mode 100755
index 00000000..57c42985
--- /dev/null
+++ b/public/vendor/codemirror/mode/mathematica/index.html
@@ -0,0 +1,72 @@
+<!doctype html>
+
+<title>CodeMirror: Mathematica 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=mathematica.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="#">Mathematica</a>
+ </ul>
+</div>
+
+<article>
+<h2>Mathematica mode</h2>
+
+
+<textarea id="mathematicaCode">
+(* example Mathematica code *)
+(* Dualisiert wird anhand einer Polarität an einer
+ Quadrik $x^t Q x = 0$ mit regulärer Matrix $Q$ (also
+ mit $det(Q) \neq 0$), z.B. die Identitätsmatrix.
+ $p$ ist eine Liste von Polynomen - ein Ideal. *)
+dualize::"singular" = "Q must be regular: found Det[Q]==0.";
+dualize[ Q_, p_ ] := Block[
+ { m, n, xv, lv, uv, vars, polys, dual },
+ If[Det[Q] == 0,
+ Message[dualize::"singular"],
+ m = Length[p];
+ n = Length[Q] - 1;
+ xv = Table[Subscript[x, i], {i, 0, n}];
+ lv = Table[Subscript[l, i], {i, 1, m}];
+ uv = Table[Subscript[u, i], {i, 0, n}];
+ (* Konstruiere Ideal polys. *)
+ If[m == 0,
+ polys = Q.uv,
+ polys = Join[p, Q.uv - Transpose[Outer[D, p, xv]].lv]
+ ];
+ (* Eliminiere die ersten n + 1 + m Variablen xv und lv
+ aus dem Ideal polys. *)
+ vars = Join[xv, lv];
+ dual = GroebnerBasis[polys, uv, vars];
+ (* Ersetze u mit x im Ergebnis. *)
+ ReplaceAll[dual, Rule[u, x]]
+ ]
+ ]
+</textarea>
+
+<script>
+ var mathematicaEditor = CodeMirror.fromTextArea(document.getElementById('mathematicaCode'), {
+ mode: 'text/x-mathematica',
+ lineNumbers: true,
+ matchBrackets: true
+ });
+</script>
+
+<p><strong>MIME types defined:</strong> <code>text/x-mathematica</code> (Mathematica).</p>
+</article>
diff --git a/public/vendor/codemirror/mode/mathematica/mathematica.js b/public/vendor/codemirror/mode/mathematica/mathematica.js
new file mode 100755
index 00000000..5ae6f55c
--- /dev/null
+++ b/public/vendor/codemirror/mode/mathematica/mathematica.js
@@ -0,0 +1,175 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+// Mathematica mode copyright (c) 2015 by Calin Barbat
+// Based on code by Patrick Scheibe (halirutan)
+// See: https://github.com/halirutan/Mathematica-Source-Highlighting/tree/master/src/lang-mma.js
+
+(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('mathematica', function(_config, _parserConfig) {
+
+ // used pattern building blocks
+ var Identifier = '[a-zA-Z\\$][a-zA-Z0-9\\$]*';
+ var pBase = "(?:\\d+)";
+ var pFloat = "(?:\\.\\d+|\\d+\\.\\d*|\\d+)";
+ var pFloatBase = "(?:\\.\\w+|\\w+\\.\\w*|\\w+)";
+ var pPrecision = "(?:`(?:`?"+pFloat+")?)";
+
+ // regular expressions
+ var reBaseForm = new RegExp('(?:'+pBase+'(?:\\^\\^'+pFloatBase+pPrecision+'?(?:\\*\\^[+-]?\\d+)?))');
+ var reFloatForm = new RegExp('(?:' + pFloat + pPrecision + '?(?:\\*\\^[+-]?\\d+)?)');
+ var reIdInContext = new RegExp('(?:`?)(?:' + Identifier + ')(?:`(?:' + Identifier + '))*(?:`?)');
+
+ function tokenBase(stream, state) {
+ var ch;
+
+ // get next character
+ ch = stream.next();
+
+ // string
+ if (ch === '"') {
+ state.tokenize = tokenString;
+ return state.tokenize(stream, state);
+ }
+
+ // comment
+ if (ch === '(') {
+ if (stream.eat('*')) {
+ state.commentLevel++;
+ state.tokenize = tokenComment;
+ return state.tokenize(stream, state);
+ }
+ }
+
+ // go back one character
+ stream.backUp(1);
+
+ // look for numbers
+ // Numbers in a baseform
+ if (stream.match(reBaseForm, true, false)) {
+ return 'number';
+ }
+
+ // Mathematica numbers. Floats (1.2, .2, 1.) can have optionally a precision (`float) or an accuracy definition
+ // (``float). Note: while 1.2` is possible 1.2`` is not. At the end an exponent (float*^+12) can follow.
+ if (stream.match(reFloatForm, true, false)) {
+ return 'number';
+ }
+
+ /* In[23] and Out[34] */
+ if (stream.match(/(?:In|Out)\[[0-9]*\]/, true, false)) {
+ return 'atom';
+ }
+
+ // usage
+ if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::usage)/, true, false)) {
+ return 'meta';
+ }
+
+ // message
+ if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::[a-zA-Z\$][a-zA-Z0-9\$]*):?/, true, false)) {
+ return 'string-2';
+ }
+
+ // this makes a look-ahead match for something like variable:{_Integer}
+ // the match is then forwarded to the mma-patterns tokenizer.
+ if (stream.match(/([a-zA-Z\$][a-zA-Z0-9\$]*\s*:)(?:(?:[a-zA-Z\$][a-zA-Z0-9\$]*)|(?:[^:=>~@\^\&\*\)\[\]'\?,\|])).*/, true, false)) {
+ return 'variable-2';
+ }
+
+ // catch variables which are used together with Blank (_), BlankSequence (__) or BlankNullSequence (___)
+ // Cannot start with a number, but can have numbers at any other position. Examples
+ // blub__Integer, a1_, b34_Integer32
+ if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) {
+ return 'variable-2';
+ }
+ if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+/, true, false)) {
+ return 'variable-2';
+ }
+ if (stream.match(/_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) {
+ return 'variable-2';
+ }
+
+ // Named characters in Mathematica, like \[Gamma].
+ if (stream.match(/\\\[[a-zA-Z\$][a-zA-Z0-9\$]*\]/, true, false)) {
+ return 'variable-3';
+ }
+
+ // Match all braces separately
+ if (stream.match(/(?:\[|\]|{|}|\(|\))/, true, false)) {
+ return 'bracket';
+ }
+
+ // Catch Slots (#, ##, #3, ##9 and the V10 named slots #name). I have never seen someone using more than one digit after #, so we match
+ // only one.
+ if (stream.match(/(?:#[a-zA-Z\$][a-zA-Z0-9\$]*|#+[0-9]?)/, true, false)) {
+ return 'variable-2';
+ }
+
+ // Literals like variables, keywords, functions
+ if (stream.match(reIdInContext, true, false)) {
+ return 'keyword';
+ }
+
+ // operators. Note that operators like @@ or /; are matched separately for each symbol.
+ if (stream.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%)/, true, false)) {
+ return 'operator';
+ }
+
+ // everything else is an error
+ return 'error';
+ }
+
+ 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: "*)"
+ };
+});
+
+CodeMirror.defineMIME('text/x-mathematica', {
+ name: 'mathematica'
+});
+
+});