prism-ocaml.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // https://ocaml.org/manual/lex.html
  2. Prism.languages.ocaml = {
  3. 'comment': {
  4. pattern: /\(\*[\s\S]*?\*\)/,
  5. greedy: true
  6. },
  7. 'char': {
  8. pattern: /'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,
  9. greedy: true
  10. },
  11. 'string': [
  12. {
  13. pattern: /"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,
  14. greedy: true
  15. },
  16. {
  17. pattern: /\{([a-z_]*)\|[\s\S]*?\|\1\}/,
  18. greedy: true
  19. }
  20. ],
  21. 'number': [
  22. // binary and octal
  23. /\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,
  24. // hexadecimal
  25. /\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,
  26. // decimal
  27. /\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i,
  28. ],
  29. 'directive': {
  30. pattern: /\B#\w+/,
  31. alias: 'property'
  32. },
  33. 'label': {
  34. pattern: /\B~\w+/,
  35. alias: 'property'
  36. },
  37. 'type-variable': {
  38. pattern: /\B'\w+/,
  39. alias: 'function'
  40. },
  41. 'variant': {
  42. pattern: /`\w+/,
  43. alias: 'symbol'
  44. },
  45. // For the list of keywords and operators,
  46. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  47. 'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,
  48. 'boolean': /\b(?:false|true)\b/,
  49. 'operator-like-punctuation': {
  50. pattern: /\[[<>|]|[>|]\]|\{<|>\}/,
  51. alias: 'punctuation'
  52. },
  53. // Custom operators are allowed
  54. 'operator': /\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  55. 'punctuation': /;;|::|[(){}\[\].,:;#]|\b_\b/
  56. };