UNPKG

2.52 kBJavaScriptView Raw
1/*
2Language: Elm
3Author: Janis Voigtlaender <janis.voigtlaender@gmail.com>
4Website: https://elm-lang.org
5Category: functional
6*/
7
8/** @type LanguageFn */
9function elm(hljs) {
10 const COMMENT = { variants: [
11 hljs.COMMENT('--', '$'),
12 hljs.COMMENT(
13 /\{-/,
14 /-\}/,
15 { contains: [ 'self' ] }
16 )
17 ] };
18
19 const CONSTRUCTOR = {
20 className: 'type',
21 begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (built-in, infix).
22 relevance: 0
23 };
24
25 const LIST = {
26 begin: '\\(',
27 end: '\\)',
28 illegal: '"',
29 contains: [
30 {
31 className: 'type',
32 begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
33 },
34 COMMENT
35 ]
36 };
37
38 const RECORD = {
39 begin: /\{/,
40 end: /\}/,
41 contains: LIST.contains
42 };
43
44 const CHARACTER = {
45 className: 'string',
46 begin: '\'\\\\?.',
47 end: '\'',
48 illegal: '.'
49 };
50
51 const KEYWORDS = [
52 "let",
53 "in",
54 "if",
55 "then",
56 "else",
57 "case",
58 "of",
59 "where",
60 "module",
61 "import",
62 "exposing",
63 "type",
64 "alias",
65 "as",
66 "infix",
67 "infixl",
68 "infixr",
69 "port",
70 "effect",
71 "command",
72 "subscription"
73 ];
74
75 return {
76 name: 'Elm',
77 keywords: KEYWORDS,
78 contains: [
79
80 // Top-level constructions.
81
82 {
83 beginKeywords: 'port effect module',
84 end: 'exposing',
85 keywords: 'port effect module where command subscription exposing',
86 contains: [
87 LIST,
88 COMMENT
89 ],
90 illegal: '\\W\\.|;'
91 },
92 {
93 begin: 'import',
94 end: '$',
95 keywords: 'import as exposing',
96 contains: [
97 LIST,
98 COMMENT
99 ],
100 illegal: '\\W\\.|;'
101 },
102 {
103 begin: 'type',
104 end: '$',
105 keywords: 'type alias',
106 contains: [
107 CONSTRUCTOR,
108 LIST,
109 RECORD,
110 COMMENT
111 ]
112 },
113 {
114 beginKeywords: 'infix infixl infixr',
115 end: '$',
116 contains: [
117 hljs.C_NUMBER_MODE,
118 COMMENT
119 ]
120 },
121 {
122 begin: 'port',
123 end: '$',
124 keywords: 'port',
125 contains: [ COMMENT ]
126 },
127
128 // Literals and names.
129 CHARACTER,
130 hljs.QUOTE_STRING_MODE,
131 hljs.C_NUMBER_MODE,
132 CONSTRUCTOR,
133 hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }),
134 COMMENT,
135
136 { // No markup, relevance booster
137 begin: '->|<-' }
138 ],
139 illegal: /;/
140 };
141}
142
143module.exports = elm;