1 | /*
|
---|
2 | Language: Objective-C
|
---|
3 | Author: Valerii Hiora <valerii.hiora@gmail.com>
|
---|
4 | Contributors: Angel G. Olloqui <angelgarcia.mail@gmail.com>, Matt Diephouse <matt@diephouse.com>, Andrew Farmer <ahfarmer@gmail.com>, Minh Nguyễn <mxn@1ec5.org>
|
---|
5 | Website: https://developer.apple.com/documentation/objectivec
|
---|
6 | Category: common
|
---|
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 OBJC_KEYWORDS = {
|
---|
16 | $pattern: IDENTIFIER_RE,
|
---|
17 | keyword:
|
---|
18 | 'int float while char export sizeof typedef const struct for union ' +
|
---|
19 | 'unsigned long volatile static bool mutable if do return goto void ' +
|
---|
20 | 'enum else break extern asm case short default double register explicit ' +
|
---|
21 | 'signed typename this switch continue wchar_t inline readonly assign ' +
|
---|
22 | 'readwrite self @synchronized id typeof ' +
|
---|
23 | 'nonatomic super unichar IBOutlet IBAction strong weak copy ' +
|
---|
24 | 'in out inout bycopy byref oneway __strong __weak __block __autoreleasing ' +
|
---|
25 | '@private @protected @public @try @property @end @throw @catch @finally ' +
|
---|
26 | '@autoreleasepool @synthesize @dynamic @selector @optional @required ' +
|
---|
27 | '@encode @package @import @defs @compatibility_alias ' +
|
---|
28 | '__bridge __bridge_transfer __bridge_retained __bridge_retain ' +
|
---|
29 | '__covariant __contravariant __kindof ' +
|
---|
30 | '_Nonnull _Nullable _Null_unspecified ' +
|
---|
31 | '__FUNCTION__ __PRETTY_FUNCTION__ __attribute__ ' +
|
---|
32 | 'getter setter retain unsafe_unretained ' +
|
---|
33 | 'nonnull nullable null_unspecified null_resettable class instancetype ' +
|
---|
34 | 'NS_DESIGNATED_INITIALIZER NS_UNAVAILABLE NS_REQUIRES_SUPER ' +
|
---|
35 | 'NS_RETURNS_INNER_POINTER NS_INLINE NS_AVAILABLE NS_DEPRECATED ' +
|
---|
36 | 'NS_ENUM NS_OPTIONS NS_SWIFT_UNAVAILABLE ' +
|
---|
37 | 'NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END ' +
|
---|
38 | 'NS_REFINED_FOR_SWIFT NS_SWIFT_NAME NS_SWIFT_NOTHROW ' +
|
---|
39 | 'NS_DURING NS_HANDLER NS_ENDHANDLER NS_VALUERETURN NS_VOIDRETURN',
|
---|
40 | literal:
|
---|
41 | 'false true FALSE TRUE nil YES NO NULL',
|
---|
42 | built_in:
|
---|
43 | 'BOOL dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once'
|
---|
44 | };
|
---|
45 | const CLASS_KEYWORDS = {
|
---|
46 | $pattern: IDENTIFIER_RE,
|
---|
47 | keyword: '@interface @class @protocol @implementation'
|
---|
48 | };
|
---|
49 | return {
|
---|
50 | name: 'Objective-C',
|
---|
51 | aliases: [
|
---|
52 | 'mm',
|
---|
53 | 'objc',
|
---|
54 | 'obj-c',
|
---|
55 | 'obj-c++',
|
---|
56 | 'objective-c++'
|
---|
57 | ],
|
---|
58 | keywords: OBJC_KEYWORDS,
|
---|
59 | illegal: '</',
|
---|
60 | contains: [
|
---|
61 | API_CLASS,
|
---|
62 | hljs.C_LINE_COMMENT_MODE,
|
---|
63 | hljs.C_BLOCK_COMMENT_MODE,
|
---|
64 | hljs.C_NUMBER_MODE,
|
---|
65 | hljs.QUOTE_STRING_MODE,
|
---|
66 | hljs.APOS_STRING_MODE,
|
---|
67 | {
|
---|
68 | className: 'string',
|
---|
69 | variants: [
|
---|
70 | {
|
---|
71 | begin: '@"',
|
---|
72 | end: '"',
|
---|
73 | illegal: '\\n',
|
---|
74 | contains: [ hljs.BACKSLASH_ESCAPE ]
|
---|
75 | }
|
---|
76 | ]
|
---|
77 | },
|
---|
78 | {
|
---|
79 | className: 'meta',
|
---|
80 | begin: /#\s*[a-z]+\b/,
|
---|
81 | end: /$/,
|
---|
82 | keywords: {
|
---|
83 | 'meta-keyword':
|
---|
84 | 'if else elif endif define undef warning error line ' +
|
---|
85 | 'pragma ifdef ifndef include'
|
---|
86 | },
|
---|
87 | contains: [
|
---|
88 | {
|
---|
89 | begin: /\\\n/,
|
---|
90 | relevance: 0
|
---|
91 | },
|
---|
92 | hljs.inherit(hljs.QUOTE_STRING_MODE, {
|
---|
93 | className: 'meta-string'
|
---|
94 | }),
|
---|
95 | {
|
---|
96 | className: 'meta-string',
|
---|
97 | begin: /<.*?>/,
|
---|
98 | end: /$/,
|
---|
99 | illegal: '\\n'
|
---|
100 | },
|
---|
101 | hljs.C_LINE_COMMENT_MODE,
|
---|
102 | hljs.C_BLOCK_COMMENT_MODE
|
---|
103 | ]
|
---|
104 | },
|
---|
105 | {
|
---|
106 | className: 'class',
|
---|
107 | begin: '(' + CLASS_KEYWORDS.keyword.split(' ').join('|') + ')\\b',
|
---|
108 | end: /(\{|$)/,
|
---|
109 | excludeEnd: true,
|
---|
110 | keywords: CLASS_KEYWORDS,
|
---|
111 | contains: [ hljs.UNDERSCORE_TITLE_MODE ]
|
---|
112 | },
|
---|
113 | {
|
---|
114 | begin: '\\.' + hljs.UNDERSCORE_IDENT_RE,
|
---|
115 | relevance: 0
|
---|
116 | }
|
---|
117 | ]
|
---|
118 | };
|
---|
119 | }
|
---|
120 |
|
---|
121 | module.exports = objectivec;
|
---|