-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
dart.js
176 lines (170 loc) · 3.72 KB
/
dart.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
173
174
175
176
/*
Language: Dart
Requires: markdown.js
Author: Maxim Dikun <dikmax@gmail.com>
Description: Dart a modern, object-oriented language developed by Google. For more information see https://www.dartlang.org/
Website: https://dart.dev
Category: scripting
*/
export default function(hljs) {
const SUBST = {
className: 'subst',
variants: [{
begin: '\\$[A-Za-z0-9_]+'
}],
};
const BRACED_SUBST = {
className: 'subst',
variants: [{
begin: /\$\{/,
end: /\}/
}],
keywords: 'true false null this is new super',
};
const STRING = {
className: 'string',
variants: [{
begin: 'r\'\'\'',
end: '\'\'\''
},
{
begin: 'r"""',
end: '"""'
},
{
begin: 'r\'',
end: '\'',
illegal: '\\n'
},
{
begin: 'r"',
end: '"',
illegal: '\\n'
},
{
begin: '\'\'\'',
end: '\'\'\'',
contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST]
},
{
begin: '"""',
end: '"""',
contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST]
},
{
begin: '\'',
end: '\'',
illegal: '\\n',
contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST]
},
{
begin: '"',
end: '"',
illegal: '\\n',
contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST]
}
]
};
BRACED_SUBST.contains = [
hljs.C_NUMBER_MODE, STRING
];
const BUILT_IN_TYPES = [
// dart:core
'Comparable',
'DateTime',
'Duration',
'Function',
'Iterable',
'Iterator',
'List',
'Map',
'Match',
'Object',
'Pattern',
'RegExp',
'Set',
'Stopwatch',
'String',
'StringBuffer',
'StringSink',
'Symbol',
'Type',
'Uri',
'bool',
'double',
'int',
'num',
// dart:html
'Element',
'ElementList',
];
const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`);
const KEYWORDS = {
keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' +
'dynamic else enum export extends extension external factory false final finally for Function get hide if ' +
'implements import in inferface is late library mixin new null on operator part required rethrow return set ' +
'show static super switch sync this throw true try typedef var void while with yield',
built_in:
BUILT_IN_TYPES
.concat(NULLABLE_BUILT_IN_TYPES)
.concat([
// dart:core
'Never',
'Null',
'dynamic',
'print',
// dart:html
'document',
'querySelector',
'querySelectorAll',
'window',
]).join(' '),
$pattern: /[A-Za-z][A-Za-z0-9_]*\??/
};
return {
name: 'Dart',
keywords: KEYWORDS,
contains: [
STRING,
hljs.COMMENT(
'/\\*\\*',
'\\*/', {
subLanguage: 'markdown',
relevance:0
}
),
hljs.COMMENT(
'///+\\s*',
'$', {
contains: [{
subLanguage: 'markdown',
begin: '.',
end: '$',
relevance:0
}]
}
),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
{
className: 'class',
beginKeywords: 'class interface',
end: /\{/,
excludeEnd: true,
contains: [{
beginKeywords: 'extends implements'
},
hljs.UNDERSCORE_TITLE_MODE
]
},
hljs.C_NUMBER_MODE,
{
className: 'meta',
begin: '@[A-Za-z]+'
},
{
begin: '=>' // No markup, just a relevance booster
}
]
};
}