Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/julia/julia.js
1293 views
CodeMirror.defineMode("julia", function(_conf, parserConf) {1var ERRORCLASS = 'error';23function wordRegexp(words) {4return new RegExp("^((" + words.join(")|(") + "))\\b");5}67var operators = parserConf.operators || /^(?:\.?[|&^\\%*+\-<>!=\/]=?|\?|~|:|\$|<:|\.[<>]|<<=?|>>>?=?|\.[<>=]=|->?|\/\/|\bin\b|\.{3})/;8var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;9var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*!*/;10var blockOpeners = ["begin", "function", "type", "immutable", "let", "macro", "for", "while", "quote", "if", "else", "elseif", "try", "finally", "catch"];11var blockClosers = ["end", "else", "elseif", "catch", "finally"];12var keywordList = ['if', 'else', 'elseif', 'while', 'for', 'begin', 'let', 'end', 'do', 'try', 'catch', 'finally', 'return', 'break', 'continue', 'global', 'local', 'const', 'export', 'import', 'importall', 'using', 'function', 'macro', 'module', 'baremodule', 'type', 'immutable', 'quote', 'typealias', 'abstract', 'bitstype', 'ccall'];13var builtinList = ['true', 'false', 'enumerate', 'open', 'close', 'nothing', 'NaN', 'Inf', 'print', 'println', 'Int8', 'Uint8', 'Int16', 'Uint16', 'Int32', 'Uint32', 'Int64', 'Uint64', 'Int128', 'Uint128', 'Bool', 'Char', 'Float16', 'Float32', 'Float64', 'Array', 'Vector', 'Matrix', 'String', 'UTF8String', 'ASCIIString', 'error', 'warn', 'info', '@printf'];1415//var stringPrefixes = new RegExp("^[br]?('|\")")16var stringPrefixes = /^[br]?('|"{3}|")/;17var keywords = wordRegexp(keywordList);18var builtins = wordRegexp(builtinList);19var openers = wordRegexp(blockOpeners);20var closers = wordRegexp(blockClosers);21var macro = /@[_A-Za-z][_A-Za-z0-9]*!*/;22var indentInfo = null;2324function in_array(state) {25var ch = cur_scope(state);26if(ch=="[" || ch=="{") {27return true;28}29else {30return false;31}32}3334function cur_scope(state) {35if(state.scopes.length==0) {36return null;37}38return state.scopes[state.scopes.length - 1];39}4041// tokenizers42function tokenBase(stream, state) {43// Handle scope changes44var leaving_expr = state.leaving_expr;45state.leaving_expr = false;46if(leaving_expr) {47if(stream.match(/^'+/)) {48return 'operator';49}50if(stream.match("...")) {51return 'operator';52}53}5455if (stream.eatSpace()) {56return null;57}5859var ch = stream.peek();60// Handle Comments61if (ch === '#') {62stream.skipToEnd();63return 'comment';64}65if(ch==='[') {66state.scopes.push("[");67}6869if(ch==='{') {70state.scopes.push("{");71}7273var scope=cur_scope(state);7475if(scope==='[' && ch===']') {76state.scopes.pop();77state.leaving_expr=true;78}7980if(scope==='{' && ch==='}') {81state.scopes.pop();82state.leaving_expr=true;83}8485var match;86if(match=stream.match(openers, false)) {87state.scopes.push(match);88}8990if(!in_array(state) && stream.match(closers, false)) {91state.scopes.pop();92}9394if(in_array(state)) {95if(stream.match("end")) {96return 'number';97}9899}100if(stream.match("=>")) {101return 'operator';102}103// Handle Number Literals104if (stream.match(/^[0-9\.]/, false)) {105var imMatcher = RegExp(/^im\b/);106var floatLiteral = false;107// Floats108if (stream.match(/^\d*\.\d+([ef][\+\-]?\d+)?/i)) { floatLiteral = true; }109if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }110if (stream.match(/^\.\d+/)) { floatLiteral = true; }111if (floatLiteral) {112// Float literals may be "imaginary"113stream.match(imMatcher);114return 'number';115}116// Integers117var intLiteral = false;118// Hex119if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }120// Binary121if (stream.match(/^0b[01]+/i)) { intLiteral = true; }122// Octal123if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }124// Decimal125if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {126// Decimal literals may be "imaginary"127stream.eat(/J/i);128// TODO - Can you have imaginary longs?129intLiteral = true;130}131// Zero by itself with no other piece of number.132if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }133if (intLiteral) {134// Integer literals may be "long"135stream.match(imMatcher);136return 'number';137}138}139140// Handle Strings141if (stream.match(stringPrefixes)) {142state.tokenize = tokenStringFactory(stream.current());143return state.tokenize(stream, state);144}145146// Handle operators and Delimiters147if (stream.match(operators)) {148return 'operator';149}150151if (stream.match(delimiters)) {152return null;153}154155if (stream.match(keywords)) {156return 'keyword';157}158159if (stream.match(builtins)) {160return 'builtin';161}162163if (stream.match(macro)) {164return 'meta';165}166167if (stream.match(identifiers)) {168state.leaving_expr=true;169return 'variable';170}171// Handle non-detected items172stream.next();173return ERRORCLASS;174}175176function tokenStringFactory(delimiter) {177while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {178delimiter = delimiter.substr(1);179}180var singleline = delimiter.length == 1;181var OUTCLASS = 'string';182183function tokenString(stream, state) {184while (!stream.eol()) {185stream.eatWhile(/[^'"\\]/);186if (stream.eat('\\')) {187stream.next();188if (singleline && stream.eol()) {189return OUTCLASS;190}191} else if (stream.match(delimiter)) {192state.tokenize = tokenBase;193return OUTCLASS;194} else {195stream.eat(/['"]/);196}197}198if (singleline) {199if (parserConf.singleLineStringErrors) {200return ERRORCLASS;201} else {202state.tokenize = tokenBase;203}204}205return OUTCLASS;206}207tokenString.isString = true;208return tokenString;209}210211function tokenLexer(stream, state) {212indentInfo = null;213var style = state.tokenize(stream, state);214var current = stream.current();215216// Handle '.' connected identifiers217if (current === '.') {218style = stream.match(identifiers, false) ? null : ERRORCLASS;219if (style === null && state.lastStyle === 'meta') {220// Apply 'meta' style to '.' connected identifiers when221// appropriate.222style = 'meta';223}224return style;225}226227return style;228}229230var external = {231startState: function() {232return {233tokenize: tokenBase,234scopes: [],235leaving_expr: false236};237},238239token: function(stream, state) {240var style = tokenLexer(stream, state);241state.lastStyle = style;242return style;243},244245indent: function(state, textAfter) {246var delta = 0;247if(textAfter=="end" || textAfter=="]" || textAfter=="}" || textAfter=="else" || textAfter=="elseif" || textAfter=="catch" || textAfter=="finally") {248delta = -1;249}250return (state.scopes.length + delta) * 2;251},252253lineComment: "#",254fold: "indent",255electricChars: "edlsifyh]}"256};257return external;258});259260261CodeMirror.defineMIME("text/x-julia", "julia");262263264