5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("octave", function() {
15
function wordRegexp(words) {
16
return new RegExp("^((" + words.join(")|(") + "))\\b");
19
var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]");
20
var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;\\.]');
21
var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))");
22
var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))");
23
var tripleDelimiters = new RegExp("^((>>=)|(<<=))");
24
var expressionEnd = new RegExp("^[\\]\\)]");
25
var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*");
27
var builtins = wordRegexp([
28
'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos',
29
'cosh', 'exp', 'log', 'prod', 'sum', 'log10', 'max', 'min', 'sign', 'sin', 'sinh',
30
'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones',
31
'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov',
32
'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot',
33
'title', 'xlabel', 'ylabel', 'legend', 'text', 'grid', 'meshgrid', 'mesh', 'num2str',
34
'fft', 'ifft', 'arrayfun', 'cellfun', 'input', 'fliplr', 'flipud', 'ismember'
37
var keywords = wordRegexp([
38
'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction',
39
'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events',
40
'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'sprintf', 'disp', 'until',
46
function tokenTranspose(stream, state) {
47
if (!stream.sol() && stream.peek() === '\'') {
49
state.tokenize = tokenBase;
52
state.tokenize = tokenBase;
53
return tokenBase(stream, state);
57
function tokenComment(stream, state) {
58
if (stream.match(/^.*%}/)) {
59
state.tokenize = tokenBase;
66
function tokenBase(stream, state) {
68
if (stream.eatSpace()) return null;
71
if (stream.match('%{')){
72
state.tokenize = tokenComment;
77
if (stream.match(/^[%#]/)){
83
if (stream.match(/^[0-9\.+-]/, false)) {
84
if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {
85
stream.tokenize = tokenBase;
87
if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
88
if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };
90
if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; };
93
var m = stream.match(/^"(?:[^"]|"")*("|$)/) || stream.match(/^'(?:[^']|'')*('|$)/)
94
if (m) { return m[1] ? 'string' : "string error"; }
97
if (stream.match(keywords)) { return 'keyword'; } ;
98
if (stream.match(builtins)) { return 'builtin'; } ;
99
if (stream.match(identifiers)) { return 'variable'; } ;
101
if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; };
102
if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; };
104
if (stream.match(expressionEnd)) {
105
state.tokenize = tokenTranspose;
117
startState: function() {
123
token: function(stream, state) {
124
var style = state.tokenize(stream, state);
125
if (style === 'number' || style === 'variable'){
126
state.tokenize = tokenTranspose;
137
CodeMirror.defineMIME("text/x-octave", "octave");