]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/ocaml.js
Initial commit.
[flow-web.git] / static / highlight / languages / ocaml.js
1 /*! `ocaml` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: OCaml
8 Author: Mehdi Dogguy <mehdi@dogguy.org>
9 Contributors: Nicolas Braud-Santoni <nicolas.braud-santoni@ens-cachan.fr>, Mickael Delahaye <mickael.delahaye@gmail.com>
10 Description: OCaml language definition.
11 Website: https://ocaml.org
12 Category: functional
13 */
14
15 function ocaml(hljs) {
16 /* missing support for heredoc-like string (OCaml 4.0.2+) */
17 return {
18 name: 'OCaml',
19 aliases: [ 'ml' ],
20 keywords: {
21 $pattern: '[a-z_]\\w*!?',
22 keyword:
23 'and as assert asr begin class constraint do done downto else end '
24 + 'exception external for fun function functor if in include '
25 + 'inherit! inherit initializer land lazy let lor lsl lsr lxor match method!|10 method '
26 + 'mod module mutable new object of open! open or private rec sig struct '
27 + 'then to try type val! val virtual when while with '
28 /* camlp4 */
29 + 'parser value',
30 built_in:
31 /* built-in types */
32 'array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 string unit '
33 /* (some) types in Pervasives */
34 + 'in_channel out_channel ref',
35 literal:
36 'true false'
37 },
38 illegal: /\/\/|>>/,
39 contains: [
40 {
41 className: 'literal',
42 begin: '\\[(\\|\\|)?\\]|\\(\\)',
43 relevance: 0
44 },
45 hljs.COMMENT(
46 '\\(\\*',
47 '\\*\\)',
48 { contains: [ 'self' ] }
49 ),
50 { /* type variable */
51 className: 'symbol',
52 begin: '\'[A-Za-z_](?!\')[\\w\']*'
53 /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
54 },
55 { /* polymorphic variant */
56 className: 'type',
57 begin: '`[A-Z][\\w\']*'
58 },
59 { /* module or constructor */
60 className: 'type',
61 begin: '\\b[A-Z][\\w\']*',
62 relevance: 0
63 },
64 { /* don't color identifiers, but safely catch all identifiers with ' */
65 begin: '[a-z_]\\w*\'[\\w\']*',
66 relevance: 0
67 },
68 hljs.inherit(hljs.APOS_STRING_MODE, {
69 className: 'string',
70 relevance: 0
71 }),
72 hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
73 {
74 className: 'number',
75 begin:
76 '\\b(0[xX][a-fA-F0-9_]+[Lln]?|'
77 + '0[oO][0-7_]+[Lln]?|'
78 + '0[bB][01_]+[Lln]?|'
79 + '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
80 relevance: 0
81 },
82 { begin: /->/ // relevance booster
83 }
84 ]
85 };
86 }
87
88 return ocaml;
89
90 })();
91
92 hljs.registerLanguage('ocaml', hljsGrammar);
93 })();