UNPKG

2.28 kBJavaScriptView Raw
1/*
2Language: SML (Standard ML)
3Author: Edwin Dalorzo <edwin@dalorzo.org>
4Description: SML language definition.
5Website: https://www.smlnj.org
6Origin: ocaml.js
7Category: functional
8*/
9function sml(hljs) {
10 return {
11 name: 'SML (Standard ML)',
12 aliases: [ 'ml' ],
13 keywords: {
14 $pattern: '[a-z_]\\w*!?',
15 keyword:
16 /* according to Definition of Standard ML 97 */
17 'abstype and andalso as case datatype do else end eqtype ' +
18 'exception fn fun functor handle if in include infix infixr ' +
19 'let local nonfix of op open orelse raise rec sharing sig ' +
20 'signature struct structure then type val with withtype where while',
21 built_in:
22 /* built-in types according to basis library */
23 'array bool char exn int list option order real ref string substring vector unit word',
24 literal:
25 'true false NONE SOME LESS EQUAL GREATER nil'
26 },
27 illegal: /\/\/|>>/,
28 contains: [
29 {
30 className: 'literal',
31 begin: /\[(\|\|)?\]|\(\)/,
32 relevance: 0
33 },
34 hljs.COMMENT(
35 '\\(\\*',
36 '\\*\\)',
37 {
38 contains: [ 'self' ]
39 }
40 ),
41 { /* type variable */
42 className: 'symbol',
43 begin: '\'[A-Za-z_](?!\')[\\w\']*'
44 /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
45 },
46 { /* polymorphic variant */
47 className: 'type',
48 begin: '`[A-Z][\\w\']*'
49 },
50 { /* module or constructor */
51 className: 'type',
52 begin: '\\b[A-Z][\\w\']*',
53 relevance: 0
54 },
55 { /* don't color identifiers, but safely catch all identifiers with ' */
56 begin: '[a-z_]\\w*\'[\\w\']*'
57 },
58 hljs.inherit(hljs.APOS_STRING_MODE, {
59 className: 'string',
60 relevance: 0
61 }),
62 hljs.inherit(hljs.QUOTE_STRING_MODE, {
63 illegal: null
64 }),
65 {
66 className: 'number',
67 begin:
68 '\\b(0[xX][a-fA-F0-9_]+[Lln]?|' +
69 '0[oO][0-7_]+[Lln]?|' +
70 '0[bB][01_]+[Lln]?|' +
71 '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
72 relevance: 0
73 },
74 {
75 begin: /[-=]>/ // relevance booster
76 }
77 ]
78 };
79}
80
81export { sml as default };