- update to r225 of google-code-prettify (Timothy Armstrong's dart prettify mode)
diff --git a/src/prettify/lang/LangDart.java b/src/prettify/lang/LangDart.java
new file mode 100644
index 0000000..e90f12f
--- /dev/null
+++ b/src/prettify/lang/LangDart.java
@@ -0,0 +1,94 @@
+/**
+ * @license Copyright (C) 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package prettify.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+import prettify.parser.Prettify;
+
+/**
+ * This is similar to the lang-dart.js in JavaScript Prettify.
+ *
+ * All comments are adapted from the JavaScript Prettify.
+ *
+ * <p>
+ * Registers a language handler for Dart.
+ *
+ *
+ * Loosely structured based on the DartLexer in Pygments: http://pygments.org/.
+ *
+ * To use, include prettify.js and this file in your HTML page.
+ * Then put your code in an HTML tag like
+ * <pre class="prettyprint lang-dart">(Dart code)</pre>
+ *
+ * @author armstrong.timothy@gmail.com
+ */
+public class LangDart extends Lang {
+
+ public LangDart() {
+ List<List<Object>> _shortcutStylePatterns = new ArrayList<List<Object>>();
+ List<List<Object>> _fallthroughStylePatterns = new ArrayList<List<Object>>();
+
+ // Whitespace.
+ _shortcutStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[\t\n\r \\xA0]+"), null, "\t\n\r " + Character.toString((char) 0xA0)}));
+
+ // Script tag.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^#!(?:.*)")}));
+ // `import`, `library`, `part of`, `part`, `as`, `show`, and `hide`
+ // keywords.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:import|library|part of|part|as|show|hide)\\b", Pattern.CASE_INSENSITIVE)}));
+ // Single-line comments.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\/(?:.*)")}));
+ // Multiline comments.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_COMMENT, Pattern.compile("^\\/\\*[^*]*\\*+(?:[^\\/*][^*]*\\*+)*\\/")}));
+ // `class` and `interface` keywords.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:class|interface)\\b", Pattern.CASE_INSENSITIVE)}));
+ // General keywords.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\\b", Pattern.CASE_INSENSITIVE)}));
+ // Declaration keywords.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("^\\b(?:abstract|const|extends|factory|final|get|implements|native|operator|set|static|typedef|var)\\b", Pattern.CASE_INSENSITIVE)}));
+ // Keywords for types.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_TYPE, Pattern.compile("^\\b(?:bool|double|Dynamic|int|num|Object|String|void)\\b", Pattern.CASE_INSENSITIVE)}));
+ // Keywords for constants.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_KEYWORD, Pattern.compile("\\b(?:false|null|true)\\b", Pattern.CASE_INSENSITIVE)}));
+ // Multiline strings, single- and double-quoted.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?[\\']{3}[\\s|\\S]*?[^\\\\][\\']{3}")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?[\\\"]{3}[\\s|\\S]*?[^\\\\][\\\"]{3}")}));
+ // Normal and raw strings, single- and double-quoted.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?\\'(\\'|(?:[^\\n\\r\\f])*?[^\\\\]\\')")}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_STRING, Pattern.compile("^r?\\\"(\\\"|(?:[^\\n\\r\\f])*?[^\\\\]\\\")")}));
+ // Identifiers.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PLAIN, Pattern.compile("^[a-z_$][a-z0-9_]*", Pattern.CASE_INSENSITIVE)}));
+ // Operators.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[~!%^&*+=|?:<>/-]")}));
+ // Hex numbers.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b0x[0-9a-f]+", Pattern.CASE_INSENSITIVE)}));
+ // Decimal numbers.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b\\d+(?:\\.\\d*)?(?:e[+-]?\\d+)?", Pattern.CASE_INSENSITIVE)}));
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_LITERAL, Pattern.compile("^\\b\\.\\d+(?:e[+-]?\\d+)?", Pattern.CASE_INSENSITIVE)}));
+ // Punctuation.
+ _fallthroughStylePatterns.add(Arrays.asList(new Object[]{Prettify.PR_PUNCTUATION, Pattern.compile("^[(){}\\[\\],.;]")}));
+
+ setShortcutStylePatterns(_shortcutStylePatterns);
+ setFallthroughStylePatterns(_fallthroughStylePatterns);
+ }
+
+ public static List<String> getFileExtensions() {
+ return Arrays.asList(new String[]{"dart"});
+ }
+}
diff --git a/src/prettify/parser/Prettify.java b/src/prettify/parser/Prettify.java
index 0acb9b7..7639395 100644
--- a/src/prettify/parser/Prettify.java
+++ b/src/prettify/parser/Prettify.java
@@ -26,6 +26,7 @@
import prettify.lang.LangAppollo;
import prettify.lang.LangClj;
import prettify.lang.LangCss;
+import prettify.lang.LangDart;
import prettify.lang.LangGo;
import prettify.lang.LangHs;
import prettify.lang.LangLisp;
@@ -349,6 +350,7 @@
register(LangAppollo.class);
register(LangClj.class);
register(LangCss.class);
+ register(LangDart.class);
register(LangGo.class);
register(LangHs.class);
register(LangLisp.class);
diff --git a/test/prettify/PrettifyTest.java b/test/prettify/PrettifyTest.java
index 77dddcd..15fc747 100644
--- a/test/prettify/PrettifyTest.java
+++ b/test/prettify/PrettifyTest.java
@@ -106,6 +106,7 @@
test("c", "C_lang", false);
test(null, "Cpp", false);
test("cpp", "Cpp_lang", false);
+ test(null, "dart", false);
test(null, "javascript", false);
test(null, "perl", false);
test(null, "python", false);
diff --git a/test/prettify/PrettifyTest/result/dart.txt b/test/prettify/PrettifyTest/result/dart.txt
new file mode 100644
index 0000000..9874567
--- /dev/null
+++ b/test/prettify/PrettifyTest/result/dart.txt
@@ -0,0 +1,41 @@
+`PLNpart of myLib`END`PUN;`END`PLN
+
+part `END`STR'something.dart'`END`PUN;`END`PLN
+
+`END`KWDimport`END`PLN `END`STR'dart:math'`END`PLN `END`KWDas`END`PLN test show foo`END`PUN,`END`PLN bar`END`PUN;`END`PLN
+
+`END`KWDclass`END`PLN `END`TYPPoint`END`PLN `END`PUN{`END`PLN
+ `END`KWDfinal`END`PLN num x`END`PUN,`END`PLN y`END`PUN;`END`PLN
+
+ `END`TYPPoint`END`PUN(`END`KWDthis`END`PUN.`END`PLNx`END`PUN,`END`PLN `END`KWDthis`END`PUN.`END`PLNy`END`PUN);`END`PLN
+ `END`TYPPoint`END`PUN.`END`PLNzero`END`PUN()`END`PLN `END`PUN:`END`PLN x `END`PUN=`END`PLN `END`LIT0`END`PUN,`END`PLN y `END`PUN=`END`PLN `END`LIT0`END`PUN;`END`PLN `END`COM// Named constructor`END`PLN
+ `END`COM// with an initializer list.`END`PLN
+
+ num distanceTo`END`PUN(`END`TYPPoint`END`PLN other`END`PUN)`END`PLN `END`PUN{`END`PLN
+ `END`KWDvar`END`PLN dx `END`PUN=`END`PLN x `END`PUN-`END`PLN other`END`PUN.`END`PLNx`END`PUN;`END`PLN
+ `END`KWDvar`END`PLN dy `END`PUN=`END`PLN y `END`PUN-`END`PLN other`END`PUN.`END`PLNy`END`PUN;`END`PLN
+ `END`KWDreturn`END`PLN sqrt`END`PUN(`END`PLNdx `END`PUN*`END`PLN dx `END`PUN+`END`PLN dy `END`PUN*`END`PLN dy`END`PUN);`END`PLN
+ `END`PUN}`END`PLN
+`END`PUN}`END`PLN
+
+`END`COM// This is a single-line comment.`END`PLN
+
+`END`COM/*
+This is a
+multiline comment.
+*/`END`PLN
+
+main`END`PUN()`END`PLN `END`PUN{`END`PLN
+ `END`TYPPoint`END`PLN p `END`PUN=`END`PLN `END`KWDnew`END`PLN `END`TYPPoint`END`PUN(`END`LIT7`END`PUN,`END`PLN `END`LIT12`END`PUN);`END`PLN
+ `END`TYPString`END`PLN thing `END`PUN=`END`PLN `END`STR'It\'s awesome!'`END`PUN;`END`PLN
+ `END`TYPString`END`PLN thing2 `END`PUN=`END`PLN `END`STR'''
+This is a test! \'''
+This is the end of the test'''`END`PUN;`END`PLN
+ `END`TYPString`END`PLN thing3 `END`PUN=`END`PLN r`END`STR"""
+This is a raw
+multiline string!"""`END`PUN;`END`PLN
+ num x `END`PUN=`END`PLN `END`LIT0x123ABC`END`PUN;`END`PLN
+ num y `END`PUN=`END`PLN `END`LIT1.8e-12`END`PUN;`END`PLN
+ `END`KWDbool`END`PLN flag `END`PUN=`END`PLN `END`KWDfalse`END`PUN;`END`PLN
+ `END`TYPString`END`PLN raw `END`PUN=`END`PLN r`END`STR"This is a raw string, where \n doesn't matter"`END`PUN;`END`PLN
+`END`PUN}`END'
\ No newline at end of file
diff --git a/test/prettify/PrettifyTest/source/dart.txt b/test/prettify/PrettifyTest/source/dart.txt
new file mode 100644
index 0000000..0cf6fb9
--- /dev/null
+++ b/test/prettify/PrettifyTest/source/dart.txt
@@ -0,0 +1,41 @@
+part of myLib;
+
+part 'something.dart';
+
+import 'dart:math' as test show foo, bar;
+
+class Point {
+ final num x, y;
+
+ Point(this.x, this.y);
+ Point.zero() : x = 0, y = 0; // Named constructor
+ // with an initializer list.
+
+ num distanceTo(Point other) {
+ var dx = x - other.x;
+ var dy = y - other.y;
+ return sqrt(dx * dx + dy * dy);
+ }
+}
+
+// This is a single-line comment.
+
+/*
+This is a
+multiline comment.
+*/
+
+main() {
+ Point p = new Point(7, 12);
+ String thing = 'It\'s awesome!';
+ String thing2 = '''
+This is a test! \'''
+This is the end of the test''';
+ String thing3 = r"""
+This is a raw
+multiline string!""";
+ num x = 0x123ABC;
+ num y = 1.8e-12;
+ bool flag = false;
+ String raw = r"This is a raw string, where \n doesn't matter";
+}
\ No newline at end of file