ocaml.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. { contains: [ 'self' ] }
  43. ),
  44. { /* type variable */
  45. className: 'symbol',
  46. begin: '\'[A-Za-z_](?!\')[\\w\']*'
  47. /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
  48. },
  49. { /* polymorphic variant */
  50. className: 'type',
  51. begin: '`[A-Z][\\w\']*'
  52. },
  53. { /* module or constructor */
  54. className: 'type',
  55. begin: '\\b[A-Z][\\w\']*',
  56. relevance: 0
  57. },
  58. { /* don't color identifiers, but safely catch all identifiers with ' */
  59. begin: '[a-z_]\\w*\'[\\w\']*',
  60. relevance: 0
  61. },
  62. hljs.inherit(hljs.APOS_STRING_MODE, {
  63. className: 'string',
  64. relevance: 0
  65. }),
  66. hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
  67. {
  68. className: 'number',
  69. begin:
  70. '\\b(0[xX][a-fA-F0-9_]+[Lln]?|'
  71. + '0[oO][0-7_]+[Lln]?|'
  72. + '0[bB][01_]+[Lln]?|'
  73. + '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
  74. relevance: 0
  75. },
  76. { begin: /->/ // relevance booster
  77. }
  78. ]
  79. };
  80. }
  81. export { ocaml as default };