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