scala.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Language: Scala
  3. Category: functional
  4. Author: Jan Berkel <jan.berkel@gmail.com>
  5. Contributors: Erik Osheim <d_m@plastic-idolatry.com>
  6. Website: https://www.scala-lang.org
  7. */
  8. function scala(hljs) {
  9. const ANNOTATION = {
  10. className: 'meta',
  11. begin: '@[A-Za-z]+'
  12. };
  13. // used in strings for escaping/interpolation/substitution
  14. const SUBST = {
  15. className: 'subst',
  16. variants: [
  17. {
  18. begin: '\\$[A-Za-z0-9_]+'
  19. },
  20. {
  21. begin: /\$\{/,
  22. end: /\}/
  23. }
  24. ]
  25. };
  26. const STRING = {
  27. className: 'string',
  28. variants: [
  29. {
  30. begin: '"""',
  31. end: '"""'
  32. },
  33. {
  34. begin: '"',
  35. end: '"',
  36. illegal: '\\n',
  37. contains: [ hljs.BACKSLASH_ESCAPE ]
  38. },
  39. {
  40. begin: '[a-z]+"',
  41. end: '"',
  42. illegal: '\\n',
  43. contains: [
  44. hljs.BACKSLASH_ESCAPE,
  45. SUBST
  46. ]
  47. },
  48. {
  49. className: 'string',
  50. begin: '[a-z]+"""',
  51. end: '"""',
  52. contains: [ SUBST ],
  53. relevance: 10
  54. }
  55. ]
  56. };
  57. const SYMBOL = {
  58. className: 'symbol',
  59. begin: '\'\\w[\\w\\d_]*(?!\')'
  60. };
  61. const TYPE = {
  62. className: 'type',
  63. begin: '\\b[A-Z][A-Za-z0-9_]*',
  64. relevance: 0
  65. };
  66. const NAME = {
  67. className: 'title',
  68. begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,
  69. relevance: 0
  70. };
  71. const CLASS = {
  72. className: 'class',
  73. beginKeywords: 'class object trait type',
  74. end: /[:={\[\n;]/,
  75. excludeEnd: true,
  76. contains: [
  77. hljs.C_LINE_COMMENT_MODE,
  78. hljs.C_BLOCK_COMMENT_MODE,
  79. {
  80. beginKeywords: 'extends with',
  81. relevance: 10
  82. },
  83. {
  84. begin: /\[/,
  85. end: /\]/,
  86. excludeBegin: true,
  87. excludeEnd: true,
  88. relevance: 0,
  89. contains: [ TYPE ]
  90. },
  91. {
  92. className: 'params',
  93. begin: /\(/,
  94. end: /\)/,
  95. excludeBegin: true,
  96. excludeEnd: true,
  97. relevance: 0,
  98. contains: [ TYPE ]
  99. },
  100. NAME
  101. ]
  102. };
  103. const METHOD = {
  104. className: 'function',
  105. beginKeywords: 'def',
  106. end: /[:={\[(\n;]/,
  107. excludeEnd: true,
  108. contains: [ NAME ]
  109. };
  110. return {
  111. name: 'Scala',
  112. keywords: {
  113. literal: 'true false null',
  114. 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'
  115. },
  116. contains: [
  117. hljs.C_LINE_COMMENT_MODE,
  118. hljs.C_BLOCK_COMMENT_MODE,
  119. STRING,
  120. SYMBOL,
  121. TYPE,
  122. METHOD,
  123. CLASS,
  124. hljs.C_NUMBER_MODE,
  125. ANNOTATION
  126. ]
  127. };
  128. }
  129. module.exports = scala;