|
|
function c(t){for(var e={},n=0;n<t.length;n++)e[t[n]]=!0;return e}var f=c(["_","var","let","actor","class","enum","extension","import","protocol","struct","func","typealias","associatedtype","open","public","internal","fileprivate","private","deinit","init","new","override","self","subscript","super","convenience","dynamic","final","indirect","lazy","required","static","unowned","unowned(safe)","unowned(unsafe)","weak","as","is","break","case","continue","default","else","fallthrough","for","guard","if","in","repeat","switch","where","while","defer","return","inout","mutating","nonmutating","isolated","nonisolated","catch","do","rethrows","throw","throws","async","await","try","didSet","get","set","willSet","assignment","associativity","infix","left","none","operator","postfix","precedence","precedencegroup","prefix","right","Any","AnyObject","Type","dynamicType","Self","Protocol","__COLUMN__","__FILE__","__FUNCTION__","__LINE__"]),l=c(["var","let","actor","class","enum","extension","import","protocol","struct","func","typealias","associatedtype","for"]),p=c(["true","false","nil","self","super","_"]),d=c(["Array","Bool","Character","Dictionary","Double","Float","Int","Int8","Int16","Int32","Int64","Never","Optional","Set","String","UInt8","UInt16","UInt32","UInt64","Void"]),h="+-/*%=|&<>~^?!",m=":;,.(){}[]",v=/^\-?0b[01][01_]*/,_=/^\-?0o[0-7][0-7_]*/,k=/^\-?0x[\dA-Fa-f][\dA-Fa-f_]*(?:(?:\.[\dA-Fa-f][\dA-Fa-f_]*)?[Pp]\-?\d[\d_]*)?/,x=/^\-?\d[\d_]*(?:\.\d[\d_]*)?(?:[Ee]\-?\d[\d_]*)?/,y=/^\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1/,g=/^\.(?:\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1)/,w=/^\#[A-Za-z]+/,z=/^@(?:\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1)/;function s(t,e,n){if(t.sol()&&(e.indented=t.indentation()),t.eatSpace())return null;var i=t.peek();if(i=="/"){if(t.match("//"))return t.skipToEnd(),"comment";if(t.match("/*"))return e.tokenize.push(u),u(t,e)}if(t.match(w))return"builtin";if(t.match(z))return"attribute";if(t.match(v)||t.match(_)||t.match(k)||t.match(x))return"number";if(t.match(g))return"property";if(h.indexOf(i)>-1)return t.next(),"operator";if(m.indexOf(i)>-1)return t.next(),t.match(".."),"punctuation";var r;if(r=t.match(/("""|"|')/)){var a=A.bind(null,r[0]);return e.tokenize.push(a),a(t,e)}if(t.match(y)){var o=t.current();return d.hasOwnProperty(o)?"type":p.hasOwnProperty(o)?"atom":f.hasOwnProperty(o)?(l.hasOwnProperty(o)&&(e.prev="define"),"keyword"):n=="define"?"def":"variable"}return t.next(),null}function b(){var t=0;return function(e,n,i){var r=s(e,n,i);if(r=="punctuation"){if(e.current()=="(")++t;else if(e.current()==")"){if(t==0)return e.backUp(1),n.tokenize.pop(),n.tokenize[n.tokenize.length-1](e,n);--t}}return r}}function A(t,e,n){for(var i=t.length==1,r,a=!1;r=e.peek();)if(a){if(e.next(),r=="(")return n.tokenize.push(b()),"string";a=!1}else{if(e.match(t))return n.tokenize.pop(),"string";e.next(),a=r=="\\"}return i&&n.tokenize.pop(),"string"}function u(t,e){for(var n;n=t.next();)if(n==="/"&&t.eat("*"))e.tokenize.push(u);else if(n==="*"&&t.eat("/")){e.tokenize.pop();break}return"comment"}function I(t,e,n){this.prev=t,this.align=e,this.indented=n}function O(t,e){var n=e.match(/^\s*($|\/[\/\*]|[)}\]])/,!1)?null:e.column()+1;t.context=new I(t.context,n,t.indented)}function S(t){t.context&&(t.indented=t.context.indented,t.context=t.context.prev)}const $={name:"swift",startState:function(){return{prev:null,context:null,indented:0,tokenize:[]}},token:function(t,e){var n=e.prev;e.prev=null;var i=e.tokenize[e.tokenize.length-1]||s,r=i(t,e,n);if(!r||r=="comment"?e.prev=n:e.prev||(e.prev=r),r=="punctuation"){var a=/[\(\[\{]|([\]\)\}])/.exec(t.current());a&&(a[1]?S:O)(e,t)}return r},indent:function(t,e,n){var i=t.context;if(!i)return 0;var r=/^[\]\}\)]/.test(e);return i.align!=null?i.align-(r?1:0):i.indented+(r?0:n.unit)},languageData:{indentOnInput:/^\s*[\)\}\]]$/,commentTokens:{line:"//",block:{open:"/*",close:"*/"}},closeBrackets:{brackets:["(","[","{","'",'"',"`"]}}};export{$ as swift};
|