/
scala.js
172 lines (160 loc) · 3.41 KB
/
scala.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Language: Scala
Category: functional
Author: Jan Berkel <jan.berkel@gmail.com>
Contributors: Erik Osheim <d_m@plastic-idolatry.com>
Website: https://www.scala-lang.org
*/
export default function(hljs) {
const ANNOTATION = {
className: 'meta',
begin: '@[A-Za-z]+'
};
// used in strings for escaping/interpolation/substitution
const SUBST = {
className: 'subst',
variants: [
{
begin: '\\$[A-Za-z0-9_]+'
},
{
begin: /\$\{/,
end: /\}/
}
]
};
const STRING = {
className: 'string',
variants: [
{
begin: '"""',
end: '"""'
},
{
begin: '"',
end: '"',
illegal: '\\n',
contains: [ hljs.BACKSLASH_ESCAPE ]
},
{
begin: '[a-z]+"',
end: '"',
illegal: '\\n',
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
},
{
className: 'string',
begin: '[a-z]+"""',
end: '"""',
contains: [ SUBST ],
relevance: 10
}
]
};
const TYPE = {
className: 'type',
begin: '\\b[A-Z][A-Za-z0-9_]*',
relevance: 0
};
const NAME = {
className: 'title',
begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,
relevance: 0
};
const CLASS = {
className: 'class',
beginKeywords: 'class object trait type',
end: /[:={\[\n;]/,
excludeEnd: true,
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
{
beginKeywords: 'extends with',
relevance: 10
},
{
begin: /\[/,
end: /\]/,
excludeBegin: true,
excludeEnd: true,
relevance: 0,
contains: [ TYPE ]
},
{
className: 'params',
begin: /\(/,
end: /\)/,
excludeBegin: true,
excludeEnd: true,
relevance: 0,
contains: [ TYPE ]
},
NAME
]
};
const METHOD = {
className: 'function',
beginKeywords: 'def',
end: /[:={\[(\n;]/,
excludeEnd: true,
contains: [ NAME ]
};
const EXTENSION = {
begin: [
/^\s*/, // Is first token on the line
'extension',
/\s+(?=[[(])/, // followed by at least one space and `[` or `(`
],
beginScope: {
2: "keyword",
}
};
/** Capture end marker followed by extension.
* `extension` is the only marker that follows an `end` that cannot be captured by another rule.
*/
const EXTENSION_END = {
begin: [
/^\s*/, // Is first token on the line
/end/,
/\s+/,
/extension\b/,
],
beginScope: {
2: "keyword",
4: "keyword",
}
};
const END = {
begin: [
/^\s*/, // Is first token on the line
/end\b/,
],
beginScope: {
2: "keyword",
}
};
return {
name: 'Scala',
keywords: {
literal: 'true false null',
keyword: 'type yield lazy override def with val var sealed abstract private trait object if then forSome for while do throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit export enum given'
},
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
STRING,
TYPE,
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
EXTENSION,
EXTENSION_END,
END,
ANNOTATION
]
};
}