UNPKG

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