ocaml.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Language: OCaml
  3. Author: Mehdi Dogguy <mehdi@dogguy.org>
  4. Contributors: Nicolas Braud-Santoni <nicolas.braud-santoni@ens-cachan.fr>, Mickael Delahaye <mickael.delahaye@gmail.com>
  5. Description: OCaml language definition.
  6. Website: https://ocaml.org
  7. Category: functional
  8. */
  9. function ocaml(hljs) {
  10. /* missing support for heredoc-like string (OCaml 4.0.2+) */
  11. return {
  12. name: 'OCaml',
  13. aliases: ['ml'],
  14. keywords: {
  15. $pattern: '[a-z_]\\w*!?',
  16. keyword:
  17. 'and as assert asr begin class constraint do done downto else end ' +
  18. 'exception external for fun function functor if in include ' +
  19. 'inherit! inherit initializer land lazy let lor lsl lsr lxor match method!|10 method ' +
  20. 'mod module mutable new object of open! open or private rec sig struct ' +
  21. 'then to try type val! val virtual when while with ' +
  22. /* camlp4 */
  23. 'parser value',
  24. built_in:
  25. /* built-in types */
  26. 'array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 string unit ' +
  27. /* (some) types in Pervasives */
  28. 'in_channel out_channel ref',
  29. literal:
  30. 'true false'
  31. },
  32. illegal: /\/\/|>>/,
  33. contains: [
  34. {
  35. className: 'literal',
  36. begin: '\\[(\\|\\|)?\\]|\\(\\)',
  37. relevance: 0
  38. },
  39. hljs.COMMENT(
  40. '\\(\\*',
  41. '\\*\\)',
  42. {
  43. contains: ['self']
  44. }
  45. ),
  46. { /* type variable */
  47. className: 'symbol',
  48. begin: '\'[A-Za-z_](?!\')[\\w\']*'
  49. /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
  50. },
  51. { /* polymorphic variant */
  52. className: 'type',
  53. begin: '`[A-Z][\\w\']*'
  54. },
  55. { /* module or constructor */
  56. className: 'type',
  57. begin: '\\b[A-Z][\\w\']*',
  58. relevance: 0
  59. },
  60. { /* don't color identifiers, but safely catch all identifiers with '*/
  61. begin: '[a-z_]\\w*\'[\\w\']*', relevance: 0
  62. },
  63. hljs.inherit(hljs.APOS_STRING_MODE, {className: 'string', relevance: 0}),
  64. hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null}),
  65. {
  66. className: 'number',
  67. begin:
  68. '\\b(0[xX][a-fA-F0-9_]+[Lln]?|' +
  69. '0[oO][0-7_]+[Lln]?|' +
  70. '0[bB][01_]+[Lln]?|' +
  71. '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
  72. relevance: 0
  73. },
  74. {
  75. begin: /->/ // relevance booster
  76. }
  77. ]
  78. }
  79. }
  80. module.exports = ocaml;