objectivec.js
1 /*! `objectivec` grammar compiled for Highlight.js 11.10.0 */ 2 (function(){ 3 var hljsGrammar = (function () { 4 'use strict'; 5 6 /* 7 Language: Objective-C 8 Author: Valerii Hiora <valerii.hiora@gmail.com> 9 Contributors: Angel G. Olloqui <angelgarcia.mail@gmail.com>, Matt Diephouse <matt@diephouse.com>, Andrew Farmer <ahfarmer@gmail.com>, Minh Nguyễn <mxn@1ec5.org> 10 Website: https://developer.apple.com/documentation/objectivec 11 Category: common 12 */ 13 14 function objectivec(hljs) { 15 const API_CLASS = { 16 className: 'built_in', 17 begin: '\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+' 18 }; 19 const IDENTIFIER_RE = /[a-zA-Z@][a-zA-Z0-9_]*/; 20 const TYPES = [ 21 "int", 22 "float", 23 "char", 24 "unsigned", 25 "signed", 26 "short", 27 "long", 28 "double", 29 "wchar_t", 30 "unichar", 31 "void", 32 "bool", 33 "BOOL", 34 "id|0", 35 "_Bool" 36 ]; 37 const KWS = [ 38 "while", 39 "export", 40 "sizeof", 41 "typedef", 42 "const", 43 "struct", 44 "for", 45 "union", 46 "volatile", 47 "static", 48 "mutable", 49 "if", 50 "do", 51 "return", 52 "goto", 53 "enum", 54 "else", 55 "break", 56 "extern", 57 "asm", 58 "case", 59 "default", 60 "register", 61 "explicit", 62 "typename", 63 "switch", 64 "continue", 65 "inline", 66 "readonly", 67 "assign", 68 "readwrite", 69 "self", 70 "@synchronized", 71 "id", 72 "typeof", 73 "nonatomic", 74 "IBOutlet", 75 "IBAction", 76 "strong", 77 "weak", 78 "copy", 79 "in", 80 "out", 81 "inout", 82 "bycopy", 83 "byref", 84 "oneway", 85 "__strong", 86 "__weak", 87 "__block", 88 "__autoreleasing", 89 "@private", 90 "@protected", 91 "@public", 92 "@try", 93 "@property", 94 "@end", 95 "@throw", 96 "@catch", 97 "@finally", 98 "@autoreleasepool", 99 "@synthesize", 100 "@dynamic", 101 "@selector", 102 "@optional", 103 "@required", 104 "@encode", 105 "@package", 106 "@import", 107 "@defs", 108 "@compatibility_alias", 109 "__bridge", 110 "__bridge_transfer", 111 "__bridge_retained", 112 "__bridge_retain", 113 "__covariant", 114 "__contravariant", 115 "__kindof", 116 "_Nonnull", 117 "_Nullable", 118 "_Null_unspecified", 119 "__FUNCTION__", 120 "__PRETTY_FUNCTION__", 121 "__attribute__", 122 "getter", 123 "setter", 124 "retain", 125 "unsafe_unretained", 126 "nonnull", 127 "nullable", 128 "null_unspecified", 129 "null_resettable", 130 "class", 131 "instancetype", 132 "NS_DESIGNATED_INITIALIZER", 133 "NS_UNAVAILABLE", 134 "NS_REQUIRES_SUPER", 135 "NS_RETURNS_INNER_POINTER", 136 "NS_INLINE", 137 "NS_AVAILABLE", 138 "NS_DEPRECATED", 139 "NS_ENUM", 140 "NS_OPTIONS", 141 "NS_SWIFT_UNAVAILABLE", 142 "NS_ASSUME_NONNULL_BEGIN", 143 "NS_ASSUME_NONNULL_END", 144 "NS_REFINED_FOR_SWIFT", 145 "NS_SWIFT_NAME", 146 "NS_SWIFT_NOTHROW", 147 "NS_DURING", 148 "NS_HANDLER", 149 "NS_ENDHANDLER", 150 "NS_VALUERETURN", 151 "NS_VOIDRETURN" 152 ]; 153 const LITERALS = [ 154 "false", 155 "true", 156 "FALSE", 157 "TRUE", 158 "nil", 159 "YES", 160 "NO", 161 "NULL" 162 ]; 163 const BUILT_INS = [ 164 "dispatch_once_t", 165 "dispatch_queue_t", 166 "dispatch_sync", 167 "dispatch_async", 168 "dispatch_once" 169 ]; 170 const KEYWORDS = { 171 "variable.language": [ 172 "this", 173 "super" 174 ], 175 $pattern: IDENTIFIER_RE, 176 keyword: KWS, 177 literal: LITERALS, 178 built_in: BUILT_INS, 179 type: TYPES 180 }; 181 const CLASS_KEYWORDS = { 182 $pattern: IDENTIFIER_RE, 183 keyword: [ 184 "@interface", 185 "@class", 186 "@protocol", 187 "@implementation" 188 ] 189 }; 190 return { 191 name: 'Objective-C', 192 aliases: [ 193 'mm', 194 'objc', 195 'obj-c', 196 'obj-c++', 197 'objective-c++' 198 ], 199 keywords: KEYWORDS, 200 illegal: '</', 201 contains: [ 202 API_CLASS, 203 hljs.C_LINE_COMMENT_MODE, 204 hljs.C_BLOCK_COMMENT_MODE, 205 hljs.C_NUMBER_MODE, 206 hljs.QUOTE_STRING_MODE, 207 hljs.APOS_STRING_MODE, 208 { 209 className: 'string', 210 variants: [ 211 { 212 begin: '@"', 213 end: '"', 214 illegal: '\\n', 215 contains: [ hljs.BACKSLASH_ESCAPE ] 216 } 217 ] 218 }, 219 { 220 className: 'meta', 221 begin: /#\s*[a-z]+\b/, 222 end: /$/, 223 keywords: { keyword: 224 'if else elif endif define undef warning error line ' 225 + 'pragma ifdef ifndef include' }, 226 contains: [ 227 { 228 begin: /\\\n/, 229 relevance: 0 230 }, 231 hljs.inherit(hljs.QUOTE_STRING_MODE, { className: 'string' }), 232 { 233 className: 'string', 234 begin: /<.*?>/, 235 end: /$/, 236 illegal: '\\n' 237 }, 238 hljs.C_LINE_COMMENT_MODE, 239 hljs.C_BLOCK_COMMENT_MODE 240 ] 241 }, 242 { 243 className: 'class', 244 begin: '(' + CLASS_KEYWORDS.keyword.join('|') + ')\\b', 245 end: /(\{|$)/, 246 excludeEnd: true, 247 keywords: CLASS_KEYWORDS, 248 contains: [ hljs.UNDERSCORE_TITLE_MODE ] 249 }, 250 { 251 begin: '\\.' + hljs.UNDERSCORE_IDENT_RE, 252 relevance: 0 253 } 254 ] 255 }; 256 } 257 258 return objectivec; 259 260 })(); 261 262 hljs.registerLanguage('objectivec', hljsGrammar); 263 })();