1 line
5.1 KiB
JavaScript
1 line
5.1 KiB
JavaScript
function e(e,t,n){return n===void 0&&(n=``),t===void 0&&(t=`\\b`),RegExp(`^`+n+`((`+e.join(`)|(`)+`))`+t)}var t=`\\\\[0-7]{1,3}`,n=`\\\\x[A-Fa-f0-9]{1,2}`,r=`\\\\[abefnrtv0%?'"\\\\]`,i=`([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])`,a=[`[<>]:`,`[<>=]=`,`<<=?`,`>>>?=?`,`=>`,`--?>`,`<--[->]?`,`\\/\\/`,`\\.{2,3}`,`[\\.\\\\%*+\\-<>!\\/^|&]=?`,`\\?`,`\\$`,`~`,`:`],o=e(`[<>]:,[<>=]=,[!=]==,<<=?,>>>?=?,=>?,--?>,<--[->]?,\\/\\/,[\\\\%*+\\-<>!\\/^|&\\u00F7\\u22BB]=?,\\?,\\$,~,:,\\u00D7,\\u2208,\\u2209,\\u220B,\\u220C,\\u2218,\\u221A,\\u221B,\\u2229,\\u222A,\\u2260,\\u2264,\\u2265,\\u2286,\\u2288,\\u228A,\\u22C5,\\b(in|isa)\\b(?!.?\\()`.split(`,`),``),s=/^[;,()[\]{}]/,c=/^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/,l=e([t,n,r,i],`'`),u=[`begin`,`function`,`type`,`struct`,`immutable`,`let`,`macro`,`for`,`while`,`quote`,`if`,`else`,`elseif`,`try`,`finally`,`catch`,`do`],d=[`end`,`else`,`elseif`,`catch`,`finally`],f=`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(`.`),p=[`true`,`false`,`nothing`,`NaN`,`Inf`],m=e(u),h=e(d),g=e(f),_=e(p),v=/^@[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/,y=/^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/,b=/^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/,x=e(a,``,`@`),S=e(a,``,`:`);function C(e){return e.nestedArrays>0}function w(e){return e.nestedGenerators>0}function T(e,t){return t===void 0&&(t=0),e.scopes.length<=t?null:e.scopes[e.scopes.length-(t+1)]}function E(e,t){if(e.match(`#=`,!1))return t.tokenize=O,t.tokenize(e,t);var n=t.leavingExpr;if(e.sol()&&(n=!1),t.leavingExpr=!1,n&&e.match(/^'+/))return`operator`;if(e.match(/\.{4,}/))return`error`;if(e.match(/\.{1,3}/))return`operator`;if(e.eatSpace())return null;var r=e.peek();if(r===`#`)return e.skipToEnd(),`comment`;if(r===`[`&&(t.scopes.push(`[`),t.nestedArrays++),r===`(`&&(t.scopes.push(`(`),t.nestedGenerators++),C(t)&&r===`]`){for(;t.scopes.length&&T(t)!==`[`;)t.scopes.pop();t.scopes.pop(),t.nestedArrays--,t.leavingExpr=!0}if(w(t)&&r===`)`){for(;t.scopes.length&&T(t)!==`(`;)t.scopes.pop();t.scopes.pop(),t.nestedGenerators--,t.leavingExpr=!0}if(C(t)){if(t.lastToken==`end`&&e.match(`:`))return`operator`;if(e.match(`end`))return`number`}var i;if((i=e.match(m,!1))&&t.scopes.push(i[0]),e.match(h,!1)&&t.scopes.pop(),e.match(/^::(?![:\$])/))return t.tokenize=D,t.tokenize(e,t);if(!n&&(e.match(y)||e.match(S)))return`builtin`;if(e.match(o))return`operator`;if(e.match(/^\.?\d/,!1)){var a=RegExp(/^im\b/),l=!1;if(e.match(/^0x\.[0-9a-f_]+p[\+\-]?[_\d]+/i)&&(l=!0),e.match(/^0x[0-9a-f_]+/i)&&(l=!0),e.match(/^0b[01_]+/i)&&(l=!0),e.match(/^0o[0-7_]+/i)&&(l=!0),e.match(/^(?:(?:\d[_\d]*)?\.(?!\.)(?:\d[_\d]*)?|\d[_\d]*\.(?!\.)(?:\d[_\d]*))?([Eef][\+\-]?[_\d]+)?/i)&&(l=!0),e.match(/^\d[_\d]*(e[\+\-]?\d+)?/i)&&(l=!0),l)return e.match(a),t.leavingExpr=!0,`number`}if(e.match(`'`))return t.tokenize=k,t.tokenize(e,t);if(e.match(b))return t.tokenize=A(e.current()),t.tokenize(e,t);if(e.match(v)||e.match(x))return`meta`;if(e.match(s))return null;if(e.match(g))return`keyword`;if(e.match(_))return`builtin`;var u=t.isDefinition||t.lastToken==`function`||t.lastToken==`macro`||t.lastToken==`type`||t.lastToken==`struct`||t.lastToken==`immutable`;return e.match(c)?u?e.peek()===`.`?(t.isDefinition=!0,`variable`):(t.isDefinition=!1,`def`):(t.leavingExpr=!0,`variable`):(e.next(),`error`)}function D(e,t){return e.match(/.*?(?=[,;{}()=\s]|$)/),e.match(`{`)?t.nestedParameters++:e.match(`}`)&&t.nestedParameters>0&&t.nestedParameters--,t.nestedParameters>0?e.match(/.*?(?={|})/)||e.next():t.nestedParameters==0&&(t.tokenize=E),`builtin`}function O(e,t){return e.match(`#=`)&&t.nestedComments++,e.match(/.*?(?=(#=|=#))/)||e.skipToEnd(),e.match(`=#`)&&(t.nestedComments--,t.nestedComments==0&&(t.tokenize=E)),`comment`}function k(e,t){var n=!1,r;if(e.match(l))n=!0;else if(r=e.match(/\\u([a-f0-9]{1,4})(?=')/i)){var i=parseInt(r[1],16);(i<=55295||i>=57344)&&(n=!0,e.next())}else if(r=e.match(/\\U([A-Fa-f0-9]{5,8})(?=')/)){var i=parseInt(r[1],16);i<=1114111&&(n=!0,e.next())}return n?(t.leavingExpr=!0,t.tokenize=E,`string`):(e.match(/^[^']+(?=')/)||e.skipToEnd(),e.match(`'`)&&(t.tokenize=E),`error`)}function A(e){e.substr(-3)===`"""`?e=`"""`:e.substr(-1)===`"`&&(e=`"`);function t(t,n){if(t.eat(`\\`))t.next();else if(t.match(e))return n.tokenize=E,n.leavingExpr=!0,`string`;else t.eat(/[`"]/);return t.eatWhile(/[^\\`"]/),`string`}return t}var j={name:`julia`,startState:function(){return{tokenize:E,scopes:[],lastToken:null,leavingExpr:!1,isDefinition:!1,nestedArrays:0,nestedComments:0,nestedGenerators:0,nestedParameters:0,firstParenPos:-1}},token:function(e,t){var n=t.tokenize(e,t),r=e.current();return r&&n&&(t.lastToken=r),n},indent:function(e,t,n){var r=0;return(t===`]`||t===`)`||/^end\b/.test(t)||/^else/.test(t)||/^catch\b/.test(t)||/^elseif\b/.test(t)||/^finally/.test(t))&&(r=-1),(e.scopes.length+r)*n.unit},languageData:{indentOnInput:/^\s*(end|else|catch|finally)\b$/,commentTokens:{line:`#`,block:{open:`#=`,close:`=#`}},closeBrackets:{brackets:[`(`,`[`,`{`,`"`]},autocomplete:f.concat(p)}};export{j as julia}; |