-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dart: Improved support for classes & generics (#2810)
- Loading branch information
Showing
5 changed files
with
167 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,67 @@ | ||
Prism.languages.dart = Prism.languages.extend('clike', { | ||
'string': [ | ||
{ | ||
pattern: /r?("""|''')[\s\S]*?\1/, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /r?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, | ||
greedy: true | ||
} | ||
], | ||
'keyword': [ | ||
(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|extension|external|extends|factory|final|finally|for|Function|get|hide|if|implements|interface|import|in|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/ | ||
], | ||
'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/ | ||
}); | ||
/\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extension|external|extends|factory|final|finally|for|get|hide|if|implements|interface|import|in|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.insertBefore('dart','function',{ | ||
'metadata': { | ||
pattern: /@\w+/, | ||
alias: 'symbol' | ||
} | ||
}); | ||
Prism.languages.dart = Prism.languages.extend('clike', { | ||
'string': [ | ||
{ | ||
pattern: /r?("""|''')[\s\S]*?\1/, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /r?(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/, | ||
greedy: true | ||
} | ||
], | ||
'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','function',{ | ||
'metadata': { | ||
pattern: /@\w+/, | ||
alias: 'symbol' | ||
} | ||
}); | ||
|
||
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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
class Foo with ns.Bar { | ||
const Foo(this.bar); | ||
|
||
final Bar bar; | ||
|
||
Baz<ns.Bat> baz(ns.Bat bat) { | ||
return Baz<ns.Bat>(bat); | ||
} | ||
|
||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "class"], | ||
["class-name", ["Foo"]], | ||
["keyword", "with"], | ||
["class-name", [ | ||
["namespace", [ | ||
"ns", | ||
["punctuation", "."] | ||
]], | ||
"Bar" | ||
]], | ||
["punctuation", "{"], | ||
|
||
["keyword", "const"], | ||
["class-name", ["Foo"]], | ||
["punctuation", "("], | ||
["keyword", "this"], | ||
["punctuation", "."], | ||
"bar", | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["keyword", "final"], | ||
["class-name", ["Bar"]], | ||
" bar", | ||
["punctuation", ";"], | ||
|
||
["class-name", ["Baz"]], | ||
["generics", [ | ||
["punctuation", "<"], | ||
["class-name", [ | ||
["namespace", [ | ||
"ns", | ||
["punctuation", "."] | ||
]], | ||
"Bat" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["function", "baz"], | ||
["punctuation", "("], | ||
["class-name", [ | ||
["namespace", [ | ||
"ns", | ||
["punctuation", "."] | ||
]], | ||
"Bat" | ||
]], | ||
" bat", | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["keyword", "return"], | ||
["class-name", [ | ||
"Baz" | ||
]], | ||
["generics", [ | ||
["punctuation", "<"], | ||
["class-name", [ | ||
["namespace", [ | ||
"ns", | ||
["punctuation", "."] | ||
]], | ||
"Bat" | ||
]], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "("], | ||
"bat", | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
["punctuation", "}"], | ||
|
||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks class names and generics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters