Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/yacas
File: yacas.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
// Yacas mode copyright (c) 2015 by Grzegorz Mazur
[3] Fix | Delete
// Loosely based on mathematica mode by Calin Barbat
[4] Fix | Delete
[5] Fix | Delete
(function(mod) {
[6] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[7] Fix | Delete
mod(require("../../lib/codemirror"));
[8] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[9] Fix | Delete
define(["../../lib/codemirror"], mod);
[10] Fix | Delete
else // Plain browser env
[11] Fix | Delete
mod(CodeMirror);
[12] Fix | Delete
})(function(CodeMirror) {
[13] Fix | Delete
"use strict";
[14] Fix | Delete
[15] Fix | Delete
CodeMirror.defineMode('yacas', function(_config, _parserConfig) {
[16] Fix | Delete
[17] Fix | Delete
function words(str) {
[18] Fix | Delete
var obj = {}, words = str.split(" ");
[19] Fix | Delete
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
[20] Fix | Delete
return obj;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
var bodiedOps = words("Assert BackQuote D Defun Deriv For ForEach FromFile " +
[24] Fix | Delete
"FromString Function Integrate InverseTaylor Limit " +
[25] Fix | Delete
"LocalSymbols Macro MacroRule MacroRulePattern " +
[26] Fix | Delete
"NIntegrate Rule RulePattern Subst TD TExplicitSum " +
[27] Fix | Delete
"TSum Taylor Taylor1 Taylor2 Taylor3 ToFile " +
[28] Fix | Delete
"ToStdout ToString TraceRule Until While");
[29] Fix | Delete
[30] Fix | Delete
// patterns
[31] Fix | Delete
var pFloatForm = "(?:(?:\\.\\d+|\\d+\\.\\d*|\\d+)(?:[eE][+-]?\\d+)?)";
[32] Fix | Delete
var pIdentifier = "(?:[a-zA-Z\\$'][a-zA-Z0-9\\$']*)";
[33] Fix | Delete
[34] Fix | Delete
// regular expressions
[35] Fix | Delete
var reFloatForm = new RegExp(pFloatForm);
[36] Fix | Delete
var reIdentifier = new RegExp(pIdentifier);
[37] Fix | Delete
var rePattern = new RegExp(pIdentifier + "?_" + pIdentifier);
[38] Fix | Delete
var reFunctionLike = new RegExp(pIdentifier + "\\s*\\(");
[39] Fix | Delete
[40] Fix | Delete
function tokenBase(stream, state) {
[41] Fix | Delete
var ch;
[42] Fix | Delete
[43] Fix | Delete
// get next character
[44] Fix | Delete
ch = stream.next();
[45] Fix | Delete
[46] Fix | Delete
// string
[47] Fix | Delete
if (ch === '"') {
[48] Fix | Delete
state.tokenize = tokenString;
[49] Fix | Delete
return state.tokenize(stream, state);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
// comment
[53] Fix | Delete
if (ch === '/') {
[54] Fix | Delete
if (stream.eat('*')) {
[55] Fix | Delete
state.tokenize = tokenComment;
[56] Fix | Delete
return state.tokenize(stream, state);
[57] Fix | Delete
}
[58] Fix | Delete
if (stream.eat("/")) {
[59] Fix | Delete
stream.skipToEnd();
[60] Fix | Delete
return "comment";
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
// go back one character
[65] Fix | Delete
stream.backUp(1);
[66] Fix | Delete
[67] Fix | Delete
// update scope info
[68] Fix | Delete
var m = stream.match(/^(\w+)\s*\(/, false);
[69] Fix | Delete
if (m !== null && bodiedOps.hasOwnProperty(m[1]))
[70] Fix | Delete
state.scopes.push('bodied');
[71] Fix | Delete
[72] Fix | Delete
var scope = currentScope(state);
[73] Fix | Delete
[74] Fix | Delete
if (scope === 'bodied' && ch === '[')
[75] Fix | Delete
state.scopes.pop();
[76] Fix | Delete
[77] Fix | Delete
if (ch === '[' || ch === '{' || ch === '(')
[78] Fix | Delete
state.scopes.push(ch);
[79] Fix | Delete
[80] Fix | Delete
scope = currentScope(state);
[81] Fix | Delete
[82] Fix | Delete
if (scope === '[' && ch === ']' ||
[83] Fix | Delete
scope === '{' && ch === '}' ||
[84] Fix | Delete
scope === '(' && ch === ')')
[85] Fix | Delete
state.scopes.pop();
[86] Fix | Delete
[87] Fix | Delete
if (ch === ';') {
[88] Fix | Delete
while (scope === 'bodied') {
[89] Fix | Delete
state.scopes.pop();
[90] Fix | Delete
scope = currentScope(state);
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
// look for ordered rules
[95] Fix | Delete
if (stream.match(/\d+ *#/, true, false)) {
[96] Fix | Delete
return 'qualifier';
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
// look for numbers
[100] Fix | Delete
if (stream.match(reFloatForm, true, false)) {
[101] Fix | Delete
return 'number';
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// look for placeholders
[105] Fix | Delete
if (stream.match(rePattern, true, false)) {
[106] Fix | Delete
return 'variable-3';
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
// match all braces separately
[110] Fix | Delete
if (stream.match(/(?:\[|\]|{|}|\(|\))/, true, false)) {
[111] Fix | Delete
return 'bracket';
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
// literals looking like function calls
[115] Fix | Delete
if (stream.match(reFunctionLike, true, false)) {
[116] Fix | Delete
stream.backUp(1);
[117] Fix | Delete
return 'variable';
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
// all other identifiers
[121] Fix | Delete
if (stream.match(reIdentifier, true, false)) {
[122] Fix | Delete
return 'variable-2';
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
// operators; note that operators like @@ or /; are matched separately for each symbol.
[126] Fix | Delete
if (stream.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%)/, true, false)) {
[127] Fix | Delete
return 'operator';
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
// everything else is an error
[131] Fix | Delete
return 'error';
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
function tokenString(stream, state) {
[135] Fix | Delete
var next, end = false, escaped = false;
[136] Fix | Delete
while ((next = stream.next()) != null) {
[137] Fix | Delete
if (next === '"' && !escaped) {
[138] Fix | Delete
end = true;
[139] Fix | Delete
break;
[140] Fix | Delete
}
[141] Fix | Delete
escaped = !escaped && next === '\\';
[142] Fix | Delete
}
[143] Fix | Delete
if (end && !escaped) {
[144] Fix | Delete
state.tokenize = tokenBase;
[145] Fix | Delete
}
[146] Fix | Delete
return 'string';
[147] Fix | Delete
};
[148] Fix | Delete
[149] Fix | Delete
function tokenComment(stream, state) {
[150] Fix | Delete
var prev, next;
[151] Fix | Delete
while((next = stream.next()) != null) {
[152] Fix | Delete
if (prev === '*' && next === '/') {
[153] Fix | Delete
state.tokenize = tokenBase;
[154] Fix | Delete
break;
[155] Fix | Delete
}
[156] Fix | Delete
prev = next;
[157] Fix | Delete
}
[158] Fix | Delete
return 'comment';
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
function currentScope(state) {
[162] Fix | Delete
var scope = null;
[163] Fix | Delete
if (state.scopes.length > 0)
[164] Fix | Delete
scope = state.scopes[state.scopes.length - 1];
[165] Fix | Delete
return scope;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return {
[169] Fix | Delete
startState: function() {
[170] Fix | Delete
return {
[171] Fix | Delete
tokenize: tokenBase,
[172] Fix | Delete
scopes: []
[173] Fix | Delete
};
[174] Fix | Delete
},
[175] Fix | Delete
token: function(stream, state) {
[176] Fix | Delete
if (stream.eatSpace()) return null;
[177] Fix | Delete
return state.tokenize(stream, state);
[178] Fix | Delete
},
[179] Fix | Delete
indent: function(state, textAfter) {
[180] Fix | Delete
if (state.tokenize !== tokenBase && state.tokenize !== null)
[181] Fix | Delete
return CodeMirror.Pass;
[182] Fix | Delete
[183] Fix | Delete
var delta = 0;
[184] Fix | Delete
if (textAfter === ']' || textAfter === '];' ||
[185] Fix | Delete
textAfter === '}' || textAfter === '};' ||
[186] Fix | Delete
textAfter === ');')
[187] Fix | Delete
delta = -1;
[188] Fix | Delete
[189] Fix | Delete
return (state.scopes.length + delta) * _config.indentUnit;
[190] Fix | Delete
},
[191] Fix | Delete
electricChars: "{}[]();",
[192] Fix | Delete
blockCommentStart: "/*",
[193] Fix | Delete
blockCommentEnd: "*/",
[194] Fix | Delete
lineComment: "//"
[195] Fix | Delete
};
[196] Fix | Delete
});
[197] Fix | Delete
[198] Fix | Delete
CodeMirror.defineMIME('text/x-yacas', {
[199] Fix | Delete
name: 'yacas'
[200] Fix | Delete
});
[201] Fix | Delete
[202] Fix | Delete
});
[203] Fix | Delete
[204] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function