elm.js 2.4 KB

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