UNPKG

2.52 kBJavaScriptView Raw
1/*
2Language: OCaml
3Author: Mehdi Dogguy <mehdi@dogguy.org>
4Contributors: Nicolas Braud-Santoni <nicolas.braud-santoni@ens-cachan.fr>, Mickael Delahaye <mickael.delahaye@gmail.com>
5Description: OCaml language definition.
6Website: https://ocaml.org
7Category: functional
8*/
9
10function 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 { contains: [ 'self' ] }
44 ),
45 { /* type variable */
46 className: 'symbol',
47 begin: '\'[A-Za-z_](?!\')[\\w\']*'
48 /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
49 },
50 { /* polymorphic variant */
51 className: 'type',
52 begin: '`[A-Z][\\w\']*'
53 },
54 { /* module or constructor */
55 className: 'type',
56 begin: '\\b[A-Z][\\w\']*',
57 relevance: 0
58 },
59 { /* don't color identifiers, but safely catch all identifiers with ' */
60 begin: '[a-z_]\\w*\'[\\w\']*',
61 relevance: 0
62 },
63 hljs.inherit(hljs.APOS_STRING_MODE, {
64 className: 'string',
65 relevance: 0
66 }),
67 hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
68 {
69 className: 'number',
70 begin:
71 '\\b(0[xX][a-fA-F0-9_]+[Lln]?|'
72 + '0[oO][0-7_]+[Lln]?|'
73 + '0[bB][01_]+[Lln]?|'
74 + '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
75 relevance: 0
76 },
77 { begin: /->/ // relevance booster
78 }
79 ]
80 };
81}
82
83module.exports = ocaml;