reasonml.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Language: ReasonML
  3. Description: Reason lets you write simple, fast and quality type safe code while leveraging both the JavaScript & OCaml ecosystems.
  4. Website: https://reasonml.github.io
  5. Author: Gidi Meir Morris <oss@gidi.io>
  6. Category: functional
  7. */
  8. function reasonml(hljs) {
  9. const BUILT_IN_TYPES = [
  10. "array",
  11. "bool",
  12. "bytes",
  13. "char",
  14. "exn|5",
  15. "float",
  16. "int",
  17. "int32",
  18. "int64",
  19. "list",
  20. "lazy_t|5",
  21. "nativeint|5",
  22. "ref",
  23. "string",
  24. "unit",
  25. ];
  26. return {
  27. name: 'ReasonML',
  28. aliases: [ 're' ],
  29. keywords: {
  30. $pattern: /[a-z_]\w*!?/,
  31. keyword: [
  32. "and",
  33. "as",
  34. "asr",
  35. "assert",
  36. "begin",
  37. "class",
  38. "constraint",
  39. "do",
  40. "done",
  41. "downto",
  42. "else",
  43. "end",
  44. "esfun",
  45. "exception",
  46. "external",
  47. "for",
  48. "fun",
  49. "function",
  50. "functor",
  51. "if",
  52. "in",
  53. "include",
  54. "inherit",
  55. "initializer",
  56. "land",
  57. "lazy",
  58. "let",
  59. "lor",
  60. "lsl",
  61. "lsr",
  62. "lxor",
  63. "mod",
  64. "module",
  65. "mutable",
  66. "new",
  67. "nonrec",
  68. "object",
  69. "of",
  70. "open",
  71. "or",
  72. "pri",
  73. "pub",
  74. "rec",
  75. "sig",
  76. "struct",
  77. "switch",
  78. "then",
  79. "to",
  80. "try",
  81. "type",
  82. "val",
  83. "virtual",
  84. "when",
  85. "while",
  86. "with",
  87. ],
  88. built_in: BUILT_IN_TYPES,
  89. literal: ["true", "false"],
  90. },
  91. illegal: /(:-|:=|\$\{|\+=)/,
  92. contains: [
  93. {
  94. scope: 'literal',
  95. match: /\[(\|\|)?\]|\(\)/,
  96. relevance: 0
  97. },
  98. hljs.C_LINE_COMMENT_MODE,
  99. hljs.COMMENT(/\/\*/, /\*\//, { illegal: /^(#,\/\/)/ }),
  100. { /* type variable */
  101. scope: 'symbol',
  102. match: /\'[A-Za-z_](?!\')[\w\']*/
  103. /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
  104. },
  105. { /* polymorphic variant */
  106. scope: 'type',
  107. match: /`[A-Z][\w\']*/
  108. },
  109. { /* module or constructor */
  110. scope: 'type',
  111. match: /\b[A-Z][\w\']*/,
  112. relevance: 0
  113. },
  114. { /* don't color identifiers, but safely catch all identifiers with ' */
  115. match: /[a-z_]\w*\'[\w\']*/,
  116. relevance: 0
  117. },
  118. {
  119. scope: 'operator',
  120. match: /\s+(\|\||\+[\+\.]?|\*[\*\/\.]?|\/[\.]?|\.\.\.|\|>|&&|===?)\s+/,
  121. relevance: 0
  122. },
  123. hljs.inherit(hljs.APOS_STRING_MODE, {
  124. scope: 'string',
  125. relevance: 0
  126. }),
  127. hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
  128. {
  129. scope: 'number',
  130. variants: [
  131. { match: /\b0[xX][a-fA-F0-9_]+[Lln]?/ },
  132. { match: /\b0[oO][0-7_]+[Lln]?/ },
  133. { match: /\b0[bB][01_]+[Lln]?/ },
  134. { match: /\b[0-9][0-9_]*([Lln]|(\.[0-9_]*)?([eE][-+]?[0-9_]+)?)/ },
  135. ],
  136. relevance: 0
  137. },
  138. ]
  139. };
  140. }
  141. export { reasonml as default };