ocaml.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Language: OCaml
  3. Author: Mehdi Dogguy <[email protected]>
  4. Contributors: Nicolas Braud-Santoni <[email protected]>, Mickael Delahaye <[email protected]>
  5. Description: OCaml language definition.
  6. Category: functional
  7. */
  8. function(hljs) {
  9. /* missing support for heredoc-like string (OCaml 4.0.2+) */
  10. return {
  11. aliases: ['ml'],
  12. keywords: {
  13. keyword:
  14. 'and as assert asr begin class constraint do done downto else end ' +
  15. 'exception external for fun function functor if in include ' +
  16. 'inherit! inherit initializer land lazy let lor lsl lsr lxor match method!|10 method ' +
  17. 'mod module mutable new object of open! open or private rec sig struct ' +
  18. 'then to try type val! val virtual when while with ' +
  19. /* camlp4 */
  20. 'parser value',
  21. built_in:
  22. /* built-in types */
  23. 'array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 string unit ' +
  24. /* (some) types in Pervasives */
  25. 'in_channel out_channel ref',
  26. literal:
  27. 'true false'
  28. },
  29. illegal: /\/\/|>>/,
  30. lexemes: '[a-z_]\\w*!?',
  31. contains: [
  32. {
  33. className: 'literal',
  34. begin: '\\[(\\|\\|)?\\]|\\(\\)',
  35. relevance: 0
  36. },
  37. hljs.COMMENT(
  38. '\\(\\*',
  39. '\\*\\)',
  40. {
  41. contains: ['self']
  42. }
  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\']*', relevance: 0
  60. },
  61. hljs.inherit(hljs.APOS_STRING_MODE, {className: 'string', relevance: 0}),
  62. hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null}),
  63. {
  64. className: 'number',
  65. begin:
  66. '\\b(0[xX][a-fA-F0-9_]+[Lln]?|' +
  67. '0[oO][0-7_]+[Lln]?|' +
  68. '0[bB][01_]+[Lln]?|' +
  69. '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
  70. relevance: 0
  71. },
  72. {
  73. begin: /[-=]>/ // relevance booster
  74. }
  75. ]
  76. }
  77. }