2022-04-11 06:26:22 +02:00
|
|
|
/*! `swift` grammar compiled for Highlight.js 11.5.1 */
|
2021-10-18 07:02:03 +02:00
|
|
|
(()=>{var e=(()=>{"use strict";function e(e){
|
2021-06-08 07:40:19 +02:00
|
|
|
return e?"string"==typeof e?e:e.source:null}function a(e){return t("(?=",e,")")}
|
2021-10-18 07:02:03 +02:00
|
|
|
function t(...a){return a.map((a=>e(a))).join("")}function n(...a){const t=(e=>{
|
|
|
|
const a=e[e.length-1]
|
2021-06-08 07:40:19 +02:00
|
|
|
;return"object"==typeof a&&a.constructor===Object?(e.splice(e.length-1,1),a):{}
|
2021-10-18 07:02:03 +02:00
|
|
|
})(a);return"("+(t.capture?"":"?:")+a.map((a=>e(a))).join("|")+")"}
|
2021-08-02 06:42:23 +02:00
|
|
|
const i=e=>t(/\b/,e,/\w$/.test(e)?/\b/:/\B/),s=["Protocol","Type"].map(i),u=["init","self"].map(i),c=["Any","Self"],r=["actor","associatedtype","async","await",/as\?/,/as!/,"as","break","case","catch","class","continue","convenience","default","defer","deinit","didSet","do","dynamic","else","enum","extension","fallthrough",/fileprivate\(set\)/,"fileprivate","final","for","func","get","guard","if","import","indirect","infix",/init\?/,/init!/,"inout",/internal\(set\)/,"internal","in","is","isolated","nonisolated","lazy","let","mutating","nonmutating",/open\(set\)/,"open","operator","optional","override","postfix","precedencegroup","prefix",/private\(set\)/,"private","protocol",/public\(set\)/,"public","repeat","required","rethrows","return","set","some","static","struct","subscript","super","switch","throws","throw",/try\?/,/try!/,"try","typealias",/unowned\(safe\)/,/unowned\(unsafe\)/,"unowned","var","weak","where","while","willSet"],o=["false","nil","true"],l=["assignment","associativity","higherThan","left","lowerThan","none","right"],m=["#colorLiteral","#column","#dsohandle","#else","#elseif","#endif","#error","#file","#fileID","#fileLiteral","#filePath","#function","#if","#imageLiteral","#keyPath","#line","#selector","#sourceLocation","#warn_unqualified_access","#warning"],p=["abs","all","any","assert","assertionFailure","debugPrint","dump","fatalError","getVaList","isKnownUniquelyReferenced","max","min","numericCast","pointwiseMax","pointwiseMin","precondition","preconditionFailure","print","readLine","repeatElement","sequence","stride","swap","swift_unboxFromSwiftValueWithType","transcode","type","unsafeBitCast","unsafeDowncast","withExtendedLifetime","withUnsafeMutablePointer","withUnsafePointer","withVaList","withoutActuallyEscaping","zip"],d=n(/[/=\-+!*%<>&|^~?]/,/[\u00A1-\u00A7]/,/[\u00A9\u00AB]/,/[\u00AC\u00AE]/,/[\u00B0\u00B1]/,/[\u00B6\u00BB\u00BF\u00D7\u00F7]/,/[\u2016-\u2017]/,/[\u2020-\u2027]/,/[\u2030-\u203E]/,/[\u2041-\u2053]/,/[\u2055-\u205E]/,/[\u2190-\u23FF]/,/[\u2500-\u2775]/,/[\u2794-\u2BFF]/,/[\u2E00-\u2E7F]/,/[\u3001-\u3003]/,/[\u3008-\u3020]/,/[\u3030]/),F=n(d,/[\u0300-\u036F]/,/[\u1DC0-\u1DFF]/,/[\u20D0-\u20FF]/,/[\uFE00-\uFE0F]/,/[\uFE20-\uFE2F]/),b=t(d,F,"*"),h=n(/[a-zA-Z_]/,/[\u00A8\u00AA\u00AD\u00AF\u00B2-\u00B5\u00B7-\u00BA]/,/[\u00BC-\u00BE\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]/,/[\u0100-\u02FF\u0370-\u167F\u1681-\u180D\u180F-\u1DBF]/,/[\u1E00-\u1FFF]/,/[\u200B-\u200D\u202A-\u202E\u203F-\u2040\u2054\u2060-\u206F]/,/[\u2070-\u20CF\u2100-\u218F\u2460-\u24FF\u2776-\u2793]/,/[\u2C00-\u2DFF\u2E80-\u2FFF]/,/[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,/[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,/[\uFE47-\uFEFE\uFF00-\uFFFD]/),f=n(h,/\d/,/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/),w=t(h,f,"*"),y=t(/[A-Z]/,f,"*"),g=["autoclosure",t(/convention\(/,n("swift","block","c"),/\)/),"discardableResult","dynamicCallable","dynamicMemberLookup","escaping","frozen","GKInspectable","IBAction","IBDesignable","IBInspectable","IBOutlet","IBSegueAction","inlinable","main","nonobjc","NSApplicationMain","NSCopying","NSManaged",t(/objc\(/,w,/\)/),"objc","objcMembers","propertyWrapper","requires_stored_property_inits","resultBuilder","testable","UIApplicationMain","unknown","usableFromInline"],E=["iOS","iOSApplicationExtension","macOS","macOSApplicationExtension","macCatalyst","macCatalystApplicationExtension","watchOS","watchOSApplicationExtension","tvOS","tvOSApplicationExtension","swift"]
|
|
|
|
;return e=>{const d={match:/\s+/,relevance:0},h=e.COMMENT("/\\*","\\*/",{
|
2021-06-08 07:40:19 +02:00
|
|
|
contains:["self"]}),v=[e.C_LINE_COMMENT_MODE,h],A={match:[/\./,n(...s,...u)],
|
|
|
|
className:{2:"keyword"}},N={match:t(/\./,n(...r)),relevance:0
|
|
|
|
},C=r.filter((e=>"string"==typeof e)).concat(["_|0"]),D={variants:[{
|
|
|
|
className:"keyword",
|
|
|
|
match:n(...r.filter((e=>"string"!=typeof e)).concat(c).map(i),...u)}]},k={
|
|
|
|
$pattern:n(/\b\w+/,/#\w+/),keyword:C.concat(m),literal:o},B=[A,N,D],_=[{
|
|
|
|
match:t(/\./,n(...p)),relevance:0},{className:"built_in",
|
|
|
|
match:t(/\b/,n(...p),/(?=\()/)}],S={match:/->/,relevance:0},M=[S,{
|
2021-08-02 06:42:23 +02:00
|
|
|
className:"operator",relevance:0,variants:[{match:b},{match:`\\.(\\.|${F})+`}]
|
2021-06-08 07:40:19 +02:00
|
|
|
}],x="([0-9a-fA-F]_*)+",I={className:"number",relevance:0,variants:[{
|
|
|
|
match:"\\b(([0-9]_*)+)(\\.(([0-9]_*)+))?([eE][+-]?(([0-9]_*)+))?\\b"},{
|
|
|
|
match:`\\b0x(${x})(\\.(${x}))?([pP][+-]?(([0-9]_*)+))?\\b`},{
|
|
|
|
match:/\b0o([0-7]_*)+\b/},{match:/\b0b([01]_*)+\b/}]},L=(e="")=>({
|
|
|
|
className:"subst",variants:[{match:t(/\\/,e,/[0\\tnr"']/)},{
|
|
|
|
match:t(/\\/,e,/u\{[0-9a-fA-F]{1,8}\}/)}]}),O=(e="")=>({className:"subst",
|
|
|
|
match:t(/\\/,e,/[\t ]*(?:[\r\n]|\r\n)/)}),T=(e="")=>({className:"subst",
|
|
|
|
label:"interpol",begin:t(/\\/,e,/\(/),end:/\)/}),$=(e="")=>({begin:t(e,/"""/),
|
|
|
|
end:t(/"""/,e),contains:[L(e),O(e),T(e)]}),j=(e="")=>({begin:t(e,/"/),
|
|
|
|
end:t(/"/,e),contains:[L(e),T(e)]}),P={className:"string",
|
|
|
|
variants:[$(),$("#"),$("##"),$("###"),j(),j("#"),j("##"),j("###")]},K={
|
|
|
|
match:t(/`/,w,/`/)},z=[K,{className:"variable",match:/\$\d+/},{
|
2022-01-09 09:04:16 +01:00
|
|
|
className:"variable",match:`\\$${f}+`}],q=[{match:/(@|#(un)?)available/,
|
2021-06-08 07:40:19 +02:00
|
|
|
className:"keyword",starts:{contains:[{begin:/\(/,end:/\)/,keywords:E,
|
|
|
|
contains:[...M,I,P]}]}},{className:"keyword",match:t(/@/,n(...g))},{
|
|
|
|
className:"meta",match:t(/@/,w)}],U={match:a(/\b[A-Z]/),relevance:0,contains:[{
|
|
|
|
className:"type",
|
|
|
|
match:t(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/,f,"+")
|
|
|
|
},{className:"type",match:y,relevance:0},{match:/[?!]+/,relevance:0},{
|
|
|
|
match:/\.\.\./,relevance:0},{match:t(/\s+&\s+/,a(y)),relevance:0}]},Z={
|
|
|
|
begin:/</,end:/>/,keywords:k,contains:[...v,...B,...q,S,U]};U.contains.push(Z)
|
|
|
|
;const V={begin:/\(/,end:/\)/,relevance:0,keywords:k,contains:["self",{
|
|
|
|
match:t(w,/\s*:/),keywords:"_|0",relevance:0
|
|
|
|
},...v,...B,..._,...M,I,P,...z,...q,U]},W={begin:/</,end:/>/,contains:[...v,U]
|
|
|
|
},G={begin:/\(/,end:/\)/,keywords:k,contains:[{
|
|
|
|
begin:n(a(t(w,/\s*:/)),a(t(w,/\s+/,w,/\s*:/))),end:/:/,relevance:0,contains:[{
|
|
|
|
className:"keyword",match:/\b_\b/},{className:"params",match:w}]
|
|
|
|
},...v,...B,...M,I,P,...q,U,V],endsParent:!0,illegal:/["']/},R={
|
|
|
|
match:[/func/,/\s+/,n(K.match,w,b)],className:{1:"keyword",3:"title.function"},
|
2021-08-02 06:42:23 +02:00
|
|
|
contains:[W,G,d],illegal:[/\[/,/%/]},X={
|
2021-06-08 07:40:19 +02:00
|
|
|
match:[/\b(?:subscript|init[?!]?)/,/\s*(?=[<(])/],className:{1:"keyword"},
|
2021-08-02 06:42:23 +02:00
|
|
|
contains:[W,G,d],illegal:/\[|%/},H={match:[/operator/,/\s+/,b],className:{
|
2021-06-08 07:40:19 +02:00
|
|
|
1:"keyword",3:"title"}},J={begin:[/precedencegroup/,/\s+/,y],className:{
|
|
|
|
1:"keyword",3:"title"},contains:[U],keywords:[...l,...o],end:/}/}
|
|
|
|
;for(const e of P.variants){const a=e.contains.find((e=>"interpol"===e.label))
|
|
|
|
;a.keywords=k;const t=[...B,..._,...M,I,P,...z];a.contains=[...t,{begin:/\(/,
|
|
|
|
end:/\)/,contains:["self",...t]}]}return{name:"Swift",keywords:k,
|
|
|
|
contains:[...v,R,X,{beginKeywords:"struct protocol class extension enum actor",
|
|
|
|
end:"\\{",excludeEnd:!0,keywords:k,contains:[e.inherit(e.TITLE_MODE,{
|
|
|
|
className:"title.class",begin:/[A-Za-z$_][\u00C0-\u02B80-9A-Za-z$_]*/}),...B]
|
|
|
|
},H,J,{beginKeywords:"import",end:/$/,contains:[...v],relevance:0
|
2021-10-18 07:02:03 +02:00
|
|
|
},...B,..._,...M,I,P,...z,...q,U,V]}}})();hljs.registerLanguage("swift",e)})();
|