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