elm.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Language: Elm
  3. Author: Janis Voigtlaender <janis.voigtlaender@gmail.com>
  4. Website: https://elm-lang.org
  5. Category: functional
  6. */
  7. function elm(hljs) {
  8. var COMMENT = {
  9. variants: [
  10. hljs.COMMENT('--', '$'),
  11. hljs.COMMENT(
  12. '{-',
  13. '-}',
  14. {
  15. contains: ['self']
  16. }
  17. )
  18. ]
  19. };
  20. var CONSTRUCTOR = {
  21. className: 'type',
  22. begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (built-in, infix).
  23. relevance: 0
  24. };
  25. var LIST = {
  26. begin: '\\(', end: '\\)',
  27. illegal: '"',
  28. contains: [
  29. {className: 'type', begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'},
  30. COMMENT
  31. ]
  32. };
  33. var RECORD = {
  34. begin: '{', end: '}',
  35. contains: LIST.contains
  36. };
  37. var CHARACTER = {
  38. className: 'string',
  39. begin: '\'\\\\?.', end: '\'',
  40. illegal: '.'
  41. };
  42. return {
  43. name: 'Elm',
  44. keywords:
  45. 'let in if then else case of where module import exposing ' +
  46. 'type alias as infix infixl infixr port effect command subscription',
  47. contains: [
  48. // Top-level constructions.
  49. {
  50. beginKeywords: 'port effect module', end: 'exposing',
  51. keywords: 'port effect module where command subscription exposing',
  52. contains: [LIST, COMMENT],
  53. illegal: '\\W\\.|;'
  54. },
  55. {
  56. begin: 'import', end: '$',
  57. keywords: 'import as exposing',
  58. contains: [LIST, COMMENT],
  59. illegal: '\\W\\.|;'
  60. },
  61. {
  62. begin: 'type', end: '$',
  63. keywords: 'type alias',
  64. contains: [CONSTRUCTOR, LIST, RECORD, COMMENT]
  65. },
  66. {
  67. beginKeywords: 'infix infixl infixr', end: '$',
  68. contains: [hljs.C_NUMBER_MODE, COMMENT]
  69. },
  70. {
  71. begin: 'port', end: '$',
  72. keywords: 'port',
  73. contains: [COMMENT]
  74. },
  75. // Literals and names.
  76. CHARACTER,
  77. hljs.QUOTE_STRING_MODE,
  78. hljs.C_NUMBER_MODE,
  79. CONSTRUCTOR,
  80. hljs.inherit(hljs.TITLE_MODE, {begin: '^[_a-z][\\w\']*'}),
  81. COMMENT,
  82. {begin: '->|<-'} // No markup, relevance booster
  83. ],
  84. illegal: /;/
  85. };
  86. }
  87. module.exports = elm;