-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
dart.js
91 lines (88 loc) · 2.87 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
// @ts-nocheck
import refractorClike from './clike.js'
dart.displayName = 'dart'
dart.aliases = []
/** @type {import('../core.js').Syntax} */
export default function dart(Prism) {
Prism.register(refractorClike)
;(function (Prism) {
var keywords = [
/\b(?:async|sync|yield)\*/,
/\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extends|extension|external|factory|final|finally|for|get|hide|if|implements|import|in|interface|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/
]
// Handles named imports, such as http.Client
var packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/
.source
// based on the dart naming conventions
var className = {
pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
lookbehind: true,
inside: {
namespace: {
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
inside: {
punctuation: /\./
}
}
}
}
Prism.languages.dart = Prism.languages.extend('clike', {
'class-name': [
className,
{
// variables and parameters
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
pattern: RegExp(
packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source
),
lookbehind: true,
inside: className.inside
}
],
keyword: keywords,
operator:
/\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
})
Prism.languages.insertBefore('dart', 'string', {
'string-literal': {
pattern:
/r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/,
greedy: true,
inside: {
interpolation: {
pattern:
/((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
lookbehind: true,
inside: {
punctuation: /^\$\{?|\}$/,
expression: {
pattern: /[\s\S]+/,
inside: Prism.languages.dart
}
}
},
string: /[\s\S]+/
}
},
string: undefined
})
Prism.languages.insertBefore('dart', 'class-name', {
metadata: {
pattern: /@\w+/,
alias: 'function'
}
})
Prism.languages.insertBefore('dart', 'class-name', {
generics: {
pattern:
/<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
inside: {
'class-name': className,
keyword: keywords,
punctuation: /[<>(),.:]/,
operator: /[?&|]/
}
}
})
})(Prism)
}