scala.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. module.exports = function(hljs) {
  2. var ANNOTATION = { className: 'meta', begin: '@[A-Za-z]+' };
  3. // used in strings for escaping/interpolation/substitution
  4. var SUBST = {
  5. className: 'subst',
  6. variants: [
  7. {begin: '\\$[A-Za-z0-9_]+'},
  8. {begin: '\\${', end: '}'}
  9. ]
  10. };
  11. var STRING = {
  12. className: 'string',
  13. variants: [
  14. {
  15. begin: '"', end: '"',
  16. illegal: '\\n',
  17. contains: [hljs.BACKSLASH_ESCAPE]
  18. },
  19. {
  20. begin: '"""', end: '"""',
  21. relevance: 10
  22. },
  23. {
  24. begin: '[a-z]+"', end: '"',
  25. illegal: '\\n',
  26. contains: [hljs.BACKSLASH_ESCAPE, SUBST]
  27. },
  28. {
  29. className: 'string',
  30. begin: '[a-z]+"""', end: '"""',
  31. contains: [SUBST],
  32. relevance: 10
  33. }
  34. ]
  35. };
  36. var SYMBOL = {
  37. className: 'symbol',
  38. begin: '\'\\w[\\w\\d_]*(?!\')'
  39. };
  40. var TYPE = {
  41. className: 'type',
  42. begin: '\\b[A-Z][A-Za-z0-9_]*',
  43. relevance: 0
  44. };
  45. var NAME = {
  46. className: 'title',
  47. begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,
  48. relevance: 0
  49. };
  50. var CLASS = {
  51. className: 'class',
  52. beginKeywords: 'class object trait type',
  53. end: /[:={\[\n;]/,
  54. excludeEnd: true,
  55. contains: [
  56. {
  57. beginKeywords: 'extends with',
  58. relevance: 10
  59. },
  60. {
  61. begin: /\[/,
  62. end: /\]/,
  63. excludeBegin: true,
  64. excludeEnd: true,
  65. relevance: 0,
  66. contains: [TYPE]
  67. },
  68. {
  69. className: 'params',
  70. begin: /\(/,
  71. end: /\)/,
  72. excludeBegin: true,
  73. excludeEnd: true,
  74. relevance: 0,
  75. contains: [TYPE]
  76. },
  77. NAME
  78. ]
  79. };
  80. var METHOD = {
  81. className: 'function',
  82. beginKeywords: 'def',
  83. end: /[:={\[(\n;]/,
  84. excludeEnd: true,
  85. contains: [NAME]
  86. };
  87. return {
  88. keywords: {
  89. literal: 'true false null',
  90. keyword: 'type yield lazy override def with val var sealed abstract private trait object if forSome for while throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit'
  91. },
  92. contains: [
  93. hljs.C_LINE_COMMENT_MODE,
  94. hljs.C_BLOCK_COMMENT_MODE,
  95. STRING,
  96. SYMBOL,
  97. TYPE,
  98. METHOD,
  99. CLASS,
  100. hljs.C_NUMBER_MODE,
  101. ANNOTATION
  102. ]
  103. };
  104. };