8
if (typeof exports == "object" && typeof module == "object")
9
mod(require("../../lib/codemirror"));
10
else if (typeof define == "function" && define.amd)
11
define(["../../lib/codemirror"], mod);
14
})(function(CodeMirror) {
17
CodeMirror.defineMode('yacas', function(_config, _parserConfig) {
20
var obj = {}, words = str.split(" ");
21
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
25
var bodiedOps = words("Assert BackQuote D Defun Deriv For ForEach FromFile " +
26
"FromString Function Integrate InverseTaylor Limit " +
27
"LocalSymbols Macro MacroRule MacroRulePattern " +
28
"NIntegrate Rule RulePattern Subst TD TExplicitSum " +
29
"TSum Taylor Taylor1 Taylor2 Taylor3 ToFile " +
30
"ToStdout ToString TraceRule Until While");
33
var pFloatForm = "(?:(?:\\.\\d+|\\d+\\.\\d*|\\d+)(?:[eE][+-]?\\d+)?)";
34
var pIdentifier = "(?:[a-zA-Z\\$'][a-zA-Z0-9\\$']*)";
37
var reFloatForm = new RegExp(pFloatForm);
38
var reIdentifier = new RegExp(pIdentifier);
39
var rePattern = new RegExp(pIdentifier + "?_" + pIdentifier);
40
var reFunctionLike = new RegExp(pIdentifier + "\\s*\\(");
42
function tokenBase(stream, state) {
50
state.tokenize = tokenString;
51
return state.tokenize(stream, state);
56
if (stream.eat('*')) {
57
state.tokenize = tokenComment;
58
return state.tokenize(stream, state);
60
if (stream.eat("/")) {
70
var m = stream.match(/^(\w+)\s*\(/, false);
71
if (m !== null && bodiedOps.hasOwnProperty(m[1]))
72
state.scopes.push('bodied');
74
var scope = currentScope(state);
76
if (scope === 'bodied' && ch === '[')
79
if (ch === '[' || ch === '{' || ch === '(')
80
state.scopes.push(ch);
82
scope = currentScope(state);
84
if (scope === '[' && ch === ']' ||
85
scope === '{' && ch === '}' ||
86
scope === '(' && ch === ')')
90
while (scope === 'bodied') {
92
scope = currentScope(state);
97
if (stream.match(/\d+ *#/, true, false)) {
102
if (stream.match(reFloatForm, true, false)) {
107
if (stream.match(rePattern, true, false)) {
112
if (stream.match(/(?:\[|\]|{|}|\(|\))/, true, false)) {
117
if (stream.match(reFunctionLike, true, false)) {
123
if (stream.match(reIdentifier, true, false)) {
128
if (stream.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%|#)/, true, false)) {
136
function tokenString(stream, state) {
137
var next, end = false, escaped = false;
138
while ((next = stream.next()) != null) {
139
if (next === '"' && !escaped) {
143
escaped = !escaped && next === '\\';
145
if (end && !escaped) {
146
state.tokenize = tokenBase;
151
function tokenComment(stream, state) {
153
while((next = stream.next()) != null) {
154
if (prev === '*' && next === '/') {
155
state.tokenize = tokenBase;
163
function currentScope(state) {
165
if (state.scopes.length > 0)
166
scope = state.scopes[state.scopes.length - 1];
171
startState: function() {
177
token: function(stream, state) {
178
if (stream.eatSpace()) return null;
179
return state.tokenize(stream, state);
181
indent: function(state, textAfter) {
182
if (state.tokenize !== tokenBase && state.tokenize !== null)
183
return CodeMirror.Pass;
186
if (textAfter === ']' || textAfter === '];' ||
187
textAfter === '}' || textAfter === '};' ||
191
return (state.scopes.length + delta) * _config.indentUnit;
193
electricChars: "{}[]();",
194
blockCommentStart: "/*",
195
blockCommentEnd: "*/",
200
CodeMirror.defineMIME('text/x-yacas', {