物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
6.3 KiB

function k(i){return new RegExp("^(("+i.join(")|(")+"))\\b")}var R=k(["and","or","not","is"]),T=["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","False","True"],L=["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 c(i){return i.scopes[i.scopes.length-1]}function E(i){for(var u="error",O=i.delimiters||i.singleDelimiters||/^[\(\)\[\]\{\}@,:`=;\.\\]/,d=[i.singleOperators,i.doubleOperators,i.doubleDelimiters,i.tripleDelimiters,i.operators||/^([-+*/%\/&|^]=?|[<>=]+|\/\/=?|\*\*=?|!=|[~!@]|\.\.\.)/],m=0;m<d.length;m++)d[m]||d.splice(m--,1);var y=i.hangingIndent,f=T,p=L;i.extra_keywords!=null&&(f=f.concat(i.extra_keywords)),i.extra_builtins!=null&&(p=p.concat(i.extra_builtins));var v=!(i.version&&Number(i.version)<3);if(v){var h=i.identifiers||/^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;f=f.concat(["nonlocal","None","aiter","anext","async","await","breakpoint","match","case"]),p=p.concat(["ascii","bytes","exec","print"]);var x=new RegExp(`^(([rbuf]|(br)|(rb)|(fr)|(rf))?('{3}|"{3}|['"]))`,"i")}else{var h=i.identifiers||/^[_A-Za-z][_A-Za-z0-9]*/;f=f.concat(["exec","print"]),p=p.concat(["apply","basestring","buffer","cmp","coerce","execfile","file","intern","long","raw_input","reduce","reload","unichr","unicode","xrange","None"]);var x=new RegExp(`^(([rubf]|(ur)|(br))?('{3}|"{3}|['"]))`,"i")}var S=k(f),A=k(p);function z(e,t){var n=e.sol()&&t.lastToken!="\\";if(n&&(t.indent=e.indentation()),n&&c(t).type=="py"){var r=c(t).offset;if(e.eatSpace()){var a=e.indentation();return a>r?_(e,t):a<r&&w(e,t)&&e.peek()!="#"&&(t.errorToken=!0),null}else{var s=g(e,t);return r>0&&w(e,t)&&(s+=" "+u),s}}return g(e,t)}function g(e,t,n){if(e.eatSpace())return null;if(!n&&e.match(/^#.*/))return"comment";if(e.match(/^[0-9\.]/,!1)){var r=!1;if(e.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)&&(r=!0),e.match(/^[\d_]+\.\d*/)&&(r=!0),e.match(/^\.\d+/)&&(r=!0),r)return e.eat(/J/i),"number";var a=!1;if(e.match(/^0x[0-9a-f_]+/i)&&(a=!0),e.match(/^0b[01_]+/i)&&(a=!0),e.match(/^0o[0-7_]+/i)&&(a=!0),e.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)&&(e.eat(/J/i),a=!0),e.match(/^0(?![\dx])/i)&&(a=!0),a)return e.eat(/L/i),"number"}if(e.match(x)){var s=e.current().toLowerCase().indexOf("f")!==-1;return s?(t.tokenize=D(e.current(),t.tokenize),t.tokenize(e,t)):(t.tokenize=I(e.current(),t.tokenize),t.tokenize(e,t))}for(var o=0;o<d.length;o++)if(e.match(d[o]))return"operator";return e.match(O)?"punctuation":t.lastToken=="."&&e.match(h)?"property":e.match(S)||e.match(R)?"keyword":e.match(A)?"builtin":e.match(/^(self|cls)\b/)?"self":e.match(h)?t.lastToken=="def"||t.lastToken=="class"?"def":"variable":(e.next(),n?null:u)}function D(e,t){for(;"rubf".indexOf(e.charAt(0).toLowerCase())>=0;)e=e.substr(1);var n=e.length==1,r="string";function a(o){return function(l,b){var F=g(l,b,!0);return F=="punctuation"&&(l.current()=="{"?b.tokenize=a(o+1):l.current()=="}"&&(o>1?b.tokenize=a(o-1):b.tokenize=s)),F}}function s(o,l){for(;!o.eol();)if(o.eatWhile(/[^'"\{\}\\]/),o.eat("\\")){if(o.next(),n&&o.eol())return r}else{if(o.match(e))return l.tokenize=t,r;if(o.match("{{"))return r;if(o.match("{",!1))return l.tokenize=a(0),o.current()?r:l.tokenize(o,l);if(o.match("}}"))return r;if(o.match("}"))return u;o.eat(/['"]/)}if(n){if(i.singleLineStringErrors)return u;l.tokenize=t}return r}return s.isString=!0,s}function I(e,t){for(;"rubf".indexOf(e.charAt(0).toLowerCase())>=0;)e=e.substr(1);var n=e.length==1,r="string";function a(s,o){for(;!s.eol();)if(s.eatWhile(/[^'"\\]/),s.eat("\\")){if(s.next(),n&&s.eol())return r}else{if(s.match(e))return o.tokenize=t,r;s.eat(/['"]/)}if(n){if(i.singleLineStringErrors)return u;o.tokenize=t}return r}return a.isString=!0,a}function _(e,t){for(;c(t).type!="py";)t.scopes.pop();t.scopes.push({offset:c(t).offset+e.indentUnit,type:"py",align:null})}function N(e,t,n){var r=e.match(/^[\s\[\{\(]*(?:#|$)/,!1)?null:e.column()+1;t.scopes.push({offset:t.indent+(y||e.indentUnit),type:n,align:r})}function w(e,t){for(var n=e.indentation();t.scopes.length>1&&c(t).offset>n;){if(c(t).type!="py")return!0;t.scopes.pop()}return c(t).offset!=n}function Z(e,t){e.sol()&&(t.beginningOfLine=!0,t.dedent=!1);var n=t.tokenize(e,t),r=e.current();if(t.beginningOfLine&&r=="@")return e.match(h,!1)?"meta":v?"operator":u;if(/\S/.test(r)&&(t.beginningOfLine=!1),(n=="variable"||n=="builtin")&&t.lastToken=="meta"&&(n="meta"),(r=="pass"||r=="return")&&(t.dedent=!0),r=="lambda"&&(t.lambda=!0),r==":"&&!t.lambda&&c(t).type=="py"&&e.match(/^\s*(?:#|$)/,!1)&&_(e,t),r.length==1&&!/string|comment/.test(n)){var a="[({".indexOf(r);if(a!=-1&&N(e,t,"])}".slice(a,a+1)),a="])}".indexOf(r),a!=-1)if(c(t).type==r)t.indent=t.scopes.pop().offset-(y||e.indentUnit);else return u}return t.dedent&&e.eol()&&c(t).type=="py"&&t.scopes.length>1&&t.scopes.pop(),n}return{name:"python",startState:function(){return{tokenize:z,scopes:[{offset:0,type:"py",align:null}],indent:0,lastToken:null,lambda:!1,dedent:0}},token:function(e,t){var n=t.errorToken;n&&(t.errorToken=!1);var r=Z(e,t);return r&&r!="comment"&&(t.lastToken=r=="keyword"||r=="punctuation"?e.current():r),r=="punctuation"&&(r=null),e.eol()&&t.lambda&&(t.lambda=!1),n?u:r},indent:function(e,t,n){if(e.tokenize!=z)return e.tokenize.isString?null:0;var r=c(e),a=r.type==t.charAt(0)||r.type=="py"&&!e.dedent&&/^(else:|elif |except |finally:)/.test(t);return r.align!=null?r.align-(a?1:0):r.offset-(a?y||n.unit:0)},languageData:{autocomplete:T.concat(L).concat(["exec","print"]),indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/,commentTokens:{line:"#"},closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""']}}}}var U=function(i){return i.split(" ")};const C=E({}),$=E({extra_keywords:U("by cdef cimport cpdef ctypedef enum except extern gil include nogil property public readonly struct union DEF IF ELIF ELSE")});export{$ as cython,E as mkPython,C as python};