aspectj.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * @param {string} value
  3. * @returns {RegExp}
  4. * */
  5. /**
  6. * @param {RegExp | string } re
  7. * @returns {string}
  8. */
  9. function source(re) {
  10. if (!re) return null;
  11. if (typeof re === "string") return re;
  12. return re.source;
  13. }
  14. /**
  15. * @param {...(RegExp | string) } args
  16. * @returns {string}
  17. */
  18. function concat(...args) {
  19. const joined = args.map((x) => source(x)).join("");
  20. return joined;
  21. }
  22. /*
  23. Language: AspectJ
  24. Author: Hakan Ozler <ozler.hakan@gmail.com>
  25. Website: https://www.eclipse.org/aspectj/
  26. Description: Syntax Highlighting for the AspectJ Language which is a general-purpose aspect-oriented extension to the Java programming language.
  27. Audit: 2020
  28. */
  29. /** @type LanguageFn */
  30. function aspectj(hljs) {
  31. const KEYWORDS =
  32. 'false synchronized int abstract float private char boolean static null if const ' +
  33. 'for true while long throw strictfp finally protected import native final return void ' +
  34. 'enum else extends implements break transient new catch instanceof byte super volatile case ' +
  35. 'assert short package default double public try this switch continue throws privileged ' +
  36. 'aspectOf adviceexecution proceed cflowbelow cflow initialization preinitialization ' +
  37. 'staticinitialization withincode target within execution getWithinTypeName handler ' +
  38. 'thisJoinPoint thisJoinPointStaticPart thisEnclosingJoinPointStaticPart declare parents ' +
  39. 'warning error soft precedence thisAspectInstance';
  40. const SHORTKEYS = 'get set args call';
  41. return {
  42. name: 'AspectJ',
  43. keywords: KEYWORDS,
  44. illegal: /<\/|#/,
  45. contains: [
  46. hljs.COMMENT(
  47. /\/\*\*/,
  48. /\*\//,
  49. {
  50. relevance: 0,
  51. contains: [
  52. {
  53. // eat up @'s in emails to prevent them to be recognized as doctags
  54. begin: /\w+@/,
  55. relevance: 0
  56. },
  57. {
  58. className: 'doctag',
  59. begin: /@[A-Za-z]+/
  60. }
  61. ]
  62. }
  63. ),
  64. hljs.C_LINE_COMMENT_MODE,
  65. hljs.C_BLOCK_COMMENT_MODE,
  66. hljs.APOS_STRING_MODE,
  67. hljs.QUOTE_STRING_MODE,
  68. {
  69. className: 'class',
  70. beginKeywords: 'aspect',
  71. end: /[{;=]/,
  72. excludeEnd: true,
  73. illegal: /[:;"\[\]]/,
  74. contains: [
  75. {
  76. beginKeywords: 'extends implements pertypewithin perthis pertarget percflowbelow percflow issingleton'
  77. },
  78. hljs.UNDERSCORE_TITLE_MODE,
  79. {
  80. begin: /\([^\)]*/,
  81. end: /[)]+/,
  82. keywords: KEYWORDS + ' ' + SHORTKEYS,
  83. excludeEnd: false
  84. }
  85. ]
  86. },
  87. {
  88. className: 'class',
  89. beginKeywords: 'class interface',
  90. end: /[{;=]/,
  91. excludeEnd: true,
  92. relevance: 0,
  93. keywords: 'class interface',
  94. illegal: /[:"\[\]]/,
  95. contains: [
  96. {
  97. beginKeywords: 'extends implements'
  98. },
  99. hljs.UNDERSCORE_TITLE_MODE
  100. ]
  101. },
  102. {
  103. // AspectJ Constructs
  104. beginKeywords: 'pointcut after before around throwing returning',
  105. end: /[)]/,
  106. excludeEnd: false,
  107. illegal: /["\[\]]/,
  108. contains: [
  109. {
  110. begin: concat(hljs.UNDERSCORE_IDENT_RE, /\s*\(/),
  111. returnBegin: true,
  112. contains: [ hljs.UNDERSCORE_TITLE_MODE ]
  113. }
  114. ]
  115. },
  116. {
  117. begin: /[:]/,
  118. returnBegin: true,
  119. end: /[{;]/,
  120. relevance: 0,
  121. excludeEnd: false,
  122. keywords: KEYWORDS,
  123. illegal: /["\[\]]/,
  124. contains: [
  125. {
  126. begin: concat(hljs.UNDERSCORE_IDENT_RE, /\s*\(/),
  127. keywords: KEYWORDS + ' ' + SHORTKEYS,
  128. relevance: 0
  129. },
  130. hljs.QUOTE_STRING_MODE
  131. ]
  132. },
  133. {
  134. // this prevents 'new Name(...), or throw ...' from being recognized as a function definition
  135. beginKeywords: 'new throw',
  136. relevance: 0
  137. },
  138. {
  139. // the function class is a bit different for AspectJ compared to the Java language
  140. className: 'function',
  141. begin: /\w+ +\w+(\.\w+)?\s*\([^\)]*\)\s*((throws)[\w\s,]+)?[\{;]/,
  142. returnBegin: true,
  143. end: /[{;=]/,
  144. keywords: KEYWORDS,
  145. excludeEnd: true,
  146. contains: [
  147. {
  148. begin: concat(hljs.UNDERSCORE_IDENT_RE, /\s*\(/),
  149. returnBegin: true,
  150. relevance: 0,
  151. contains: [ hljs.UNDERSCORE_TITLE_MODE ]
  152. },
  153. {
  154. className: 'params',
  155. begin: /\(/,
  156. end: /\)/,
  157. relevance: 0,
  158. keywords: KEYWORDS,
  159. contains: [
  160. hljs.APOS_STRING_MODE,
  161. hljs.QUOTE_STRING_MODE,
  162. hljs.C_NUMBER_MODE,
  163. hljs.C_BLOCK_COMMENT_MODE
  164. ]
  165. },
  166. hljs.C_LINE_COMMENT_MODE,
  167. hljs.C_BLOCK_COMMENT_MODE
  168. ]
  169. },
  170. hljs.C_NUMBER_MODE,
  171. {
  172. // annotation is also used in this language
  173. className: 'meta',
  174. begin: /@[A-Za-z]+/
  175. }
  176. ]
  177. };
  178. }
  179. module.exports = aspectj;