objectivec.js 3.9 KB

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