123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- /*
- Language: Objective-C
- Author: Valerii Hiora <valerii.hiora@gmail.com>
- Contributors: Angel G. Olloqui <angelgarcia.mail@gmail.com>, Matt Diephouse <matt@diephouse.com>, Andrew Farmer <ahfarmer@gmail.com>, Minh Nguyễn <mxn@1ec5.org>
- Website: https://developer.apple.com/documentation/objectivec
- Category: common
- */
- function objectivec(hljs) {
- const API_CLASS = {
- className: 'built_in',
- begin: '\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+'
- };
- const IDENTIFIER_RE = /[a-zA-Z@][a-zA-Z0-9_]*/;
- const TYPES = [
- "int",
- "float",
- "char",
- "unsigned",
- "signed",
- "short",
- "long",
- "double",
- "wchar_t",
- "unichar",
- "void",
- "bool",
- "BOOL",
- "id|0",
- "_Bool"
- ];
- const KWS = [
- "while",
- "export",
- "sizeof",
- "typedef",
- "const",
- "struct",
- "for",
- "union",
- "volatile",
- "static",
- "mutable",
- "if",
- "do",
- "return",
- "goto",
- "enum",
- "else",
- "break",
- "extern",
- "asm",
- "case",
- "default",
- "register",
- "explicit",
- "typename",
- "switch",
- "continue",
- "inline",
- "readonly",
- "assign",
- "readwrite",
- "self",
- "@synchronized",
- "id",
- "typeof",
- "nonatomic",
- "IBOutlet",
- "IBAction",
- "strong",
- "weak",
- "copy",
- "in",
- "out",
- "inout",
- "bycopy",
- "byref",
- "oneway",
- "__strong",
- "__weak",
- "__block",
- "__autoreleasing",
- "@private",
- "@protected",
- "@public",
- "@try",
- "@property",
- "@end",
- "@throw",
- "@catch",
- "@finally",
- "@autoreleasepool",
- "@synthesize",
- "@dynamic",
- "@selector",
- "@optional",
- "@required",
- "@encode",
- "@package",
- "@import",
- "@defs",
- "@compatibility_alias",
- "__bridge",
- "__bridge_transfer",
- "__bridge_retained",
- "__bridge_retain",
- "__covariant",
- "__contravariant",
- "__kindof",
- "_Nonnull",
- "_Nullable",
- "_Null_unspecified",
- "__FUNCTION__",
- "__PRETTY_FUNCTION__",
- "__attribute__",
- "getter",
- "setter",
- "retain",
- "unsafe_unretained",
- "nonnull",
- "nullable",
- "null_unspecified",
- "null_resettable",
- "class",
- "instancetype",
- "NS_DESIGNATED_INITIALIZER",
- "NS_UNAVAILABLE",
- "NS_REQUIRES_SUPER",
- "NS_RETURNS_INNER_POINTER",
- "NS_INLINE",
- "NS_AVAILABLE",
- "NS_DEPRECATED",
- "NS_ENUM",
- "NS_OPTIONS",
- "NS_SWIFT_UNAVAILABLE",
- "NS_ASSUME_NONNULL_BEGIN",
- "NS_ASSUME_NONNULL_END",
- "NS_REFINED_FOR_SWIFT",
- "NS_SWIFT_NAME",
- "NS_SWIFT_NOTHROW",
- "NS_DURING",
- "NS_HANDLER",
- "NS_ENDHANDLER",
- "NS_VALUERETURN",
- "NS_VOIDRETURN"
- ];
- const LITERALS = [
- "false",
- "true",
- "FALSE",
- "TRUE",
- "nil",
- "YES",
- "NO",
- "NULL"
- ];
- const BUILT_INS = [
- "dispatch_once_t",
- "dispatch_queue_t",
- "dispatch_sync",
- "dispatch_async",
- "dispatch_once"
- ];
- const KEYWORDS = {
- "variable.language": [
- "this",
- "super"
- ],
- $pattern: IDENTIFIER_RE,
- keyword: KWS,
- literal: LITERALS,
- built_in: BUILT_INS,
- type: TYPES
- };
- const CLASS_KEYWORDS = {
- $pattern: IDENTIFIER_RE,
- keyword: [
- "@interface",
- "@class",
- "@protocol",
- "@implementation"
- ]
- };
- return {
- name: 'Objective-C',
- aliases: [
- 'mm',
- 'objc',
- 'obj-c',
- 'obj-c++',
- 'objective-c++'
- ],
- keywords: KEYWORDS,
- illegal: '</',
- contains: [
- API_CLASS,
- hljs.C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE,
- hljs.C_NUMBER_MODE,
- hljs.QUOTE_STRING_MODE,
- hljs.APOS_STRING_MODE,
- {
- className: 'string',
- variants: [
- {
- begin: '@"',
- end: '"',
- illegal: '\\n',
- contains: [ hljs.BACKSLASH_ESCAPE ]
- }
- ]
- },
- {
- className: 'meta',
- begin: /#\s*[a-z]+\b/,
- end: /$/,
- keywords: { keyword:
- 'if else elif endif define undef warning error line '
- + 'pragma ifdef ifndef include' },
- contains: [
- {
- begin: /\\\n/,
- relevance: 0
- },
- hljs.inherit(hljs.QUOTE_STRING_MODE, { className: 'string' }),
- {
- className: 'string',
- begin: /<.*?>/,
- end: /$/,
- illegal: '\\n'
- },
- hljs.C_LINE_COMMENT_MODE,
- hljs.C_BLOCK_COMMENT_MODE
- ]
- },
- {
- className: 'class',
- begin: '(' + CLASS_KEYWORDS.keyword.join('|') + ')\\b',
- end: /(\{|$)/,
- excludeEnd: true,
- keywords: CLASS_KEYWORDS,
- contains: [ hljs.UNDERSCORE_TITLE_MODE ]
- },
- {
- begin: '\\.' + hljs.UNDERSCORE_IDENT_RE,
- relevance: 0
- }
- ]
- };
- }
- module.exports = objectivec;
|