PageSourceSearch

https://pika.page/assets/highlight.js--lib--languages--swift-1967c…45ffc8adf4454ea0508b406f48657318ea79dabd.js

js pika.page collected 2026-09-25 18:56:40 UTC 10,082 bytes, 35 lines download raw bytes

vendor: 4,977 bytes, lines 1-33
1// highlight.js/lib/languages/[email protected] downloaded from https://ga.jspm.io/npm:[email protected]/es/languages/swift.js
2
3/**
4 * @param {string} value
5 * @returns {RegExp}
6 * */
7/**
8 * @param {RegExp | string } re
9 * @returns {string}
10 */
11function source(e){return e?typeof e==="string"?e:e.source:null}
12/**
13 * @param {RegExp | string } re
14 * @returns {string}
15 */function lookahead(e){return concat("(?=",e,")")}
16/**
17 * @param {...(RegExp | string) } args
18 * @returns {string}
19 */function concat(...e){const t=e.map((e=>source(e))).join("");return t}
20/**
21 * @param { Array<string | RegExp | Object> } args
22 * @returns {object}
23 */function stripOptionsFromArgs(e){const t=e[e.length-1];if(typeof t==="object"&&t.constructor===Object){e.splice(e.length-1,1);return t}return{}}
24/** @typedef { {capture?: boolean} } RegexEitherOptions */
25/**
26 * Any of the passed expresssions may match
27 *
28 * Creates a huge this | this | that | that match
29 * @param {(RegExp | string)[] | [...(RegExp | string)[], RegexEitherOptions]} args
30 * @returns {string}
31 */function either(...e){
32/** @type { object & {capture?: boolean} }  */
33const t=stripOptionsFromArgs(e);const n="("+(t.capture?"":"?:")+e.map((e=>source(e))).join("|")+")";return n}const keywordWrapper=e=>concat(/\b/,e,/\w$/.test(e)?/\b/:/\B/);const e=["Protocol","Type"].map(keywordWrapper);const t=["init","self"].map(keywordWrapper);const n=["Any","Self"];const c=["actor","any","associatedtype","async","await",/as\?/,/as!/,"as","borrowing","break","case","catch","class","consume","consuming","continue","convenience","copy","default","defer","deinit","didSet","distributed","do","dynamic","each","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","macro","mutating","nonmutating",/open\(set\)/,"open","operator","optional","override","package","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"];const a=["false","nil","true"];const o=["assignment","associativity","higherThan","left","lowerThan","none","right"];const s=["#colorLiteral","#column","#dsohandle","#else","#elseif","#endif","#error","#file","#fileID","#fileLiteral","#filePath","#function","#if","#imageLiteral","#keyPath","#line","#selector","#sourceLocation","#warning"];const i=["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"];const r=either(/[/=\-+!*%<>&|^~?]/,/[\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]/);const u=either(r,/[\u0300-\u036F]/,/[\u1DC0-\u1DFF]/,/[\u20D0-\u20FF]/,/[\uFE00-\uFE0F]/,/[\uFE20-\uFE2F]/);const l=concat(r,u,"*");const p=either(/[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]/);const d=either(p,/\d/,/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/);const m=concat(p,d,"*");const h=concat(/[A-Z]/,d,"*");const F=["attached","autoclosure",concat(/convention\(/,either("swift","block","c"),/\)/),"discardableResult","dynamicCallable","dynamicMemberLookup","escaping","freestanding","frozen","GKInspectable","IBAction","IBDesignable","IBInspectable","IBOutlet","IBSegueAction","inlinable","main","nonobjc","NSApplicationMain","NSCopying","NSManaged",concat(/objc\(/,m,/\)/),"objc","objcMembers","propertyWrapper","requires_stored_property_inits","resultBuilder","Sendable","testable","UIApplicationMain","unchecked","unknown","usableFromInline","warn_unqualified_access"];const b=["iOS","iOSApplicationExtension","macOS","macOSApplicationExtension","macCatalyst","macCatalystApplicationExtension","wat
vendor: 4,346 bytes, lines 33-34
33chOS","watchOSApplicationExtension","tvOS","tvOSApplicationExtension","swift"];
34/** @type LanguageFn */function swift(r){const p={match:/\s+/,relevance:0};const f=r.COMMENT("/\\*","\\*/",{contains:["self"]});const w=[r.C_LINE_COMMENT_MODE,f];const y={match:[/\./,either(...e,...t)],className:{2:"keyword"}};const g={match:concat(/\./,either(...c)),relevance:0};const A=c.filter((e=>typeof e==="string")).concat(["_|0"]);const k=c.filter((e=>typeof e!=="string")).concat(n).map(keywordWrapper);const v={variants:[{className:"keyword",match:either(...k,...t)}]};const E={$pattern:either(/\b\w+/,/#\w+/),keyword:A.concat(s),literal:a};const C=[y,g,v];const N={match:concat(/\./,either(...i)),relevance:0};const S={className:"built_in",match:concat(/\b/,either(...i),/(?=\()/)};const B=[N,S];const D={match:/->/,relevance:0};const _={className:"operator",relevance:0,variants:[{match:l},{match:`\\.(\\.|${u})+`}]};const M=[D,_];const x="([0-9]_*)+";const O="([0-9a-fA-F]_*)+";const $={className:"number",relevance:0,variants:[{match:`\\b(${x})(\\.(${x}))?([eE][+-]?(${x}))?\\b`},{match:`\\b0x(${O})(\\.(${O}))?([pP][+-]?(${x}))?\\b`},{match:/\b0o([0-7]_*)+\b/},{match:/\b0b([01]_*)+\b/}]};const ESCAPED_CHARACTER=(e="")=>({className:"subst",variants:[{match:concat(/\\/,e,/[0\\tnr"']/)},{match:concat(/\\/,e,/u\{[0-9a-fA-F]{1,8}\}/)}]});const ESCAPED_NEWLINE=(e="")=>({className:"subst",match:concat(/\\/,e,/[\t ]*(?:[\r\n]|\r\n)/)});const INTERPOLATION=(e="")=>({className:"subst",label:"interpol",begin:concat(/\\/,e,/\(/),end:/\)/});const MULTILINE_STRING=(e="")=>({begin:concat(e,/"""/),end:concat(/"""/,e),contains:[ESCAPED_CHARACTER(e),ESCAPED_NEWLINE(e),INTERPOLATION(e)]});const SINGLE_LINE_STRING=(e="")=>({begin:concat(e,/"/),end:concat(/"/,e),contains:[ESCAPED_CHARACTER(e),INTERPOLATION(e)]});const L={className:"string",variants:[MULTILINE_STRING(),MULTILINE_STRING("#"),MULTILINE_STRING("##"),MULTILINE_STRING("###"),SINGLE_LINE_STRING(),SINGLE_LINE_STRING("#"),SINGLE_LINE_STRING("##"),SINGLE_LINE_STRING("###")]};const I=[r.BACKSLASH_ESCAPE,{begin:/\[/,end:/\]/,relevance:0,contains:[r.BACKSLASH_ESCAPE]}];const P={begin:/\/[^\s](?=[^/\n]*\/)/,end:/\//,contains:I};const EXTENDED_REGEXP_LITERAL=e=>{const t=concat(e,/\//);const n=concat(/\//,e);return{begin:t,end:n,contains:[...I,{scope:"comment",begin:`#(?!.*${n})`,end:/$/}]}};const K={scope:"regexp",variants:[EXTENDED_REGEXP_LITERAL("###"),EXTENDED_REGEXP_LITERAL("##"),EXTENDED_REGEXP_LITERAL("#"),P]};const T={match:concat(/`/,m,/`/)};const j={className:"variable",match:/\$\d+/};const z={className:"variable",match:`\\$${d}+`};const q=[T,j,z];const U={match:/(@|#(un)?)available/,scope:"keyword",starts:{contains:[{begin:/\(/,end:/\)/,keywords:b,contains:[...M,$,L]}]}};const Z={scope:"keyword",match:concat(/@/,either(...F),lookahead(either(/\(/,/\s+/)))};const V={scope:"meta",match:concat(/@/,m)};const W=[U,Z,V];const G={match:lookahead(/\b[A-Z]/),relevance:0,contains:[{className:"type",match:concat(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/,d,"+")},{className:"type",match:h,relevance:0},{match:/[?!]+/,relevance:0},{match:/\.\.\./,relevance:0},{match:concat(/\s+&\s+/,lookahead(h)),relevance:0}]};const H={begin:/</,end:/>/,keywords:E,contains:[...w,...C,...W,D,G]};G.contains.push(H);const R={match:concat(m,/\s*:/),keywords:"_|0",relevance:0};const X={begin:/\(/,end:/\)/,relevance:0,keywords:E,contains:["self",R,...w,K,...C,...B,...M,$,L,...q,...W,G]};const J={begin:/</,end:/>/,keywords:"repeat each",contains:[...w,G]};const Q={begin:either(lookahead(concat(m,/\s*:/)),lookahead(concat(m,/\s+/,m,/\s*:/))),end:/:/,relevance:0,contains:[{className:"keyword",match:/\b_\b/},{className:"params",match:m}]};const Y={begin:/\(/,end:/\)/,keywords:E,contains:[Q,...w,...C,...M,$,L,...W,G,X],endsParent:true,illegal:/["']/};const ee={match:[/(func|macro)/,/\s+/,either(T.match,m,l)],className:{1:"keyword",3:"title.function"},contains:[J,Y,p],illegal:[/\[/,/%/]};const te={match:[/\b(?:subscript|init[?!]?)/,/\s*(?=[<(])/],className:{1:"keyword"},contains:[J,Y,p],illegal:/\[|%/};const ne={match:[/operator/,/\s+/,l],className:{1:"keyword",3:"title"}};const ce={begin:[/precedencegroup/,/\s+/,h],className:{1:"keyword",3:"title"},contains:[G],keywords:[...o,...a],end:/}/};const ae={match:[/class\b/,/\s+/,/func\b/,/\s+/,/\b[A-Za-z_][A-Za-z0-9_]*\b/
34],scope:{1:"keyword",3:"keyword",5:"title.function"}};const oe={match:[/class\b/,/\s+/,/var\b/],scope:{1:"keyword",3:"keyword"}};const se={begin:[/(struct|protocol|class|extension|enum|actor)/,/\s+/,m,/\s*/],beginScope:{1:"keyword",3:"title.class"},keywords:E,contains:[J,...C,{begin:/:/,end:/\{/,keywords:E,contains:[{scope:"title.class.inherited",match:h},...C],relevance:0}]};for(const e of L.variants){const t=e.contains.find((e=>e.label==="interpol"));t.keywords=E;const n=[...C,...B,...M,$,L,...q];t.contains=[...n,{begin:/\(/,end:/\)/,contains:["self",...n]}]}return{name:"Swift",keywords:E,contains:[...w,ee,te,ae,oe,se,ne,ce,{beginKeywords:"import",end:/$/,contains:[...w],relevance:0},K,...C,...B,...M,$,L,...q,...W,G,X]}}export{swift as default};
35

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.