java.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. module.exports = function(hljs) {
  2. var JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';
  3. var GENERIC_IDENT_RE = JAVA_IDENT_RE + '(<' + JAVA_IDENT_RE + '(\\s*,\\s*' + JAVA_IDENT_RE + ')*>)?';
  4. var KEYWORDS =
  5. 'false synchronized int abstract float private char boolean var static null if const ' +
  6. 'for true while long strictfp finally protected import native final void ' +
  7. 'enum else break transient catch instanceof byte super volatile case assert short ' +
  8. 'package default double public try this switch continue throws protected public private ' +
  9. 'module requires exports do';
  10. // https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html
  11. var JAVA_NUMBER_RE = '\\b' +
  12. '(' +
  13. '0[bB]([01]+[01_]+[01]+|[01]+)' + // 0b...
  14. '|' +
  15. '0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)' + // 0x...
  16. '|' +
  17. '(' +
  18. '([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?' +
  19. '|' +
  20. '\\.([\\d]+[\\d_]+[\\d]+|[\\d]+)' +
  21. ')' +
  22. '([eE][-+]?\\d+)?' + // octal, decimal, float
  23. ')' +
  24. '[lLfF]?';
  25. var JAVA_NUMBER_MODE = {
  26. className: 'number',
  27. begin: JAVA_NUMBER_RE,
  28. relevance: 0
  29. };
  30. return {
  31. aliases: ['jsp'],
  32. keywords: KEYWORDS,
  33. illegal: /<\/|#/,
  34. contains: [
  35. hljs.COMMENT(
  36. '/\\*\\*',
  37. '\\*/',
  38. {
  39. relevance : 0,
  40. contains : [
  41. {
  42. // eat up @'s in emails to prevent them to be recognized as doctags
  43. begin: /\w+@/, relevance: 0
  44. },
  45. {
  46. className : 'doctag',
  47. begin : '@[A-Za-z]+'
  48. }
  49. ]
  50. }
  51. ),
  52. hljs.C_LINE_COMMENT_MODE,
  53. hljs.C_BLOCK_COMMENT_MODE,
  54. hljs.APOS_STRING_MODE,
  55. hljs.QUOTE_STRING_MODE,
  56. {
  57. className: 'class',
  58. beginKeywords: 'class interface', end: /[{;=]/, excludeEnd: true,
  59. keywords: 'class interface',
  60. illegal: /[:"\[\]]/,
  61. contains: [
  62. {beginKeywords: 'extends implements'},
  63. hljs.UNDERSCORE_TITLE_MODE
  64. ]
  65. },
  66. {
  67. // Expression keywords prevent 'keyword Name(...)' from being
  68. // recognized as a function definition
  69. beginKeywords: 'new throw return else',
  70. relevance: 0
  71. },
  72. {
  73. className: 'function',
  74. begin: '(' + GENERIC_IDENT_RE + '\\s+)+' + hljs.UNDERSCORE_IDENT_RE + '\\s*\\(', returnBegin: true, end: /[{;=]/,
  75. excludeEnd: true,
  76. keywords: KEYWORDS,
  77. contains: [
  78. {
  79. begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(', returnBegin: true,
  80. relevance: 0,
  81. contains: [hljs.UNDERSCORE_TITLE_MODE]
  82. },
  83. {
  84. className: 'params',
  85. begin: /\(/, end: /\)/,
  86. keywords: KEYWORDS,
  87. relevance: 0,
  88. contains: [
  89. hljs.APOS_STRING_MODE,
  90. hljs.QUOTE_STRING_MODE,
  91. hljs.C_NUMBER_MODE,
  92. hljs.C_BLOCK_COMMENT_MODE
  93. ]
  94. },
  95. hljs.C_LINE_COMMENT_MODE,
  96. hljs.C_BLOCK_COMMENT_MODE
  97. ]
  98. },
  99. JAVA_NUMBER_MODE,
  100. {
  101. className: 'meta', begin: '@[A-Za-z]+'
  102. }
  103. ]
  104. };
  105. };