1
|
{"version":3,"file":"highlight/swift.js?v=369721213b205d3e29f7","mappings":"uFASA,SAASA,EAAOC,GACd,OAAKA,EACa,iBAAPA,EAAwBA,EAE5BA,EAAGD,OAHM,KAUlB,SAASE,EAAUD,GACjB,OAAOE,EAAO,MAAOF,EAAI,KAO3B,SAASE,KAAUC,GAEjB,OADeA,EAAKC,KAAKC,GAAMN,EAAOM,KAAIC,KAAK,IAWjD,SAASC,KAAUJ,GAEjB,MADe,IAAMA,EAAKC,KAAKC,GAAMN,EAAOM,KAAIC,KAAK,KAAO,IAI9D,MAAME,EAAiBC,GAAWP,EAChC,KACAO,EACA,MAAMC,KAAKD,GAAW,KAAO,MAIzBE,EAAc,CAClB,WACA,QACAP,IAAII,GAGAI,EAAsB,CAC1B,OACA,QACAR,IAAII,GAGAK,EAAe,CACnB,MACA,QAIIC,EAAW,CAIf,iBACA,QACA,QACA,OACA,MACA,KACA,QACA,OACA,QACA,QACA,WACA,cACA,UACA,QACA,SACA,SACA,KACA,UACA,OACA,OACA,YACA,cACA,qBACA,cACA,QACA,MACA,OACA,MACA,QACA,KACA,SACA,WACA,QACA,SACA,QACA,QACA,kBACA,WACA,KACA,KACA,OACA,MACA,WACA,cACA,cACA,OACA,WACA,WACA,WACA,UACA,kBACA,SACA,iBACA,UACA,WACA,gBACA,SACA,SACA,WACA,WACA,SACA,MACA,OACA,SACA,SACA,YACA,QACA,SACA,SACA,QACA,QACA,OACA,MACA,YACA,kBACA,oBACA,UACA,MACA,OACA,QACA,QACA,WAOIC,EAAW,CACf,QACA,MACA,QAIIC,EAA0B,CAC9B,aACA,gBACA,aACA,OACA,YACA,OACA,SAKIC,EAAqB,CACzB,gBACA,UACA,aACA,QACA,UACA,SACA,SACA,QACA,UACA,eACA,YACA,YACA,MACA,gBACA,WACA,QACA,YACA,kBACA,2BACA,YAIIC,EAAW,CACf,MACA,MACA,MACA,SACA,mBACA,aACA,OACA,aACA,YACA,4BACA,MACA,MACA,cACA,eACA,eACA,eACA,sBACA,QACA,WACA,gBACA,WACA,SACA,OACA,oCACA,YACA,OACA,gBACA,iBACA,uBACA,2BACA,oBACA,aACA,0BACA,OAIIC,EAAeZ,EACnB,oBACA,kBACA,iBACA,iBACA,iBACA,mCACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,kBACA,YAIIa,EAAoBb,EACxBY,EACA,kBACA,kBACA,kBACA,kBACA,mBAMIE,EAAWnB,EAAOiB,EAAcC,EAAmB,KAGnDE,EAAiBf,EACrB,YACA,uDACA,yDACA,yDACA,kBACA,+DACA,yDACA,+BACA,yDACA,yDACA,gCASIgB,EAAsBhB,EAC1Be,EACA,KACA,0DAIIE,EAAatB,EAAOoB,EAAgBC,EAAqB,KAGzDE,EAAiBvB,EAAO,QAASqB,EAAqB,KAItDG,EAAoB,CACxB,cACAxB,EAAO,eAAgBK,EAAO,QAAS,QAAS,KAAM,MACtD,oBACA,kBACA,sBACA,WACA,SACA,gBACA,WACA,eACA,gBACA,WACA,gBACA,YACA,OACA,UACA,oBACA,YACA,YACAL,EAAO,SAAUsB,EAAY,MAC7B,OACA,cACA,kBACA,iCACA,WACA,oBACA,UACA,oBAIIG,EAAuB,CAC3B,MACA,0BACA,QACA,4BACA,cACA,kCACA,UACA,8BACA,OACA,2BACA,SAmgBFC,EAAOC,QAtfP,SAAeC,GACb,MAAMC,EAAa,CACjBC,MAAO,MACPC,UAAW,GAGPC,EAAgBJ,EAAKK,QACzB,OACA,OACA,CACEC,SAAU,CAAE,UAGVC,EAAW,CACfP,EAAKQ,oBACLJ,GAKIK,EAAc,CAClBC,UAAW,UACXC,MAAOvC,EAAO,KAAMD,EAAUM,KAAUI,KAAgBC,KACxD8B,IAAKnC,KAAUI,KAAgBC,GAC/B+B,cAAc,GAEVC,EAAgB,CAEpBZ,MAAO9B,EAAO,KAAMK,KAAUO,IAC9BmB,UAAW,GAEPY,EAAiB/B,EACpBgC,QAAOC,GAAoB,iBAAPA,IACpB7C,OAAO,CA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,MAAMsC,EAAgBD,EAAQlD,SAASoD,MAAKC,GAAuB,aAAfA,EAAK1B,QAEzDwB,EAAczE,SAAWoC,EACzB,MAAMwC,EAAW,IACZrC,KACAC,KACAE,EACHE,EACAQ,KACGE,GAELmB,EAAcnD,SAAW,IACpBsD,EACH,CACEjD,MAAO,KACPC,IAAK,KACLN,SAAU,CACR,UACGsD,KAMX,MAAO,CACLC,KAAM,QACN7E,SAAUoC,EACVd,SAAU,IACLC,EACH4C,EACAC,EACA,CACE1C,UAAW,QACXoC,cAAe,uCACflC,IAAK,MACLkD,YAAY,EACZ9E,SAAUoC,EACVd,SAAU,CACRN,EAAK+D,QAAQ/D,EAAKgE,WAAY,CAC5BrD,MAAO,6CAENY,IAGP8B,EACAE,EACA,CACET,cAAe,SACflC,IAAK,IACLN,SAAU,IAAKC,GACfJ,UAAW,MAEVoB,KACAC,KACAE,EACHE,EACAQ,KACGE,KACAC,EACHE,EACAG","sources":["webpack:///text/node_modules/highlight.js/lib/languages/swift.js"],"sourcesContent":["/**\n * @param {string} value\n * @returns {RegExp}\n * */\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction source(re) {\n if (!re) return null;\n if (typeof re === \"string\") return re;\n\n return re.source;\n}\n\n/**\n * @param {RegExp | string } re\n * @returns {string}\n */\nfunction lookahead(re) {\n return concat('(?=', re, ')');\n}\n\n/**\n * @param {...(RegExp | string) } args\n * @returns {string}\n */\nfunction concat(...args) {\n const joined = args.map((x) => source(x)).join(\"\");\n return joined;\n}\n\n/**\n * Any of the passed expresssions may match\n *\n * Creates a huge this | this | that | that match\n * @param {(RegExp | string)[] } args\n * @returns {string}\n */\nfunction either(...args) {\n const joined = '(' + args.map((x) => source(x)).join(\"|\") + \")\";\n return joined;\n}\n\nconst keywordWrapper = keyword => concat(\n /\\b/,\n keyword,\n /\\w$/.test(keyword) ? /\\b/ : /\\B/\n);\n\n// Keywords that require a leading dot.\nconst dotKeywords = [\n 'Protocol', // contextual\n 'Type' // contextual\n].map(keywordWrapper);\n\n// Keywords that may have a leading dot.\nconst optionalDotKeywords = [\n 'init',\n 'self'\n].map(keywordWrapper);\n\n// should register as keyword, not type\nconst keywordTypes = [\n 'Any',\n 'Self'\n];\n\n// Regular keywords and literals.\nconst keywords = [\n // strings below will be fed into the regular `keywords` engine while regex\n // will result in additional modes being created to scan for those keywords to\n // avoid conflicts with other rules\n 'associatedtype',\n 'async',\n 'await',\n /as\\?/, // operator\n /as!/, // operator\n 'as', // operator\n 'break',\n 'case',\n 'catch',\n 'class',\n 'continue',\n 'convenience', // contextual\n 'default',\n 'defer',\n 'deinit',\n 'didSet', // contextual\n 'do',\n 'dynamic', // contextual\n 'else',\n 'enum',\n 'extension',\n 'fallthrough',\n /fileprivate\\(set\\)/,\n 'fileprivate',\n 'final', // contextual\n 'for',\n 'func',\n 'get', // contextual\n 'guard',\n 'if',\n 'import',\n 'indirect', // contextual\n 'infix', // contextual\n /init\\?/,\n /init!/,\n 'inout',\n /internal\\(set\\)/,\n 'internal',\n 'in',\n 'is', // operator\n 'lazy', // contextual\n 'let',\n 'mutating', // contextual\n 'nonmutating', // contextual\n /open\\(set\\)/, // contextual\n 'open', // contextual\n 'operator',\n 'optional', // contextual\n 'override', // contextual\n 'postfix', // contextual\n 'precedencegroup',\n 'prefix', // contextual\n /private\\(set\\)/,\n 'private',\n 'protocol',\n /public\\(set\\)/,\n 'public',\n 'repeat',\n 'required', // contextual\n 'rethrows',\n 'return',\n 'set', // contextual\n 'some', // contextual\n 'static',\n 'struct',\n 'subscript',\n 'super',\n 'switch',\n 'throws',\n 'throw',\n /try\\?/, // operator\n /try!/, // operator\n 'try', // operator\n 'typealias',\n /unowned\\(safe\\)/, // contextual\n /unowned\\(unsafe\\)/, // contextual\n 'unowned', // contextual\n 'var',\n 'weak', // contextual\n 'where',\n 'while',\n 'willSet' // contextual\n];\n\n// NOTE: Contextual keywords are reserved only in specific contexts.\n// Ideally, these should be matched using modes to avoid false positives.\n\n// Literals.\nconst literals = [\n 'false',\n 'nil',\n 'true'\n];\n\n// Keywords used in precedence groups.\nconst precedencegroupKeywords = [\n 'assignment',\n 'associativity',\n 'higherThan',\n 'left',\n 'lowerThan',\n 'none',\n 'right'\n];\n\n// Keywords that start with a number sign (#).\n// #available is handled separately.\nconst numberSignKeywords = [\n '#colorLiteral',\n '#column',\n '#dsohandle',\n '#else',\n '#elseif',\n '#endif',\n '#error',\n '#file',\n '#fileID',\n '#fileLiteral',\n '#filePath',\n '#function',\n '#if',\n '#imageLiteral',\n '#keyPath',\n '#line',\n '#selector',\n '#sourceLocation',\n '#warn_unqualified_access',\n '#warning'\n];\n\n// Global functions in the Standard Library.\nconst builtIns = [\n 'abs',\n 'all',\n 'any',\n 'assert',\n 'assertionFailure',\n 'debugPrint',\n 'dump',\n 'fatalError',\n 'getVaList',\n 'isKnownUniquelyReferenced',\n 'max',\n 'min',\n 'numericCast',\n 'pointwiseMax',\n 'pointwiseMin',\n 'precondition',\n 'preconditionFailure',\n 'print',\n 'readLine',\n 'repeatElement',\n 'sequence',\n 'stride',\n 'swap',\n 'swift_unboxFromSwiftValueWithType',\n 'transcode',\n 'type',\n 'unsafeBitCast',\n 'unsafeDowncast',\n 'withExtendedLifetime',\n 'withUnsafeMutablePointer',\n 'withUnsafePointer',\n 'withVaList',\n 'withoutActuallyEscaping',\n 'zip'\n];\n\n// Valid first characters for operators.\nconst operatorHead = either(\n /[/=\\-+!*%<>&|^~?]/,\n /[\\u00A1-\\u00A7]/,\n /[\\u00A9\\u00AB]/,\n /[\\u00AC\\u00AE]/,\n /[\\u00B0\\u00B1]/,\n /[\\u00B6\\u00BB\\u00BF\\u00D7\\u00F7]/,\n /[\\u2016-\\u2017]/,\n /[\\u2020-\\u2027]/,\n /[\\u2030-\\u203E]/,\n /[\\u2041-\\u2053]/,\n /[\\u2055-\\u205E]/,\n /[\\u2190-\\u23FF]/,\n /[\\u2500-\\u2775]/,\n /[\\u2794-\\u2BFF]/,\n /[\\u2E00-\\u2E7F]/,\n /[\\u3001-\\u3003]/,\n /[\\u3008-\\u3020]/,\n /[\\u3030]/\n);\n\n// Valid characters for operators.\nconst operatorCharacter = either(\n operatorHead,\n /[\\u0300-\\u036F]/,\n /[\\u1DC0-\\u1DFF]/,\n /[\\u20D0-\\u20FF]/,\n /[\\uFE00-\\uFE0F]/,\n /[\\uFE20-\\uFE2F]/\n // TODO: The following characters are also allowed, but the regex isn't supported yet.\n // /[\\u{E0100}-\\u{E01EF}]/u\n);\n\n// Valid operator.\nconst operator = concat(operatorHead, operatorCharacter, '*');\n\n// Valid first characters for identifiers.\nconst identifierHead = either(\n /[a-zA-Z_]/,\n /[\\u00A8\\u00AA\\u00AD\\u00AF\\u00B2-\\u00B5\\u00B7-\\u00BA]/,\n /[\\u00BC-\\u00BE\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u00FF]/,\n /[\\u0100-\\u02FF\\u0370-\\u167F\\u1681-\\u180D\\u180F-\\u1DBF]/,\n /[\\u1E00-\\u1FFF]/,\n /[\\u200B-\\u200D\\u202A-\\u202E\\u203F-\\u2040\\u2054\\u2060-\\u206F]/,\n /[\\u2070-\\u20CF\\u2100-\\u218F\\u2460-\\u24FF\\u2776-\\u2793]/,\n /[\\u2C00-\\u2DFF\\u2E80-\\u2FFF]/,\n /[\\u3004-\\u3007\\u3021-\\u302F\\u3031-\\u303F\\u3040-\\uD7FF]/,\n /[\\uF900-\\uFD3D\\uFD40-\\uFDCF\\uFDF0-\\uFE1F\\uFE30-\\uFE44]/,\n /[\\uFE47-\\uFEFE\\uFF00-\\uFFFD]/ // Should be /[\\uFE47-\\uFFFD]/, but we have to exclude FEFF.\n // The following characters are also allowed, but the regexes aren't supported yet.\n // /[\\u{10000}-\\u{1FFFD}\\u{20000-\\u{2FFFD}\\u{30000}-\\u{3FFFD}\\u{40000}-\\u{4FFFD}]/u,\n // /[\\u{50000}-\\u{5FFFD}\\u{60000-\\u{6FFFD}\\u{70000}-\\u{7FFFD}\\u{80000}-\\u{8FFFD}]/u,\n // /[\\u{90000}-\\u{9FFFD}\\u{A0000-\\u{AFFFD}\\u{B0000}-\\u{BFFFD}\\u{C0000}-\\u{CFFFD}]/u,\n // /[\\u{D0000}-\\u{DFFFD}\\u{E0000-\\u{EFFFD}]/u\n);\n\n// Valid characters for identifiers.\nconst identifierCharacter = either(\n identifierHead,\n /\\d/,\n /[\\u0300-\\u036F\\u1DC0-\\u1DFF\\u20D0-\\u20FF\\uFE20-\\uFE2F]/\n);\n\n// Valid identifier.\nconst identifier = concat(identifierHead, identifierCharacter, '*');\n\n// Valid type identifier.\nconst typeIdentifier = concat(/[A-Z]/, identifierCharacter, '*');\n\n// Built-in attributes, which are highlighted as keywords.\n// @available is handled separately.\nconst keywordAttributes = [\n 'autoclosure',\n concat(/convention\\(/, either('swift', 'block', 'c'), /\\)/),\n 'discardableResult',\n 'dynamicCallable',\n 'dynamicMemberLookup',\n 'escaping',\n 'frozen',\n 'GKInspectable',\n 'IBAction',\n 'IBDesignable',\n 'IBInspectable',\n 'IBOutlet',\n 'IBSegueAction',\n 'inlinable',\n 'main',\n 'nonobjc',\n 'NSApplicationMain',\n 'NSCopying',\n 'NSManaged',\n concat(/objc\\(/, identifier, /\\)/),\n 'objc',\n 'objcMembers',\n 'propertyWrapper',\n 'requires_stored_property_inits',\n 'testable',\n 'UIApplicationMain',\n 'unknown',\n 'usableFromInline'\n];\n\n// Contextual keywords used in @available and #available.\nconst availabilityKeywords = [\n 'iOS',\n 'iOSApplicationExtension',\n 'macOS',\n 'macOSApplicationExtension',\n 'macCatalyst',\n 'macCatalystApplicationExtension',\n 'watchOS',\n 'watchOSApplicationExtension',\n 'tvOS',\n 'tvOSApplicationExtension',\n 'swift'\n];\n\n/*\nLanguage: Swift\nDescription: Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.\nAuthor: Steven Van Impe <steven.vanimpe@icloud.com>\nContributors: Chris Eidhof <chris@eidhof.nl>, Nate Cook <natecook@gmail.com>, Alexander Lichter <manniL@gmx.net>, Richard Gibson <gibson042@github>\nWebsite: https://swift.org\nCategory: common, system\n*/\n\n/** @type LanguageFn */\nfunction swift(hljs) {\n const WHITESPACE = {\n match: /\\s+/,\n relevance: 0\n };\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID411\n const BLOCK_COMMENT = hljs.COMMENT(\n '/\\\\*',\n '\\\\*/',\n {\n contains: [ 'self' ]\n }\n );\n const COMMENTS = [\n hljs.C_LINE_COMMENT_MODE,\n BLOCK_COMMENT\n ];\n\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413\n // https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html\n const DOT_KEYWORD = {\n className: 'keyword',\n begin: concat(/\\./, lookahead(either(...dotKeywords, ...optionalDotKeywords))),\n end: either(...dotKeywords, ...optionalDotKeywords),\n excludeBegin: true\n };\n const KEYWORD_GUARD = {\n // Consume .keyword to prevent highlighting properties and methods as keywords.\n match: concat(/\\./, either(...keywords)),\n relevance: 0\n };\n const PLAIN_KEYWORDS = keywords\n .filter(kw => typeof kw === 'string')\n .concat([ \"_|0\" ]); // seems common, so 0 relevance\n const REGEX_KEYWORDS = keywords\n .filter(kw => typeof kw !== 'string') // find regex\n .concat(keywordTypes)\n .map(keywordWrapper);\n const KEYWORD = {\n variants: [\n {\n className: 'keyword',\n match: either(...REGEX_KEYWORDS, ...optionalDotKeywords)\n }\n ]\n };\n // find all the regular keywords\n const KEYWORDS = {\n $pattern: either(\n /\\b\\w+/, // regular keywords\n /#\\w+/ // number keywords\n ),\n keyword: PLAIN_KEYWORDS\n .concat(numberSignKeywords),\n literal: literals\n };\n const KEYWORD_MODES = [\n DOT_KEYWORD,\n KEYWORD_GUARD,\n KEYWORD\n ];\n\n // https://github.com/apple/swift/tree/main/stdlib/public/core\n const BUILT_IN_GUARD = {\n // Consume .built_in to prevent highlighting properties and methods.\n match: concat(/\\./, either(...builtIns)),\n relevance: 0\n };\n const BUILT_IN = {\n className: 'built_in',\n match: concat(/\\b/, either(...builtIns), /(?=\\()/)\n };\n const BUILT_INS = [\n BUILT_IN_GUARD,\n BUILT_IN\n ];\n\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID418\n const OPERATOR_GUARD = {\n // Prevent -> from being highlighting as an operator.\n match: /->/,\n relevance: 0\n };\n const OPERATOR = {\n className: 'operator',\n relevance: 0,\n variants: [\n {\n match: operator\n },\n {\n // dot-operator: only operators that start with a dot are allowed to use dots as\n // characters (..., ...<, .*, etc). So there rule here is: a dot followed by one or more\n // characters that may also include dots.\n match: `\\\\.(\\\\.|${operatorCharacter})+`\n }\n ]\n };\n const OPERATORS = [\n OPERATOR_GUARD,\n OPERATOR\n ];\n\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#grammar_numeric-literal\n // TODO: Update for leading `-` after lookbehind is supported everywhere\n const decimalDigits = '([0-9]_*)+';\n const hexDigits = '([0-9a-fA-F]_*)+';\n const NUMBER = {\n className: 'number',\n relevance: 0,\n variants: [\n // decimal floating-point-literal (subsumes decimal-literal)\n {\n match: `\\\\b(${decimalDigits})(\\\\.(${decimalDigits}))?` + `([eE][+-]?(${decimalDigits}))?\\\\b`\n },\n // hexadecimal floating-point-literal (subsumes hexadecimal-literal)\n {\n match: `\\\\b0x(${hexDigits})(\\\\.(${hexDigits}))?` + `([pP][+-]?(${decimalDigits}))?\\\\b`\n },\n // octal-literal\n {\n match: /\\b0o([0-7]_*)+\\b/\n },\n // binary-literal\n {\n match: /\\b0b([01]_*)+\\b/\n }\n ]\n };\n\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#grammar_string-literal\n const ESCAPED_CHARACTER = (rawDelimiter = \"\") => ({\n className: 'subst',\n variants: [\n {\n match: concat(/\\\\/, rawDelimiter, /[0\\\\tnr\"']/)\n },\n {\n match: concat(/\\\\/, rawDelimiter, /u\\{[0-9a-fA-F]{1,8}\\}/)\n }\n ]\n });\n const ESCAPED_NEWLINE = (rawDelimiter = \"\") => ({\n className: 'subst',\n match: concat(/\\\\/, rawDelimiter, /[\\t ]*(?:[\\r\\n]|\\r\\n)/)\n });\n const INTERPOLATION = (rawDelimiter = \"\") => ({\n className: 'subst',\n label: \"interpol\",\n begin: concat(/\\\\/, rawDelimiter, /\\(/),\n end: /\\)/\n });\n const MULTILINE_STRING = (rawDelimiter = \"\") => ({\n begin: concat(rawDelimiter, /\"\"\"/),\n end: concat(/\"\"\"/, rawDelimiter),\n contains: [\n ESCAPED_CHARACTER(rawDelimiter),\n ESCAPED_NEWLINE(rawDelimiter),\n INTERPOLATION(rawDelimiter)\n ]\n });\n const SINGLE_LINE_STRING = (rawDelimiter = \"\") => ({\n begin: concat(rawDelimiter, /\"/),\n end: concat(/\"/, rawDelimiter),\n contains: [\n ESCAPED_CHARACTER(rawDelimiter),\n INTERPOLATION(rawDelimiter)\n ]\n });\n const STRING = {\n className: 'string',\n variants: [\n MULTILINE_STRING(),\n MULTILINE_STRING(\"#\"),\n MULTILINE_STRING(\"##\"),\n MULTILINE_STRING(\"###\"),\n SINGLE_LINE_STRING(),\n SINGLE_LINE_STRING(\"#\"),\n SINGLE_LINE_STRING(\"##\"),\n SINGLE_LINE_STRING(\"###\")\n ]\n };\n\n // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID412\n const QUOTED_IDENTIFIER = {\n match: concat(/`/, identifier, /`/)\n };\n const IMPLICIT_PARAMETER = {\n className: 'variable',\n match: /\\$\\d+/\n };\n const PROPERTY_WRAPPER_PROJECTION = {\n className: 'variable',\n match: `\\\\$${identifierCharacter}+`\n };\n const IDENTIFIERS = [\n QUOTED_IDENTIFIER,\n IMPLICIT_PARAMETER,\n PROPERTY_WRAPPER_PROJECTION\n ];\n\n // https://docs.swift.org/swift-book/ReferenceManual/Attributes.html\n const AVAILABLE_ATTRIBUTE = {\n match: /(@|#)available/,\n className: \"keyword\",\n starts: {\n contains: [\n {\n begin: /\\(/,\n end: /\\)/,\n keywords: availabilityKeywords,\n contains: [\n ...OPERATORS,\n NUMBER,\n STRING\n ]\n }\n ]\n }\n };\n const KEYWORD_ATTRIBUTE = {\n className: 'keyword',\n match: concat(/@/, either(...keywordAttributes))\n };\n const USER_DEFINED_ATTRIBUTE = {\n className: 'meta',\n match: concat(/@/, identifier)\n };\n const ATTRIBUTES = [\n AVAILABLE_ATTRIBUTE,\n KEYWORD_ATTRIBUTE,\n USER_DEFINED_ATTRIBUTE\n ];\n\n // https://docs.swift.org/swift-book/ReferenceManual/Types.html\n const TYPE = {\n match: lookahead(/\\b[A-Z]/),\n relevance: 0,\n contains: [\n { // Common Apple frameworks, for relevance boost\n className: 'type',\n match: concat(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/, identifierCharacter, '+')\n },\n { // Type identifier\n className: 'type',\n match: typeIdentifier,\n relevance: 0\n },\n { // Optional type\n match: /[?!]+/,\n relevance: 0\n },\n { // Variadic parameter\n match: /\\.\\.\\./,\n relevance: 0\n },\n { // Protocol composition\n match: concat(/\\s+&\\s+/, lookahead(typeIdentifier)),\n relevance: 0\n }\n ]\n };\n const GENERIC_ARGUMENTS = {\n begin: /</,\n end: />/,\n keywords: KEYWORDS,\n contains: [\n ...COMMENTS,\n ...KEYWORD_MODES,\n ...ATTRIBUTES,\n OPERATOR_GUARD,\n TYPE\n ]\n };\n TYPE.contains.push(GENERIC_ARGUMENTS);\n\n // https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#ID552\n // Prevents element names from being highlighted as keywords.\n const TUPLE_ELEMENT_NAME = {\n match: concat(identifier, /\\s*:/),\n keywords: \"_|0\",\n relevance: 0\n };\n // Matches tuples as well as the parameter list of a function type.\n const TUPLE = {\n begin: /\\(/,\n end: /\\)/,\n relevance: 0,\n keywords: KEYWORDS,\n contains: [\n 'self',\n TUPLE_ELEMENT_NAME,\n ...COMMENTS,\n ...KEYWORD_MODES,\n ...BUILT_INS,\n ...OPERATORS,\n NUMBER,\n STRING,\n ...IDENTIFIERS,\n ...ATTRIBUTES,\n TYPE\n ]\n };\n\n // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID362\n // Matches both the keyword func and the function title.\n // Grouping these lets us differentiate between the operator function <\n // and the start of the generic parameter clause (also <).\n const FUNC_PLUS_TITLE = {\n beginKeywords: 'func',\n contains: [\n {\n className: 'title',\n match: either(QUOTED_IDENTIFIER.match, identifier, operator),\n // Required to make sure the opening < of the generic parameter clause\n // isn't parsed as a second title.\n endsParent: true,\n relevance: 0\n },\n WHITESPACE\n ]\n };\n const GENERIC_PARAMETERS = {\n begin: /</,\n end: />/,\n contains: [\n ...COMMENTS,\n TYPE\n ]\n };\n const FUNCTION_PARAMETER_NAME = {\n begin: either(\n lookahead(concat(identifier, /\\s*:/)),\n lookahead(concat(identifier, /\\s+/, identifier, /\\s*:/))\n ),\n end: /:/,\n relevance: 0,\n contains: [\n {\n className: 'keyword',\n match: /\\b_\\b/\n },\n {\n className: 'params',\n match: identifier\n }\n ]\n };\n const FUNCTION_PARAMETERS = {\n begin: /\\(/,\n end: /\\)/,\n keywords: KEYWORDS,\n contains: [\n FUNCTION_PARAMETER_NAME,\n ...COMMENTS,\n ...KEYWORD_MODES,\n ...OPERATORS,\n NUMBER,\n STRING,\n ...ATTRIBUTES,\n TYPE,\n TUPLE\n ],\n endsParent: true,\n illegal: /[\"']/\n };\n const FUNCTION = {\n className: 'function',\n match: lookahead(/\\bfunc\\b/),\n contains: [\n FUNC_PLUS_TITLE,\n GENERIC_PARAMETERS,\n FUNCTION_PARAMETERS,\n WHITESPACE\n ],\n illegal: [\n /\\[/,\n /%/\n ]\n };\n\n // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID375\n // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID379\n const INIT_SUBSCRIPT = {\n className: 'function',\n match: /\\b(subscript|init[?!]?)\\s*(?=[<(])/,\n keywords: {\n keyword: \"subscript init init? init!\",\n $pattern: /\\w+[?!]?/\n },\n contains: [\n GENERIC_PARAMETERS,\n FUNCTION_PARAMETERS,\n WHITESPACE\n ],\n illegal: /\\[|%/\n };\n // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID380\n const OPERATOR_DECLARATION = {\n beginKeywords: 'operator',\n end: hljs.MATCH_NOTHING_RE,\n contains: [\n {\n className: 'title',\n match: operator,\n endsParent: true,\n relevance: 0\n }\n ]\n };\n\n // https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID550\n const PRECEDENCEGROUP = {\n beginKeywords: 'precedencegroup',\n end: hljs.MATCH_NOTHING_RE,\n contains: [\n {\n className: 'title',\n match: typeIdentifier,\n relevance: 0\n },\n {\n begin: /{/,\n end: /}/,\n relevance: 0,\n endsParent: true,\n keywords: [\n ...precedencegroupKeywords,\n ...literals\n ],\n contains: [ TYPE ]\n }\n ]\n };\n\n // Add supported submodes to string interpolation.\n for (const variant of STRING.variants) {\n const interpolation = variant.contains.find(mode => mode.label === \"interpol\");\n // TODO: Interpolation can contain any expression, so there's room for improvement here.\n interpolation.keywords = KEYWORDS;\n const submodes = [\n ...KEYWORD_MODES,\n ...BUILT_INS,\n ...OPERATORS,\n NUMBER,\n STRING,\n ...IDENTIFIERS\n ];\n interpolation.contains = [\n ...submodes,\n {\n begin: /\\(/,\n end: /\\)/,\n contains: [\n 'self',\n ...submodes\n ]\n }\n ];\n }\n\n return {\n name: 'Swift',\n keywords: KEYWORDS,\n contains: [\n ...COMMENTS,\n FUNCTION,\n INIT_SUBSCRIPT,\n {\n className: 'class',\n beginKeywords: 'struct protocol class extension enum',\n end: '\\\\{',\n excludeEnd: true,\n keywords: KEYWORDS,\n contains: [\n hljs.inherit(hljs.TITLE_MODE, {\n begin: /[A-Za-z$_][\\u00C0-\\u02B80-9A-Za-z$_]*/\n }),\n ...KEYWORD_MODES\n ]\n },\n OPERATOR_DECLARATION,\n PRECEDENCEGROUP,\n {\n beginKeywords: 'import',\n end: /$/,\n contains: [ ...COMMENTS ],\n relevance: 0\n },\n ...KEYWORD_MODES,\n ...BUILT_INS,\n ...OPERATORS,\n NUMBER,\n STRING,\n ...IDENTIFIERS,\n ...ATTRIBUTES,\n TYPE,\n TUPLE\n ]\n };\n}\n\nmodule.exports = swift;\n"],"names":["source","re","lookahead","concat","args","map","x","join","either","keywordWrapper","keyword","test","dotKeywords","optionalDotKeywords","keywordTypes","keywords","literals","precedencegroupKeywords","numberSignKeywords","builtIns","operatorHead","operatorCharacter","operator","identifierHead","identifierCharacter","identifier","typeIdentifier","keywordAttributes","availabilityKeywords","module","exports","hljs","WHITESPACE","match","relevance","BLOCK_COMMENT","COMMENT","contains","COMMENTS","C_LINE_COMMENT_MODE","DOT_KEYWORD","className","begin","end","excludeBegin","KEYWORD_GUARD","PLAIN_KEYWORDS","filter","kw","KEYWORD","variants","KEYWORDS","$pattern","literal","KEYWORD_MODES","BUILT_INS","OPERATOR_GUARD","OPERATORS","hexDigits","NUMBER","ESCAPED_CHARACTER","rawDelimiter","ESCAPED_NEWLINE","INTERPOLATION","label","MULTILINE_STRING","SINGLE_LINE_STRING","STRING","QUOTED_IDENTIFIER","IDENTIFIERS","ATTRIBUTES","starts","TYPE","GENERIC_ARGUMENTS","push","TUPLE","FUNC_PLUS_TITLE","beginKeywords","endsParent","GENERIC_PARAMETERS","FUNCTION_PARAMETERS","illegal","FUNCTION","INIT_SUBSCRIPT","OPERATOR_DECLARATION","MATCH_NOTHING_RE","PRECEDENCEGROUP","variant","interpolation","find","mode","submodes","name","excludeEnd","inherit","TITLE_MODE"],"sourceRoot":""}
|