1/**
2 * @license
3 * Copyright (C) 2013 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @fileoverview
20 * Registers a language handler Dart.
21 * Loosely structured based on the DartLexer in Pygments: http://pygments.org/.
22 *
23 * To use, include prettify.js and this file in your HTML page.
24 * Then put your code in an HTML tag like
25 *      <pre class="prettyprint lang-dart">(Dart code)</pre>
26 *
27 * @author armstrong.timothy@gmail.com
28 */
29
30PR['registerLangHandler'](
31  PR['createSimpleLexer'](
32    [
33      // Whitespace.
34      [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0']
35    ],
36    [
37      // Script tag.
38      [PR['PR_COMMENT'], /^#!(?:.*)/],
39
40      // `import`, `library`, `part of`, `part`, `as`, `show`, and `hide`
41      // keywords.
42      [PR['PR_KEYWORD'], /^\b(?:import|library|part of|part|as|show|hide)\b/i],
43
44      // Single-line comments.
45      [PR['PR_COMMENT'], /^\/\/(?:.*)/],
46
47      // Multiline comments.
48      [PR['PR_COMMENT'], /^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//], // */
49
50      // `class` and `interface` keywords.
51      [PR['PR_KEYWORD'], /^\b(?:class|interface)\b/i],
52
53      // General keywords.
54      [PR['PR_KEYWORD'], /^\b(?:assert|async|await|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|sync|this|throw|try|while)\b/i],
55
56      // Declaration keywords.
57      [PR['PR_KEYWORD'], /^\b(?:abstract|const|extends|factory|final|get|implements|native|operator|set|static|typedef|var)\b/i],
58
59      // Keywords for types.
60      [PR['PR_TYPE'], /^\b(?:bool|double|Dynamic|int|num|Object|String|void)\b/i],
61
62      // Keywords for constants.
63      [PR['PR_KEYWORD'], /^\b(?:false|null|true)\b/i],
64
65      // Multiline strings, single- and double-quoted.
66      [PR['PR_STRING'], /^r?[\']{3}[\s|\S]*?[^\\][\']{3}/],
67      [PR['PR_STRING'], /^r?[\"]{3}[\s|\S]*?[^\\][\"]{3}/],
68
69      // Normal and raw strings, single- and double-quoted.
70      [PR['PR_STRING'], /^r?\'(\'|(?:[^\n\r\f])*?[^\\]\')/],
71      [PR['PR_STRING'], /^r?\"(\"|(?:[^\n\r\f])*?[^\\]\")/],
72
73      // Types are capitalized by convention.
74      [PR['PR_TYPE'], /^[A-Z]\w*/],
75
76      // Identifiers.
77      [PR['PR_PLAIN'], /^[a-z_$][a-z0-9_]*/i],
78
79      // Operators.
80      [PR['PR_PUNCTUATION'], /^[~!%^&*+=|?:<>/-]/],
81
82      // Hex numbers.
83      [PR['PR_LITERAL'], /^\b0x[0-9a-f]+/i],
84
85      // Decimal numbers.
86      [PR['PR_LITERAL'], /^\b\d+(?:\.\d*)?(?:e[+-]?\d+)?/i],
87      [PR['PR_LITERAL'], /^\b\.\d+(?:e[+-]?\d+)?/i],
88
89      // Punctuation.
90      [PR['PR_PUNCTUATION'], /^[(){}\[\],.;]/]
91    ]),
92  ['dart']);
93