Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/mathemat...
File: mathematica.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
// Mathematica mode copyright (c) 2015 by Calin Barbat
[3] Fix | Delete
// Based on code by Patrick Scheibe (halirutan)
[4] Fix | Delete
// See: https://github.com/halirutan/Mathematica-Source-Highlighting/tree/master/src/lang-mma.js
[5] Fix | Delete
[6] Fix | Delete
(function(mod) {
[7] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[8] Fix | Delete
mod(require("../../lib/codemirror"));
[9] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[10] Fix | Delete
define(["../../lib/codemirror"], mod);
[11] Fix | Delete
else // Plain browser env
[12] Fix | Delete
mod(CodeMirror);
[13] Fix | Delete
})(function(CodeMirror) {
[14] Fix | Delete
"use strict";
[15] Fix | Delete
[16] Fix | Delete
CodeMirror.defineMode('mathematica', function(_config, _parserConfig) {
[17] Fix | Delete
[18] Fix | Delete
// used pattern building blocks
[19] Fix | Delete
var Identifier = '[a-zA-Z\\$][a-zA-Z0-9\\$]*';
[20] Fix | Delete
var pBase = "(?:\\d+)";
[21] Fix | Delete
var pFloat = "(?:\\.\\d+|\\d+\\.\\d*|\\d+)";
[22] Fix | Delete
var pFloatBase = "(?:\\.\\w+|\\w+\\.\\w*|\\w+)";
[23] Fix | Delete
var pPrecision = "(?:`(?:`?"+pFloat+")?)";
[24] Fix | Delete
[25] Fix | Delete
// regular expressions
[26] Fix | Delete
var reBaseForm = new RegExp('(?:'+pBase+'(?:\\^\\^'+pFloatBase+pPrecision+'?(?:\\*\\^[+-]?\\d+)?))');
[27] Fix | Delete
var reFloatForm = new RegExp('(?:' + pFloat + pPrecision + '?(?:\\*\\^[+-]?\\d+)?)');
[28] Fix | Delete
var reIdInContext = new RegExp('(?:`?)(?:' + Identifier + ')(?:`(?:' + Identifier + '))*(?:`?)');
[29] Fix | Delete
[30] Fix | Delete
function tokenBase(stream, state) {
[31] Fix | Delete
var ch;
[32] Fix | Delete
[33] Fix | Delete
// get next character
[34] Fix | Delete
ch = stream.next();
[35] Fix | Delete
[36] Fix | Delete
// string
[37] Fix | Delete
if (ch === '"') {
[38] Fix | Delete
state.tokenize = tokenString;
[39] Fix | Delete
return state.tokenize(stream, state);
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
// comment
[43] Fix | Delete
if (ch === '(') {
[44] Fix | Delete
if (stream.eat('*')) {
[45] Fix | Delete
state.commentLevel++;
[46] Fix | Delete
state.tokenize = tokenComment;
[47] Fix | Delete
return state.tokenize(stream, state);
[48] Fix | Delete
}
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
// go back one character
[52] Fix | Delete
stream.backUp(1);
[53] Fix | Delete
[54] Fix | Delete
// look for numbers
[55] Fix | Delete
// Numbers in a baseform
[56] Fix | Delete
if (stream.match(reBaseForm, true, false)) {
[57] Fix | Delete
return 'number';
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
// Mathematica numbers. Floats (1.2, .2, 1.) can have optionally a precision (`float) or an accuracy definition
[61] Fix | Delete
// (``float). Note: while 1.2` is possible 1.2`` is not. At the end an exponent (float*^+12) can follow.
[62] Fix | Delete
if (stream.match(reFloatForm, true, false)) {
[63] Fix | Delete
return 'number';
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/* In[23] and Out[34] */
[67] Fix | Delete
if (stream.match(/(?:In|Out)\[[0-9]*\]/, true, false)) {
[68] Fix | Delete
return 'atom';
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// usage
[72] Fix | Delete
if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::usage)/, true, false)) {
[73] Fix | Delete
return 'meta';
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
// message
[77] Fix | Delete
if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::[a-zA-Z\$][a-zA-Z0-9\$]*):?/, true, false)) {
[78] Fix | Delete
return 'string-2';
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// this makes a look-ahead match for something like variable:{_Integer}
[82] Fix | Delete
// the match is then forwarded to the mma-patterns tokenizer.
[83] Fix | Delete
if (stream.match(/([a-zA-Z\$][a-zA-Z0-9\$]*\s*:)(?:(?:[a-zA-Z\$][a-zA-Z0-9\$]*)|(?:[^:=>~@\^\&\*\)\[\]'\?,\|])).*/, true, false)) {
[84] Fix | Delete
return 'variable-2';
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
// catch variables which are used together with Blank (_), BlankSequence (__) or BlankNullSequence (___)
[88] Fix | Delete
// Cannot start with a number, but can have numbers at any other position. Examples
[89] Fix | Delete
// blub__Integer, a1_, b34_Integer32
[90] Fix | Delete
if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) {
[91] Fix | Delete
return 'variable-2';
[92] Fix | Delete
}
[93] Fix | Delete
if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+/, true, false)) {
[94] Fix | Delete
return 'variable-2';
[95] Fix | Delete
}
[96] Fix | Delete
if (stream.match(/_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) {
[97] Fix | Delete
return 'variable-2';
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// Named characters in Mathematica, like \[Gamma].
[101] Fix | Delete
if (stream.match(/\\\[[a-zA-Z\$][a-zA-Z0-9\$]*\]/, true, false)) {
[102] Fix | Delete
return 'variable-3';
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
// Match all braces separately
[106] Fix | Delete
if (stream.match(/(?:\[|\]|{|}|\(|\))/, true, false)) {
[107] Fix | Delete
return 'bracket';
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
// Catch Slots (#, ##, #3, ##9 and the V10 named slots #name). I have never seen someone using more than one digit after #, so we match
[111] Fix | Delete
// only one.
[112] Fix | Delete
if (stream.match(/(?:#[a-zA-Z\$][a-zA-Z0-9\$]*|#+[0-9]?)/, true, false)) {
[113] Fix | Delete
return 'variable-2';
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
// Literals like variables, keywords, functions
[117] Fix | Delete
if (stream.match(reIdInContext, true, false)) {
[118] Fix | Delete
return 'keyword';
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// operators. Note that operators like @@ or /; are matched separately for each symbol.
[122] Fix | Delete
if (stream.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%)/, true, false)) {
[123] Fix | Delete
return 'operator';
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
// everything else is an error
[127] Fix | Delete
stream.next(); // advance the stream.
[128] Fix | Delete
return 'error';
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
function tokenString(stream, state) {
[132] Fix | Delete
var next, end = false, escaped = false;
[133] Fix | Delete
while ((next = stream.next()) != null) {
[134] Fix | Delete
if (next === '"' && !escaped) {
[135] Fix | Delete
end = true;
[136] Fix | Delete
break;
[137] Fix | Delete
}
[138] Fix | Delete
escaped = !escaped && next === '\\';
[139] Fix | Delete
}
[140] Fix | Delete
if (end && !escaped) {
[141] Fix | Delete
state.tokenize = tokenBase;
[142] Fix | Delete
}
[143] Fix | Delete
return 'string';
[144] Fix | Delete
};
[145] Fix | Delete
[146] Fix | Delete
function tokenComment(stream, state) {
[147] Fix | Delete
var prev, next;
[148] Fix | Delete
while(state.commentLevel > 0 && (next = stream.next()) != null) {
[149] Fix | Delete
if (prev === '(' && next === '*') state.commentLevel++;
[150] Fix | Delete
if (prev === '*' && next === ')') state.commentLevel--;
[151] Fix | Delete
prev = next;
[152] Fix | Delete
}
[153] Fix | Delete
if (state.commentLevel <= 0) {
[154] Fix | Delete
state.tokenize = tokenBase;
[155] Fix | Delete
}
[156] Fix | Delete
return 'comment';
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
return {
[160] Fix | Delete
startState: function() {return {tokenize: tokenBase, commentLevel: 0};},
[161] Fix | Delete
token: function(stream, state) {
[162] Fix | Delete
if (stream.eatSpace()) return null;
[163] Fix | Delete
return state.tokenize(stream, state);
[164] Fix | Delete
},
[165] Fix | Delete
blockCommentStart: "(*",
[166] Fix | Delete
blockCommentEnd: "*)"
[167] Fix | Delete
};
[168] Fix | Delete
});
[169] Fix | Delete
[170] Fix | Delete
CodeMirror.defineMIME('text/x-mathematica', {
[171] Fix | Delete
name: 'mathematica'
[172] Fix | Delete
});
[173] Fix | Delete
[174] Fix | Delete
});
[175] Fix | Delete
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function