UNPKG

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