OLD | NEW |
| (Empty) |
1 // Copyright (C) 2013 Google Inc. | |
2 // | |
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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
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. | |
14 | |
15 | |
16 | |
17 /** | |
18 * @fileoverview | |
19 * Registers a language handler Dart. | |
20 * Loosely structured based on the DartLexer in Pygments: http://pygments.org/. | |
21 * | |
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> | |
25 * | |
26 * @author armstrong.timothy@gmail.com | |
27 */ | |
28 | |
29 PR['registerLangHandler']( | |
30 PR['createSimpleLexer']( | |
31 [ | |
32 // Whitespace. | |
33 [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'] | |
34 ], | |
35 [ | |
36 // Script tag. | |
37 [PR['PR_COMMENT'], /^#!(?:.*)/], | |
38 | |
39 // `import`, `library`, `part of`, `part`, `as`, `show`, and `hide` | |
40 // keywords. | |
41 [PR['PR_KEYWORD'], /^\b(?:import|library|part of|part|as|show|hide)\b/i], | |
42 | |
43 // Single-line comments. | |
44 [PR['PR_COMMENT'], /^\/\/(?:.*)/], | |
45 | |
46 // Multiline comments. | |
47 [PR['PR_COMMENT'], /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//], // */ | |
48 | |
49 // `class` and `interface` keywords. | |
50 [PR['PR_KEYWORD'], /^\b(?:class|interface)\b/i], | |
51 | |
52 // General keywords. | |
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], | |
54 | |
55 // Declaration keywords. | |
56 [PR['PR_KEYWORD'], /^\b(?:abstract|const|extends|factory|final|get|impleme
nts|native|operator|set|static|typedef|var)\b/i], | |
57 | |
58 // Keywords for types. | |
59 [PR['PR_TYPE'], /^\b(?:bool|double|Dynamic|int|num|Object|String|void)\b/i
], | |
60 | |
61 // Keywords for constants. | |
62 [PR['PR_KEYWORD'], /^\b(?:false|null|true)\b/i], | |
63 | |
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}/], | |
67 | |
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])*?[^\\]\")/], | |
71 | |
72 // Identifiers. | |
73 [PR['PR_PLAIN'], /^[a-z_$][a-z0-9_]*/i], | |
74 | |
75 // Operators. | |
76 [PR['PR_PUNCTUATION'], /^[~!%^&*+=|?:<>/-]/], | |
77 | |
78 // Hex numbers. | |
79 [PR['PR_LITERAL'], /^\b0x[0-9a-f]+/i], | |
80 | |
81 // Decimal numbers. | |
82 [PR['PR_LITERAL'], /^\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i], | |
83 [PR['PR_LITERAL'], /^\b\.\d+(?:e[+-]?\d+)?/i], | |
84 | |
85 // Punctuation. | |
86 [PR['PR_PUNCTUATION'], /^[(){}\[\],.;]/] | |
87 ]), | |
88 ['dart']); | |
OLD | NEW |