Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/octave/octave.js
1294 views
CodeMirror.defineMode("octave", function() {1function wordRegexp(words) {2return new RegExp("^((" + words.join(")|(") + "))\\b");3}45var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]");6var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;]');7var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))");8var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))");9var tripleDelimiters = new RegExp("^((>>=)|(<<=))");10var expressionEnd = new RegExp("^[\\]\\)]");11var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");1213var builtins = wordRegexp([14'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos',15'cosh', 'exp', 'log', 'prod', 'log10', 'max', 'min', 'sign', 'sin', 'sinh',16'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones',17'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov',18'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot',19'title', 'xlabel', 'ylabel', 'legend', 'text', 'meshgrid', 'mesh', 'num2str'20]);2122var keywords = wordRegexp([23'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction',24'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events',25'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'disp', 'until', 'continue'26]);272829// tokenizers30function tokenTranspose(stream, state) {31if (!stream.sol() && stream.peek() === '\'') {32stream.next();33state.tokenize = tokenBase;34return 'operator';35}36state.tokenize = tokenBase;37return tokenBase(stream, state);38}394041function tokenComment(stream, state) {42if (stream.match(/^.*%}/)) {43state.tokenize = tokenBase;44return 'comment';45};46stream.skipToEnd();47return 'comment';48}4950function tokenBase(stream, state) {51// whitespaces52if (stream.eatSpace()) return null;5354// Handle one line Comments55if (stream.match('%{')){56state.tokenize = tokenComment;57stream.skipToEnd();58return 'comment';59}6061if (stream.match(/^(%)|(\.\.\.)/)){62stream.skipToEnd();63return 'comment';64}6566// Handle Number Literals67if (stream.match(/^[0-9\.+-]/, false)) {68if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {69stream.tokenize = tokenBase;70return 'number'; };71if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };72if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };73}74if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; };7576// Handle Strings77if (stream.match(/^"([^"]|(""))*"/)) { return 'string'; } ;78if (stream.match(/^'([^']|(''))*'/)) { return 'string'; } ;7980// Handle words81if (stream.match(keywords)) { return 'keyword'; } ;82if (stream.match(builtins)) { return 'builtin'; } ;83if (stream.match(identifiers)) { return 'variable'; } ;8485if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; };86if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; };8788if (stream.match(expressionEnd)) {89state.tokenize = tokenTranspose;90return null;91};929394// Handle non-detected items95stream.next();96return 'error';97};9899100return {101startState: function() {102return {103tokenize: tokenBase104};105},106107token: function(stream, state) {108var style = state.tokenize(stream, state);109if (style === 'number' || style === 'variable'){110state.tokenize = tokenTranspose;111}112return style;113}114};115});116117CodeMirror.defineMIME("text/x-octave", "octave");118119120