elm.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Language: Elm
  3. Author: Janis Voigtlaender <janis.voigtlaender@gmail.com>
  4. Website: https://elm-lang.org
  5. Category: functional
  6. */
  7. /** @type LanguageFn */
  8. function elm(hljs) {
  9. const COMMENT = { variants: [
  10. hljs.COMMENT('--', '$'),
  11. hljs.COMMENT(
  12. /\{-/,
  13. /-\}/,
  14. { contains: [ 'self' ] }
  15. )
  16. ] };
  17. const CONSTRUCTOR = {
  18. className: 'type',
  19. begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (built-in, infix).
  20. relevance: 0
  21. };
  22. const LIST = {
  23. begin: '\\(',
  24. end: '\\)',
  25. illegal: '"',
  26. contains: [
  27. {
  28. className: 'type',
  29. begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
  30. },
  31. COMMENT
  32. ]
  33. };
  34. const RECORD = {
  35. begin: /\{/,
  36. end: /\}/,
  37. contains: LIST.contains
  38. };
  39. const CHARACTER = {
  40. className: 'string',
  41. begin: '\'\\\\?.',
  42. end: '\'',
  43. illegal: '.'
  44. };
  45. const KEYWORDS = [
  46. "let",
  47. "in",
  48. "if",
  49. "then",
  50. "else",
  51. "case",
  52. "of",
  53. "where",
  54. "module",
  55. "import",
  56. "exposing",
  57. "type",
  58. "alias",
  59. "as",
  60. "infix",
  61. "infixl",
  62. "infixr",
  63. "port",
  64. "effect",
  65. "command",
  66. "subscription"
  67. ];
  68. return {
  69. name: 'Elm',
  70. keywords: KEYWORDS,
  71. contains: [
  72. // Top-level constructions.
  73. {
  74. beginKeywords: 'port effect module',
  75. end: 'exposing',
  76. keywords: 'port effect module where command subscription exposing',
  77. contains: [
  78. LIST,
  79. COMMENT
  80. ],
  81. illegal: '\\W\\.|;'
  82. },
  83. {
  84. begin: 'import',
  85. end: '$',
  86. keywords: 'import as exposing',
  87. contains: [
  88. LIST,
  89. COMMENT
  90. ],
  91. illegal: '\\W\\.|;'
  92. },
  93. {
  94. begin: 'type',
  95. end: '$',
  96. keywords: 'type alias',
  97. contains: [
  98. CONSTRUCTOR,
  99. LIST,
  100. RECORD,
  101. COMMENT
  102. ]
  103. },
  104. {
  105. beginKeywords: 'infix infixl infixr',
  106. end: '$',
  107. contains: [
  108. hljs.C_NUMBER_MODE,
  109. COMMENT
  110. ]
  111. },
  112. {
  113. begin: 'port',
  114. end: '$',
  115. keywords: 'port',
  116. contains: [ COMMENT ]
  117. },
  118. // Literals and names.
  119. CHARACTER,
  120. hljs.QUOTE_STRING_MODE,
  121. hljs.C_NUMBER_MODE,
  122. CONSTRUCTOR,
  123. hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }),
  124. COMMENT,
  125. { // No markup, relevance booster
  126. begin: '->|<-' }
  127. ],
  128. illegal: /;/
  129. };
  130. }
  131. export { elm as default };