summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-02-05 12:18:36 +0100
committerGeorg Brandl <georg@python.org>2012-02-05 12:18:36 +0100
commitda12a8923f1f63c3f77c67123ead5a6c3368ff1b (patch)
tree26f68fe4c655fff6aecbde3e62496189c103ebff
parent853ead03f3dea69a76d34e9bb5a85d4df881ed59 (diff)
downloadpygments-da12a8923f1f63c3f77c67123ead5a6c3368ff1b.tar.gz
Closes #715: Add Dart lexer.
-rw-r--r--AUTHORS1
-rw-r--r--CHANGES1
-rw-r--r--pygments/lexers/_mapping.py3
-rw-r--r--pygments/lexers/web.py68
-rw-r--r--tests/examplefiles/test.dart23
5 files changed, 94 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index d9633da6..898a2eed 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -52,6 +52,7 @@ Other contributors, listed alphabetically, are:
* Marek Kubica -- Scheme lexer
* Jochen Kupperschmidt -- Markdown processor
* Gerd Kurzbach -- Modelica lexer
+* Olov Lassus -- Dart lexer
* Mark Lee -- Vala lexer
* Ben Mabey -- Gherkin lexer
* Simone Margaritelli -- Hybris lexer
diff --git a/CHANGES b/CHANGES
index 65a3bfb8..30474f47 100644
--- a/CHANGES
+++ b/CHANGES
@@ -35,6 +35,7 @@ Version 1.5
* SystemVerilog (PR#35)
* Coq (#734)
* PowerShell (#654)
+ * Dart (#715)
- In the LaTeX formatter, escape special &, < and > chars (#648).
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 3ac9229e..e702f650 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -69,6 +69,7 @@ LEXERS = {
'DLexer': ('pygments.lexers.compiled', 'D', ('d',), ('*.d', '*.di'), ('text/x-dsrc',)),
'DObjdumpLexer': ('pygments.lexers.asm', 'd-objdump', ('d-objdump',), ('*.d-objdump',), ('text/x-d-objdump',)),
'DarcsPatchLexer': ('pygments.lexers.text', 'Darcs Patch', ('dpatch',), ('*.dpatch', '*.darcspatch'), ()),
+ 'DartLexer': ('pygments.lexers.web', 'Dart', ('dart',), ('*.dart',), ('text/x-dart',)),
'DebianControlLexer': ('pygments.lexers.text', 'Debian Control file', ('control',), ('control',), ()),
'DelphiLexer': ('pygments.lexers.compiled', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas',), ('text/x-pascal',)),
'DiffLexer': ('pygments.lexers.text', 'Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')),
@@ -176,7 +177,7 @@ LEXERS = {
'PostgresConsoleLexer': ('pygments.lexers.sql', 'PostgreSQL console (psql)', ('psql', 'postgresql-console', 'postgres-console'), (), ('text/x-postgresql-psql',)),
'PostgresLexer': ('pygments.lexers.sql', 'PostgreSQL SQL dialect', ('postgresql', 'postgres'), (), ('text/x-postgresql',)),
'PovrayLexer': ('pygments.lexers.other', 'POVRay', ('pov',), ('*.pov', '*.inc'), ('text/x-povray',)),
- 'PowerShellLexer': ('pygments.lexers.shell', 'PowerShell', ('powershell', 'posh'), ('*.ps1',), ('text/x-powershell',)),
+ 'PowerShellLexer': ('pygments.lexers.shell', 'PowerShell', ('powershell', 'posh', 'ps1'), ('*.ps1',), ('text/x-powershell',)),
'PrologLexer': ('pygments.lexers.compiled', 'Prolog', ('prolog',), ('*.prolog', '*.pro', '*.pl'), ('text/x-prolog',)),
'PropertiesLexer': ('pygments.lexers.text', 'Properties', ('properties',), ('*.properties',), ('text/x-java-properties',)),
'ProtoBufLexer': ('pygments.lexers.other', 'Protocol Buffer', ('protobuf',), ('*.proto',), ()),
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py
index a88aa086..83ff201c 100644
--- a/pygments/lexers/web.py
+++ b/pygments/lexers/web.py
@@ -26,7 +26,7 @@ __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JSONLexer', 'CssLexer',
'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer',
'ObjectiveJLexer', 'CoffeeScriptLexer', 'DuelLexer', 'ScamlLexer',
- 'JadeLexer', 'XQueryLexer', 'DtdLexer']
+ 'JadeLexer', 'XQueryLexer', 'DtdLexer', 'DartLexer']
class JavascriptLexer(RegexLexer):
@@ -2777,3 +2777,69 @@ class XQueryLexer(ExtendedRegexLexer):
]
}
+
+class DartLexer(RegexLexer):
+ """
+ For `Dart <http://dartlang.org/>`_ source code.
+
+ *New in Pygments 1.5.*
+ """
+
+ name = 'Dart'
+ aliases = ['dart']
+ filenames = ['*.dart']
+ mimetypes = ['text/x-dart']
+
+ flags = re.MULTILINE | re.DOTALL
+
+ tokens = {
+ 'root': [
+ (r'#!(.*?)$', Comment.Preproc),
+ (r'(#)(import|library|source)', bygroups(Text, Keyword)),
+ (r'[^\S\n]+', Text),
+ (r'//.*?\n', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (r'(class|interface)(\s+)',
+ bygroups(Keyword.Declaration, Text), 'class'),
+ (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
+ r'if|in|is|new|return|super|switch|this|throw|try|while)\b',
+ Keyword),
+ (r'(abstract|const|extends|factory|final|get|implements|'
+ r'native|operator|set|static|typedef|var)\b', Keyword.Declaration),
+ (r'(bool|double|Dynamic|int|num|Object|String|void)', Keyword.Type),
+ (r'(false|null|true)', Keyword.Constant),
+ (r'@"(\\\\|\\"|[^"])*"', String.Double), # raw string
+ (r"@'(\\\\|\\'|[^'])*'", String.Single), # raw string
+ (r'"', String.Double, 'string_double'),
+ (r"'", String.Single, 'string_single'),
+ (r'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label),
+ (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
+ (r'[~!%^&*+=|?:<>/-]', Operator),
+ (r'[(){}\[\],.;]', Punctuation),
+ (r'0[xX][0-9a-fA-F]+', Number.Hex),
+ # DIGIT+ (‘.’ DIGIT*)? EXPONENT?
+ (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number),
+ (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT?
+ (r'\n', Text)
+ # pseudo-keyword negate intentionally left out
+ ],
+ 'class': [
+ (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name.Class, '#pop')
+ ],
+ 'string_double': [
+ (r'"', String.Double, '#pop'),
+ (r'[^"$]+', String.Double),
+ (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
+ (r'(\$\{)(.*?)(\})',
+ bygroups(String.Interpol, using(this), String.Interpol)),
+ (r'\$+', String.Double)
+ ],
+ 'string_single': [
+ (r"'", String.Single, '#pop'),
+ (r"[^'$]+", String.Single),
+ (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
+ (r'(\$\{)(.*?)(\})',
+ bygroups(String.Interpol, using(this), String.Interpol)),
+ (r'\$+', String.Single)
+ ]
+ }
diff --git a/tests/examplefiles/test.dart b/tests/examplefiles/test.dart
new file mode 100644
index 00000000..aa1fb0ed
--- /dev/null
+++ b/tests/examplefiles/test.dart
@@ -0,0 +1,23 @@
+// Greeter example from
+// <http://www.dartlang.org/docs/getting-started/interface.html>
+class Greeter implements Comparable {
+ String prefix = 'Hello,';
+ Greeter() {}
+ Greeter.withPrefix(this.prefix);
+ greet(String name) => print('$prefix $name');
+
+ int compareTo(Greeter other) => prefix.compareTo(other.prefix);
+}
+
+void main() {
+ Greeter greeter = new Greeter();
+ Greeter greeter2 = new Greeter.withPrefix('Hi,');
+
+ num result = greeter2.compareTo(greeter);
+ if (result == 0) {
+ greeter2.greet('you are the same.');
+ } else {
+ greeter2.greet('you are different.');
+ }
+}
+