source: node_modules/highlight.js/lib/languages/dart.js@ e48199a

main
Last change on this file since e48199a was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2Language: Dart
3Requires: markdown.js
4Author: Maxim Dikun <dikmax@gmail.com>
5Description: Dart a modern, object-oriented language developed by Google. For more information see https://www.dartlang.org/
6Website: https://dart.dev
7Category: scripting
8*/
9
10/** @type LanguageFn */
11function dart(hljs) {
12 const SUBST = {
13 className: 'subst',
14 variants: [{
15 begin: '\\$[A-Za-z0-9_]+'
16 }]
17 };
18
19 const BRACED_SUBST = {
20 className: 'subst',
21 variants: [{
22 begin: /\$\{/,
23 end: /\}/
24 }],
25 keywords: 'true false null this is new super'
26 };
27
28 const STRING = {
29 className: 'string',
30 variants: [
31 {
32 begin: 'r\'\'\'',
33 end: '\'\'\''
34 },
35 {
36 begin: 'r"""',
37 end: '"""'
38 },
39 {
40 begin: 'r\'',
41 end: '\'',
42 illegal: '\\n'
43 },
44 {
45 begin: 'r"',
46 end: '"',
47 illegal: '\\n'
48 },
49 {
50 begin: '\'\'\'',
51 end: '\'\'\'',
52 contains: [
53 hljs.BACKSLASH_ESCAPE,
54 SUBST,
55 BRACED_SUBST
56 ]
57 },
58 {
59 begin: '"""',
60 end: '"""',
61 contains: [
62 hljs.BACKSLASH_ESCAPE,
63 SUBST,
64 BRACED_SUBST
65 ]
66 },
67 {
68 begin: '\'',
69 end: '\'',
70 illegal: '\\n',
71 contains: [
72 hljs.BACKSLASH_ESCAPE,
73 SUBST,
74 BRACED_SUBST
75 ]
76 },
77 {
78 begin: '"',
79 end: '"',
80 illegal: '\\n',
81 contains: [
82 hljs.BACKSLASH_ESCAPE,
83 SUBST,
84 BRACED_SUBST
85 ]
86 }
87 ]
88 };
89 BRACED_SUBST.contains = [
90 hljs.C_NUMBER_MODE,
91 STRING
92 ];
93
94 const BUILT_IN_TYPES = [
95 // dart:core
96 'Comparable',
97 'DateTime',
98 'Duration',
99 'Function',
100 'Iterable',
101 'Iterator',
102 'List',
103 'Map',
104 'Match',
105 'Object',
106 'Pattern',
107 'RegExp',
108 'Set',
109 'Stopwatch',
110 'String',
111 'StringBuffer',
112 'StringSink',
113 'Symbol',
114 'Type',
115 'Uri',
116 'bool',
117 'double',
118 'int',
119 'num',
120 // dart:html
121 'Element',
122 'ElementList'
123 ];
124 const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`);
125
126 const KEYWORDS = {
127 keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' +
128 'dynamic else enum export extends extension external factory false final finally for Function get hide if ' +
129 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' +
130 'show static super switch sync this throw true try typedef var void while with yield',
131 built_in:
132 BUILT_IN_TYPES
133 .concat(NULLABLE_BUILT_IN_TYPES)
134 .concat([
135 // dart:core
136 'Never',
137 'Null',
138 'dynamic',
139 'print',
140 // dart:html
141 'document',
142 'querySelector',
143 'querySelectorAll',
144 'window'
145 ]),
146 $pattern: /[A-Za-z][A-Za-z0-9_]*\??/
147 };
148
149 return {
150 name: 'Dart',
151 keywords: KEYWORDS,
152 contains: [
153 STRING,
154 hljs.COMMENT(
155 /\/\*\*(?!\/)/,
156 /\*\//,
157 {
158 subLanguage: 'markdown',
159 relevance: 0
160 }
161 ),
162 hljs.COMMENT(
163 /\/{3,} ?/,
164 /$/, {
165 contains: [{
166 subLanguage: 'markdown',
167 begin: '.',
168 end: '$',
169 relevance: 0
170 }]
171 }
172 ),
173 hljs.C_LINE_COMMENT_MODE,
174 hljs.C_BLOCK_COMMENT_MODE,
175 {
176 className: 'class',
177 beginKeywords: 'class interface',
178 end: /\{/,
179 excludeEnd: true,
180 contains: [
181 {
182 beginKeywords: 'extends implements'
183 },
184 hljs.UNDERSCORE_TITLE_MODE
185 ]
186 },
187 hljs.C_NUMBER_MODE,
188 {
189 className: 'meta',
190 begin: '@[A-Za-z]+'
191 },
192 {
193 begin: '=>' // No markup, just a relevance booster
194 }
195 ]
196 };
197}
198
199module.exports = dart;
Note: See TracBrowser for help on using the repository browser.