1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = sml
|
---|
4 | sml.displayName = 'sml'
|
---|
5 | sml.aliases = ['smlnj']
|
---|
6 | function sml(Prism) {
|
---|
7 | // https://smlfamily.github.io/sml97-defn.pdf
|
---|
8 | // https://people.mpi-sws.org/~rossberg/sml.html
|
---|
9 | ;(function (Prism) {
|
---|
10 | var keywords =
|
---|
11 | /\b(?:abstype|and|andalso|as|case|datatype|do|else|end|eqtype|exception|fn|fun|functor|handle|if|in|include|infix|infixr|let|local|nonfix|of|op|open|orelse|raise|rec|sharing|sig|signature|struct|structure|then|type|val|where|while|with|withtype)\b/i
|
---|
12 | Prism.languages.sml = {
|
---|
13 | // allow one level of nesting
|
---|
14 | comment:
|
---|
15 | /\(\*(?:[^*(]|\*(?!\))|\((?!\*)|\(\*(?:[^*(]|\*(?!\))|\((?!\*))*\*\))*\*\)/,
|
---|
16 | string: {
|
---|
17 | pattern: /#?"(?:[^"\\]|\\.)*"/,
|
---|
18 | greedy: true
|
---|
19 | },
|
---|
20 | 'class-name': [
|
---|
21 | {
|
---|
22 | // This is only an approximation since the real grammar is context-free
|
---|
23 | //
|
---|
24 | // Why the main loop so complex?
|
---|
25 | // The main loop is approximately the same as /(?:\s*(?:[*,]|->)\s*<TERMINAL>)*/ which is, obviously, a lot
|
---|
26 | // simpler. The difference is that if a comma is the last iteration of the loop, then the terminal must be
|
---|
27 | // followed by a long identifier.
|
---|
28 | pattern: RegExp(
|
---|
29 | /((?:^|[^:]):\s*)<TERMINAL>(?:\s*(?:(?:\*|->)\s*<TERMINAL>|,\s*<TERMINAL>(?:(?=<NOT-LAST>)|(?!<NOT-LAST>)\s+<LONG-ID>)))*/.source
|
---|
30 | .replace(/<NOT-LAST>/g, function () {
|
---|
31 | return /\s*(?:[*,]|->)/.source
|
---|
32 | })
|
---|
33 | .replace(/<TERMINAL>/g, function () {
|
---|
34 | return /(?:'[\w']*|<LONG-ID>|\((?:[^()]|\([^()]*\))*\)|\{(?:[^{}]|\{[^{}]*\})*\})(?:\s+<LONG-ID>)*/
|
---|
35 | .source
|
---|
36 | })
|
---|
37 | .replace(/<LONG-ID>/g, function () {
|
---|
38 | return /(?!<KEYWORD>)[a-z\d_][\w'.]*/.source
|
---|
39 | })
|
---|
40 | .replace(/<KEYWORD>/g, function () {
|
---|
41 | return keywords.source
|
---|
42 | }),
|
---|
43 | 'i'
|
---|
44 | ),
|
---|
45 | lookbehind: true,
|
---|
46 | greedy: true,
|
---|
47 | inside: null // see below
|
---|
48 | },
|
---|
49 | {
|
---|
50 | pattern:
|
---|
51 | /((?:^|[^\w'])(?:datatype|exception|functor|signature|structure|type)\s+)[a-z_][\w'.]*/i,
|
---|
52 | lookbehind: true
|
---|
53 | }
|
---|
54 | ],
|
---|
55 | function: {
|
---|
56 | pattern: /((?:^|[^\w'])fun\s+)[a-z_][\w'.]*/i,
|
---|
57 | lookbehind: true
|
---|
58 | },
|
---|
59 | keyword: keywords,
|
---|
60 | variable: {
|
---|
61 | pattern: /(^|[^\w'])'[\w']*/,
|
---|
62 | lookbehind: true
|
---|
63 | },
|
---|
64 | number: /~?\b(?:\d+(?:\.\d+)?(?:e~?\d+)?|0x[\da-f]+)\b/i,
|
---|
65 | word: {
|
---|
66 | pattern: /\b0w(?:\d+|x[\da-f]+)\b/i,
|
---|
67 | alias: 'constant'
|
---|
68 | },
|
---|
69 | boolean: /\b(?:false|true)\b/i,
|
---|
70 | operator: /\.\.\.|:[>=:]|=>?|->|[<>]=?|[!+\-*/^#|@~]/,
|
---|
71 | punctuation: /[(){}\[\].:,;]/
|
---|
72 | }
|
---|
73 | Prism.languages.sml['class-name'][0].inside = Prism.languages.sml
|
---|
74 | Prism.languages.smlnj = Prism.languages.sml
|
---|
75 | })(Prism)
|
---|
76 | }
|
---|