You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
79 lines
2.3 KiB
(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));
|
|
|