From fb70833bc52aedffa3ed0764a31b706dd1fb3250 Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Wed, 1 Jun 2016 14:37:28 +0800 Subject: Update CodeMirror to version 5.15.3 --- public/vendor/codemirror/mode/yacas/yacas.js | 72 ++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) (limited to 'public/vendor/codemirror/mode/yacas/yacas.js') diff --git a/public/vendor/codemirror/mode/yacas/yacas.js b/public/vendor/codemirror/mode/yacas/yacas.js index 2967382b..30bd60b2 100644 --- a/public/vendor/codemirror/mode/yacas/yacas.js +++ b/public/vendor/codemirror/mode/yacas/yacas.js @@ -16,6 +16,19 @@ CodeMirror.defineMode('yacas', function(_config, _parserConfig) { + function words(str) { + var obj = {}, words = str.split(" "); + for (var i = 0; i < words.length; ++i) obj[words[i]] = true; + return obj; + } + + var bodiedOps = words("Assert BackQuote D Defun Deriv For ForEach FromFile " + + "FromString Function Integrate InverseTaylor Limit " + + "LocalSymbols Macro MacroRule MacroRulePattern " + + "NIntegrate Rule RulePattern Subst TD TExplicitSum " + + "TSum Taylor Taylor1 Taylor2 Taylor3 ToFile " + + "ToStdout ToString TraceRule Until While"); + // patterns var pFloatForm = "(?:(?:\\.\\d+|\\d+\\.\\d*|\\d+)(?:[eE][+-]?\\d+)?)"; var pIdentifier = "(?:[a-zA-Z\\$'][a-zA-Z0-9\\$']*)"; @@ -53,6 +66,33 @@ CodeMirror.defineMode('yacas', function(_config, _parserConfig) { // go back one character stream.backUp(1); + // update scope info + var m = stream.match(/^(\w+)\s*\(/, false); + if (m !== null && bodiedOps.hasOwnProperty(m[1])) + state.scopes.push('bodied'); + + var scope = currentScope(state); + + if (scope === 'bodied' && ch === '[') + state.scopes.pop(); + + if (ch === '[' || ch === '{' || ch === '(') + state.scopes.push(ch); + + scope = currentScope(state); + + if (scope === '[' && ch === ']' || + scope === '{' && ch === '}' || + scope === '(' && ch === ')') + state.scopes.pop(); + + if (ch === ';') { + while (scope === 'bodied') { + state.scopes.pop(); + scope = currentScope(state); + } + } + // look for ordered rules if (stream.match(/\d+ *#/, true, false)) { return 'qualifier'; @@ -111,20 +151,46 @@ CodeMirror.defineMode('yacas', function(_config, _parserConfig) { function tokenComment(stream, state) { var prev, next; while((next = stream.next()) != null) { - if (prev === '*' && next === '/') + if (prev === '*' && next === '/') { + state.tokenize = tokenBase; break; + } prev = next; } - state.tokenize = tokenBase; return 'comment'; } + function currentScope(state) { + var scope = null; + if (state.scopes.length > 0) + scope = state.scopes[state.scopes.length - 1]; + return scope; + } + return { - startState: function() {return {tokenize: tokenBase, commentLevel: 0};}, + startState: function() { + return { + tokenize: tokenBase, + scopes: [] + }; + }, token: function(stream, state) { if (stream.eatSpace()) return null; return state.tokenize(stream, state); }, + indent: function(state, textAfter) { + if (state.tokenize !== tokenBase && state.tokenize !== null) + return CodeMirror.Pass; + + var delta = 0; + if (textAfter === ']' || textAfter === '];' || + textAfter === '}' || textAfter === '};' || + textAfter === ');') + delta = -1; + + return (state.scopes.length + delta) * _config.indentUnit; + }, + electricChars: "{}[]();", blockCommentStart: "/*", blockCommentEnd: "*/", lineComment: "//" -- cgit v1.2.3