1 // Copyright (C) 2013 Google Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
19 * Registers a language handler Dart.
20 * Loosely structured based on the DartLexer in Pygments: http://pygments.org/.
22 * To use, include prettify.js and this file in your HTML page.
23 * Then put your code in an HTML tag like
24 * <pre class="prettyprint lang-dart">(Dart code)</pre>
26 * @author armstrong.timothy@gmail.com
29 PR
['registerLangHandler'](
30 PR
['createSimpleLexer'](
33 [PR
['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0']
37 [PR
['PR_COMMENT'], /^#!(?:.*)/],
39 // `import`, `library`, `part of`, `part`, `as`, `show`, and `hide`
41 [PR
['PR_KEYWORD'], /^\b(?:import|library|part of|part|as|show|hide)\b/i],
43 // Single-line comments.
44 [PR
['PR_COMMENT'], /^\/\/(?:.*)/],
46 // Multiline comments.
47 [PR
['PR_COMMENT'], /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//], // */
49 // `class` and `interface` keywords.
50 [PR
['PR_KEYWORD'], /^\b(?:class|interface)\b/i],
53 [PR
['PR_KEYWORD'], /^\b(?:assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\b/i],
55 // Declaration keywords.
56 [PR
['PR_KEYWORD'], /^\b(?:abstract|const|extends|factory|final|get|implements|native|operator|set|static|typedef|var)\b/i],
58 // Keywords for types.
59 [PR
['PR_TYPE'], /^\b(?:bool|double|Dynamic|int|num|Object|String|void)\b/i],
61 // Keywords for constants.
62 [PR
['PR_KEYWORD'], /^\b(?:false|null|true)\b/i],
64 // Multiline strings, single- and double-quoted.
65 [PR
['PR_STRING'], /^r?[\']{3}[\s|\S]*?[^\\][\']{3}/],
66 [PR
['PR_STRING'], /^r?[\"]{3}[\s|\S]*?[^\\][\"]{3}/],
68 // Normal and raw strings, single- and double-quoted.
69 [PR
['PR_STRING'], /^r?\'(\'|(?:[^\n\r\f])*?[^\\]\')/],
70 [PR
['PR_STRING'], /^r?\"(\"|(?:[^\n\r\f])*?[^\\]\")/],
73 [PR
['PR_PLAIN'], /^[a-z_$][a-z0-9_]*/i],
76 [PR
['PR_PUNCTUATION'], /^[~!%^&*+=|?:<>/-]/],
79 [PR
['PR_LITERAL'], /^\b0x[0-9a-f]+/i],
82 [PR
['PR_LITERAL'], /^\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i],
83 [PR
['PR_LITERAL'], /^\b\.\d+(?:e[+-]?\d+)?/i],
86 [PR
['PR_PUNCTUATION'], /^[(){}\[\],.;]/]