forgeplus-react/ui/js/codemirror/mode/julia/julia.min.js

3 lines
5.7 KiB
JavaScript

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/5/LICENSE
(function(f){"object"==typeof exports&&"object"==typeof module?f(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],f):f(CodeMirror)})(function(f){f.defineMode("julia",function(n,g){function e(b,a,c){"undefined"===typeof c&&(c="");"undefined"===typeof a&&(a="\\b");return new RegExp("^"+c+"(("+b.join(")|(")+"))"+a)}function k(b,a){"undefined"===typeof a&&(a=0);return b.scopes.length<=a?null:b.scopes[b.scopes.length-(a+1)]}function h(b,a){if(b.match("#\x3d",!1))return a.tokenize=p,a.tokenize(b,a);var c=a.leavingExpr;b.sol()&&(c=!1);a.leavingExpr=!1;if(c&&b.match(/^'+/))return"operator";if(b.match(/\.{4,}/))return"error";if(b.match(/\.{1,3}/))return"operator";if(b.eatSpace())return null;var d=b.peek();if("#"===d)return b.skipToEnd(),"comment";"["===d&&(a.scopes.push("["),a.nestedArrays++);"("===d&&(a.scopes.push("("),a.nestedGenerators++);if(0<a.nestedArrays&&"]"===d){for(;a.scopes.length&&"["!==k(a);)a.scopes.pop();a.scopes.pop();a.nestedArrays--;a.leavingExpr=!0}if(0<a.nestedGenerators&&")"===d){for(;a.scopes.length&&"("!==k(a);)a.scopes.pop();a.scopes.pop();a.nestedGenerators--;a.leavingExpr=!0}if(0<a.nestedArrays){if("end"==a.lastToken&&b.match(":"))return"operator";if(b.match("end"))return"number"}var e;(e=b.match(q,!1))&&a.scopes.push(e[0]);b.match(r,!1)&&a.scopes.pop();if(b.match(/^::(?![:\$])/))return a.tokenize=t,a.tokenize(b,a);if(!c&&(b.match(u)||b.match(v)))return"builtin";if(b.match(w))return"operator";if(b.match(/^\.?\d/,!1)&&(c=RegExp(/^im\b/),d=!1,b.match(/^0x\.[0-9a-f_]+p[\+\-]?[_\d]+/i)&&(d=!0),b.match(/^0x[0-9a-f_]+/i)&&(d=!0),b.match(/^0b[01_]+/i)&&(d=!0),b.match(/^0o[0-7_]+/i)&&(d=!0),b.match(/^(?:(?:\d[_\d]*)?\.(?!\.)(?:\d[_\d]*)?|\d[_\d]*\.(?!\.)(?:\d[_\d]*))?([Eef][\+\-]?[_\d]+)?/i)&&(d=!0),b.match(/^\d[_\d]*(e[\+\-]?\d+)?/i)&&(d=!0),d))return b.match(c),a.leavingExpr=!0,"number";if(b.match("'"))return a.tokenize=x,a.tokenize(b,a);if(b.match(y))return a.tokenize=z(b.current()),a.tokenize(b,a);if(b.match(A)||b.match(B))return"meta";if(b.match(C))return null;if(b.match(D))return"keyword";if(b.match(E))return"builtin";c=a.isDefinition||"function"==a.lastToken||"macro"==a.lastToken||"type"==a.lastToken||"struct"==a.lastToken||"immutable"==a.lastToken;if(b.match(F)){if(c){if("."===b.peek())return a.isDefinition=!0,"variable";a.isDefinition=!1;return"def"}a.leavingExpr=!0;return"variable"}b.next();return"error"}function t(b,a){b.match(/.*?(?=[,;{}()=\s]|$)/);b.match("{")?a.nestedParameters++:b.match("}")&&0<a.nestedParameters&&a.nestedParameters--;0<a.nestedParameters?b.match(/.*?(?={|})/)||b.next():0==a.nestedParameters&&(a.tokenize=h);return"builtin"}function p(b,a){b.match("#\x3d")&&a.nestedComments++;b.match(/.*?(?=(#=|=#))/)||b.skipToEnd();b.match("\x3d#")&&(a.nestedComments--,0==a.nestedComments&&(a.tokenize=h));return"comment"}function x(b,a){var c=!1,d;if(b.match(G))c=!0;else if(d=b.match(/\\u([a-f0-9]{1,4})(?=')/i)){if(d=parseInt(d[1],16),55295>=d||57344<=d)c=!0,b.next()}else if(d=b.match(/\\U([A-Fa-f0-9]{5,8})(?=')/))d=parseInt(d[1],16),1114111>=d&&(c=!0,b.next());if(c)return a.leavingExpr=!0,a.tokenize=h,"string";b.match(/^[^']+(?=')/)||b.skipToEnd();b.match("'")&&(a.tokenize=h);return"error"}function z(b){'"""'===b.substr(-3)?b='"""':'"'===b.substr(-1)&&(b='"');return function(a,c){if(a.eat("\\"))a.next();else{if(a.match(b))return c.tokenize=h,c.leavingExpr=!0,"string";a.eat(/[`"]/)}a.eatWhile(/[^\\`"]/);return"string"}}var l="[\x3c\x3e]: [\x3c\x3e\x3d]\x3d \x3c\x3c\x3d? \x3e\x3e\x3e?\x3d? \x3d\x3e --?\x3e \x3c--[-\x3e]? \\/\\/ \\.{2,3} [\\.\\\\%*+\\-\x3c\x3e!\\/^|\x26]\x3d? \\? \\$ ~ :".split(" "),w=g.operators||e("[\x3c\x3e]: [\x3c\x3e\x3d]\x3d [!\x3d]\x3d\x3d \x3c\x3c\x3d? \x3e\x3e\x3e?\x3d? \x3d\x3e? --?\x3e \x3c--[-\x3e]? \\/\\/ [\\\\%*+\\-\x3c\x3e!\\/^|\x26\\u00F7\\u22BB]\x3d? \\? \\$ ~ : \\u00D7 \\u2208 \\u2209 \\u220B \\u220C \\u2218 \\u221A \\u221B \\u2229 \\u222A \\u2260 \\u2264 \\u2265 \\u2286 \\u2288 \\u228A \\u22C5 \\b(in|isa)\\b(?!.?\\()".split(" "),""),C=g.delimiters||/^[;,()[\]{}]/,F=g.identifiers||/^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/,G=e(["\\\\[0-7]{1,3}","\\\\x[A-Fa-f0-9]{1,2}","\\\\[abefnrtv0%?'\"\\\\]","([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])"],"'");g="if else elseif while for begin let end do try catch finally return break continue global local const export import importall using function where macro module baremodule struct type mutable immutable quote typealias abstract primitive bitstype".split(" ");var m=["true","false","nothing","NaN","Inf"];f.registerHelper("hintWords","julia",g.concat(m));var q=e("begin function type struct immutable let macro for while quote if else elseif try finally catch do".split(" ")),r=e(["end","else","elseif","catch","finally"]),D=e(g),E=e(m),A=/^@[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/,u=/^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/,y=/^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/,B=e(l,"","@"),v=e(l,"",":");return{startState:function(){return{tokenize:h,scopes:[],lastToken:null,leavingExpr:!1,isDefinition:!1,nestedArrays:0,nestedComments:0,nestedGenerators:0,nestedParameters:0,firstParenPos:-1}},token:function(b,a){var c=a.tokenize(b,a);(b=b.current())&&c&&(a.lastToken=b);return c},indent:function(b,a){var c=0;if("]"===a||")"===a||/^end\b/.test(a)||/^else/.test(a)||/^catch\b/.test(a)||/^elseif\b/.test(a)||/^finally/.test(a))c=-1;return(b.scopes.length+c)*n.indentUnit},electricInput:/\b(end|else|catch|finally)\b/,blockCommentStart:"#\x3d",blockCommentEnd:"\x3d#",lineComment:"#",closeBrackets:'()[]{}""',fold:"indent"}});f.defineMIME("text/x-julia","julia")});