elm.js 1.9 KB

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