-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
reasonml.js
140 lines (140 loc) · 3 KB
/
reasonml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
Language: ReasonML
Description: Reason lets you write simple, fast and quality type safe code while leveraging both the JavaScript & OCaml ecosystems.
Website: https://reasonml.github.io
Author: Gidi Meir Morris <oss@gidi.io>
Category: functional
*/
export default function(hljs) {
const BUILT_IN_TYPES = [
"array",
"bool",
"bytes",
"char",
"exn|5",
"float",
"int",
"int32",
"int64",
"list",
"lazy_t|5",
"nativeint|5",
"ref",
"string",
"unit",
];
return {
name: 'ReasonML',
aliases: [ 're' ],
keywords: {
$pattern: /[a-z_]\w*!?/,
keyword: [
"and",
"as",
"asr",
"assert",
"begin",
"class",
"constraint",
"do",
"done",
"downto",
"else",
"end",
"esfun",
"exception",
"external",
"for",
"fun",
"function",
"functor",
"if",
"in",
"include",
"inherit",
"initializer",
"land",
"lazy",
"let",
"lor",
"lsl",
"lsr",
"lxor",
"mod",
"module",
"mutable",
"new",
"nonrec",
"object",
"of",
"open",
"or",
"pri",
"pub",
"rec",
"sig",
"struct",
"switch",
"then",
"to",
"try",
"type",
"val",
"virtual",
"when",
"while",
"with",
],
built_in: BUILT_IN_TYPES,
literal: ["true", "false"],
},
illegal: /(:-|:=|\$\{|\+=)/,
contains: [
{
scope: 'literal',
match: /\[(\|\|)?\]|\(\)/,
relevance: 0
},
hljs.C_LINE_COMMENT_MODE,
hljs.COMMENT(/\/\*/, /\*\//, { illegal: /^(#,\/\/)/ }),
{ /* type variable */
scope: 'symbol',
match: /\'[A-Za-z_](?!\')[\w\']*/
/* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
},
{ /* polymorphic variant */
scope: 'type',
match: /`[A-Z][\w\']*/
},
{ /* module or constructor */
scope: 'type',
match: /\b[A-Z][\w\']*/,
relevance: 0
},
{ /* don't color identifiers, but safely catch all identifiers with ' */
match: /[a-z_]\w*\'[\w\']*/,
relevance: 0
},
{
scope: 'operator',
match: /\s+(\|\||\+[\+\.]?|\*[\*\/\.]?|\/[\.]?|\.\.\.|\|>|&&|===?)\s+/,
relevance: 0
},
hljs.inherit(hljs.APOS_STRING_MODE, {
scope: 'string',
relevance: 0
}),
hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
{
scope: 'number',
variants: [
{ match: /\b0[xX][a-fA-F0-9_]+[Lln]?/ },
{ match: /\b0[oO][0-7_]+[Lln]?/ },
{ match: /\b0[bB][01_]+[Lln]?/ },
{ match: /\b[0-9][0-9_]*([Lln]|(\.[0-9_]*)?([eE][-+]?[0-9_]+)?)/ },
],
relevance: 0
},
]
};
}