ocaml.js 2.2 KB

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