LaravelTest
139 строк · 4.4 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("octave", function() {15function wordRegexp(words) {16return new RegExp("^((" + words.join(")|(") + "))\\b");17}18
19var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]");20var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;\\.]');21var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))");22var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))");23var tripleDelimiters = new RegExp("^((>>=)|(<<=))");24var expressionEnd = new RegExp("^[\\]\\)]");25var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*");26
27var 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'35]);36
37var 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',41'continue', 'pkg'42]);43
44
45// tokenizers46function tokenTranspose(stream, state) {47if (!stream.sol() && stream.peek() === '\'') {48stream.next();49state.tokenize = tokenBase;50return 'operator';51}52state.tokenize = tokenBase;53return tokenBase(stream, state);54}55
56
57function tokenComment(stream, state) {58if (stream.match(/^.*%}/)) {59state.tokenize = tokenBase;60return 'comment';61};62stream.skipToEnd();63return 'comment';64}65
66function tokenBase(stream, state) {67// whitespaces68if (stream.eatSpace()) return null;69
70// Handle one line Comments71if (stream.match('%{')){72state.tokenize = tokenComment;73stream.skipToEnd();74return 'comment';75}76
77if (stream.match(/^[%#]/)){78stream.skipToEnd();79return 'comment';80}81
82// Handle Number Literals83if (stream.match(/^[0-9\.+-]/, false)) {84if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {85stream.tokenize = tokenBase;86return 'number'; };87if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };88if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; };89}90if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; };91
92// Handle Strings93var m = stream.match(/^"(?:[^"]|"")*("|$)/) || stream.match(/^'(?:[^']|'')*('|$)/)94if (m) { return m[1] ? 'string' : "string error"; }95
96// Handle words97if (stream.match(keywords)) { return 'keyword'; } ;98if (stream.match(builtins)) { return 'builtin'; } ;99if (stream.match(identifiers)) { return 'variable'; } ;100
101if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; };102if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; };103
104if (stream.match(expressionEnd)) {105state.tokenize = tokenTranspose;106return null;107};108
109
110// Handle non-detected items111stream.next();112return 'error';113};114
115
116return {117startState: function() {118return {119tokenize: tokenBase120};121},122
123token: function(stream, state) {124var style = state.tokenize(stream, state);125if (style === 'number' || style === 'variable'){126state.tokenize = tokenTranspose;127}128return style;129},130
131lineComment: '%',132
133fold: 'indent'134};135});136
137CodeMirror.defineMIME("text/x-octave", "octave");138
139});140