objectivec.js 3.4 KB

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