mirror of
https://github.com/TomHodson/tomhodson.github.com.git
synced 2025-06-26 10:01:18 +02:00
1 line
6.2 KiB
JavaScript
1 line
6.2 KiB
JavaScript
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(k){"use strict";function v(e){return new RegExp("^(("+e.join(")|(")+"))\\b")}var x=v(["and","or","not","is"]),_=["as","assert","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","lambda","pass","raise","return","try","while","with","yield","in"],z=["abs","all","any","bin","bool","bytearray","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip","__import__","NotImplemented","Ellipsis","__debug__"];function w(e){return e.scopes[e.scopes.length-1]}k.registerHelper("hintWords","python",_.concat(z)),k.defineMode("python",function(t,l){for(var c="error",a=l.delimiters||l.singleDelimiters||/^[\(\)\[\]\{\}@,:`=;\.\\]/,s=[l.singleOperators,l.doubleOperators,l.doubleDelimiters,l.tripleDelimiters,l.operators||/^([-+*/%\/&|^]=?|[<>=]+|\/\/=?|\*\*=?|!=|[~!@])/],e=0;e<s.length;e++)s[e]||s.splice(e--,1);var u=l.hangingIndent||t.indentUnit,n=_,r=z;null!=l.extra_keywords&&(n=n.concat(l.extra_keywords)),null!=l.extra_builtins&&(r=r.concat(l.extra_builtins));var f=!(l.version&&Number(l.version)<3);if(f){var p=l.identifiers||/^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;n=n.concat(["nonlocal","False","True","None","async","await"]),r=r.concat(["ascii","bytes","exec","print"]);var d=new RegExp("^(([rbuf]|(br)|(fr))?('{3}|\"{3}|['\"]))","i")}else{p=l.identifiers||/^[_A-Za-z][_A-Za-z0-9]*/;n=n.concat(["exec","print"]),r=r.concat(["apply","basestring","buffer","cmp","coerce","execfile","file","intern","long","raw_input","reduce","reload","unichr","unicode","xrange","False","True","None"]);d=new RegExp("^(([rubf]|(ur)|(br))?('{3}|\"{3}|['\"]))","i")}var m=v(n),h=v(r);function i(e,t){var n=e.sol()&&"\\"!=t.lastToken;if(n&&(t.indent=e.indentation()),n&&"py"==w(t).type){var r=w(t).offset;if(e.eatSpace()){var i=e.indentation();return r<i?y(t):i<r&&g(e,t)&&"#"!=e.peek()&&(t.errorToken=!0),null}var o=b(e,t);return 0<r&&g(e,t)&&(o+=" "+c),o}return b(e,t)}function b(e,t){if(e.eatSpace())return null;if(e.match(/^#.*/))return"comment";if(e.match(/^[0-9\.]/,!1)){var n=!1;if(e.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)&&(n=!0),e.match(/^[\d_]+\.\d*/)&&(n=!0),e.match(/^\.\d+/)&&(n=!0),n)return e.eat(/J/i),"number";var r=!1;if(e.match(/^0x[0-9a-f_]+/i)&&(r=!0),e.match(/^0b[01_]+/i)&&(r=!0),e.match(/^0o[0-7_]+/i)&&(r=!0),e.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)&&(e.eat(/J/i),r=!0),e.match(/^0(?![\dx])/i)&&(r=!0),r)return e.eat(/L/i),"number"}if(e.match(d)){var i=-1!==e.current().toLowerCase().indexOf("f");return t.tokenize=i?function(n,r){for(;0<="rubf".indexOf(n.charAt(0).toLowerCase());)n=n.substr(1);var i=1==n.length,o="string";function a(r){return function(e,t){var n=b(e,t);return"punctuation"==n&&("{"==e.current()?t.tokenize=a(r+1):"}"==e.current()&&(t.tokenize=1<r?a(r-1):s)),n}}function s(e,t){for(;!e.eol();)if(e.eatWhile(/[^'"\{\}\\]/),e.eat("\\")){if(e.next(),i&&e.eol())return o}else{if(e.match(n))return t.tokenize=r,o;if(e.match("{{"))return o;if(e.match("{",!1))return t.tokenize=a(0),e.current()?o:t.tokenize(e,t);if(e.match("}}"))return o;if(e.match("}"))return c;e.eat(/['"]/)}if(i){if(l.singleLineStringErrors)return c;t.tokenize=r}return o}return s.isString=!0,s}(e.current(),t.tokenize):function(n,r){for(;0<="rubf".indexOf(n.charAt(0).toLowerCase());)n=n.substr(1);var i=1==n.length,o="string";function e(e,t){for(;!e.eol();)if(e.eatWhile(/[^'"\\]/),e.eat("\\")){if(e.next(),i&&e.eol())return o}else{if(e.match(n))return t.tokenize=r,o;e.eat(/['"]/)}if(i){if(l.singleLineStringErrors)return c;t.tokenize=r}return o}return e.isString=!0,e}(e.current(),t.tokenize),t.tokenize(e,t)}for(var o=0;o<s.length;o++)if(e.match(s[o]))return"operator";return e.match(a)?"punctuation":"."==t.lastToken&&e.match(p)?"property":e.match(m)||e.match(x)?"keyword":e.match(h)?"builtin":e.match(/^(self|cls)\b/)?"variable-2":e.match(p)?"def"==t.lastToken||"class"==t.lastToken?"def":"variable":(e.next(),c)}function y(e){for(;"py"!=w(e).type;)e.scopes.pop();e.scopes.push({offset:w(e).offset+t.indentUnit,type:"py",align:null})}function g(e,t){for(var n=e.indentation();1<t.scopes.length&&w(t).offset>n;){if("py"!=w(t).type)return!0;t.scopes.pop()}return w(t).offset!=n}function o(e,t){e.sol()&&(t.beginningOfLine=!0);var n,r,i,o,a=t.tokenize(e,t),s=e.current();if(t.beginningOfLine&&"@"==s)return e.match(p,!1)?"meta":f?"operator":c;if(/\S/.test(s)&&(t.beginningOfLine=!1),"variable"!=a&&"builtin"!=a||"meta"!=t.lastToken||(a="meta"),"pass"!=s&&"return"!=s||(t.dedent+=1),"lambda"==s&&(t.lambda=!0),":"!=s||t.lambda||"py"!=w(t).type||y(t),1==s.length&&!/string|comment/.test(a)){var l="[({".indexOf(s);if(-1!=l&&(n=e,r=t,i="])}".slice(l,l+1),o=n.match(/^([\s\[\{\(]|#.*)*$/,!1)?null:n.column()+1,r.scopes.push({offset:r.indent+u,type:i,align:o})),-1!=(l="])}".indexOf(s))){if(w(t).type!=s)return c;t.indent=t.scopes.pop().offset-u}}return 0<t.dedent&&e.eol()&&"py"==w(t).type&&(1<t.scopes.length&&t.scopes.pop(),t.dedent-=1),a}return{startState:function(e){return{tokenize:i,scopes:[{offset:e||0,type:"py",align:null}],indent:e||0,lastToken:null,lambda:!1,dedent:0}},token:function(e,t){var n=t.errorToken;n&&(t.errorToken=!1);var r=o(e,t);return r&&"comment"!=r&&(t.lastToken="keyword"==r||"punctuation"==r?e.current():r),"punctuation"==r&&(r=null),e.eol()&&t.lambda&&(t.lambda=!1),n?r+" "+c:r},indent:function(e,t){if(e.tokenize!=i)return e.tokenize.isString?k.Pass:0;var n=w(e),r=n.type==t.charAt(0);return null!=n.align?n.align-(r?1:0):n.offset-(r?u:0)},electricInput:/^\s*[\}\]\)]$/,closeBrackets:{triples:"'\""},lineComment:"#",fold:"indent"}}),k.defineMIME("text/x-python","python");var e;k.defineMIME("text/x-cython",{name:"python",extra_keywords:(e="by cdef cimport cpdef ctypedef enum except extern gil include nogil property public readonly struct union DEF IF ELIF ELSE",e.split(" "))})}); |