prism-rescript.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Prism.languages.rescript = {
  2. 'comment': {
  3. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  4. greedy: true
  5. },
  6. 'char': { pattern: /'(?:[^\r\n\\]|\\(?:.|\w+))'/, greedy: true },
  7. 'string': {
  8. pattern: /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,
  9. greedy: true
  10. },
  11. 'class-name': /\b[A-Z]\w*|@[a-z.]*|#[A-Za-z]\w*|#\d/,
  12. 'function': {
  13. pattern: /[a-zA-Z]\w*(?=\()|(\.)[a-z]\w*/,
  14. lookbehind: true,
  15. },
  16. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  17. 'boolean': /\b(?:false|true)\b/,
  18. 'attr-value': /[A-Za-z]\w*(?==)/,
  19. 'constant': {
  20. pattern: /(\btype\s+)[a-z]\w*/,
  21. lookbehind: true
  22. },
  23. 'tag': {
  24. pattern: /(<)[a-z]\w*|(?:<\/)[a-z]\w*/,
  25. lookbehind: true,
  26. inside: {
  27. 'operator': /<|>|\//,
  28. },
  29. },
  30. 'keyword': /\b(?:and|as|assert|begin|bool|class|constraint|do|done|downto|else|end|exception|external|float|for|fun|function|if|in|include|inherit|initializer|int|lazy|let|method|module|mutable|new|nonrec|object|of|open|or|private|rec|string|switch|then|to|try|type|when|while|with)\b/,
  31. 'operator': /\.{3}|:[:=]?|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/,
  32. 'punctuation': /[(){}[\],;.]/
  33. };
  34. Prism.languages.insertBefore('rescript', 'string', {
  35. 'template-string': {
  36. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  37. greedy: true,
  38. inside: {
  39. 'template-punctuation': {
  40. pattern: /^`|`$/,
  41. alias: 'string'
  42. },
  43. 'interpolation': {
  44. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  45. lookbehind: true,
  46. inside: {
  47. 'interpolation-punctuation': {
  48. pattern: /^\$\{|\}$/,
  49. alias: 'tag'
  50. },
  51. rest: Prism.languages.rescript
  52. }
  53. },
  54. 'string': /[\s\S]+/
  55. }
  56. },
  57. });
  58. Prism.languages.res = Prism.languages.rescript;