diff options
author | blackbird <devnull@localhost> | 2007-04-25 16:32:06 +0200 |
---|---|---|
committer | blackbird <devnull@localhost> | 2007-04-25 16:32:06 +0200 |
commit | 1b68b4671ab60608e2d308b0372b0629b3783360 (patch) | |
tree | 1d58344e951a2e401cfe04e54d7aebda7539b3c9 | |
parent | 5b9c141a1a5fa1f73fd18b07b8e71ee6f8553b7a (diff) | |
download | pygments-1b68b4671ab60608e2d308b0372b0629b3783360.tar.gz |
[svn] added D lexer by Kirk MyDonald, this closes #241
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 93 |
3 files changed, 93 insertions, 5 deletions
@@ -11,4 +11,5 @@ Other contributors (as mentionend in :copyright:s) are: - Marek Kubica - Ben Bangert - Tiberius Teng -- Adam Blinkinsop <blinks@acm.org>
\ No newline at end of file +- Adam Blinkinsop <blinks@acm.org> +- Kirk McDonald @@ -27,6 +27,8 @@ Version 0.8 (in development) - Added a Redcode lexer, thanks to Adam Blinkinsop. +- Added a D lexer, thanks to Kirk McDonald. + Version 0.7.1 ------------- diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 07fb162f..cb9ef6d0 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -6,8 +6,9 @@ Lexers for compiled languages. :copyright: 2006-2007 by Georg Brandl, Armin Ronacher, Christoph Hack, - Whitney Young. - :license: BSD, see LICENSE for more details. + Whitney Young, Kirk McDonald. + :license: BSD, see LICENSE for more details, the D lexer is licensed + under the MIT license and was contributed by Kirk McDonald. """ import re @@ -25,8 +26,8 @@ from pygments.token import \ Error -__all__ = ['CLexer', 'CppLexer', 'DelphiLexer', 'JavaLexer', 'DylanLexer', - 'OcamlLexer', 'ObjectiveCLexer'] +__all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer', + 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer'] class CLexer(RegexLexer): @@ -203,6 +204,90 @@ class CppLexer(RegexLexer): } +class DLexer(RegexLexer): + """ + For D source. + """ + name = 'D' + filenames = ['*.d', '*.di'] + + tokens = { + 'root': [ + (r'\n', Text), + (r'\s+', Text), + #(r'\\\n', Text), # line continuations + # Comments + (r'//(.*?)\n', Comment), + (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment), + (r'/\+', Comment, 'nestedcomment'), + # Keywords + (r'(abstract|alias|align|asm|assert|auto|body|break|case|cast' + r'|catch|class|const|continue|debug|default|delegate|delete' + r'|deprecated|do|else|enum|export|extern|finally|final' + r'|foreach_reverse|foreach|for|function|goto|if|import|inout' + r'|interface|invariant|in|is|lazy|mixin|module|new|out|override' + r'|package|pragma|private|protected|public|ref|return|scope' + r'|static|struct|super|switch|synchronized|template|this|throw' + r'|try|typedef|typeid|typeof|union|unittest|version|volatile' + r'|while|with)', Keyword + ), + (r'(bool|cdouble|cent|cfloat|char|creal|dchar|double|float|idouble' + r'|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong|ushort' + r'|ushort|void|wchar)', Keyword.Type + ), + (r'(false|true|null)', Keyword.Constant), + (r'(macro)', Keyword.Reserved), + # FloatLiteral + # -- HexFloat + (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float), + # -- DecimalFloat + (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float), + (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float), + # IntegerLiteral + # -- Binary + (r'0[Bb][01_]+', Number), + # -- Octal + (r'0[0-7_]+', Number.Oct), + # -- Hexadecimal + (r'0[xX][0-9a-fA-F_]+', Number.Hex), + # -- Decimal + (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer), + # CharacterLiteral + (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""", + String.Char + ), + # StringLiteral + # -- WysiwygString + (r'(?s)r"[^"]*"[cwd]?', String), + # -- AlternateWysiwygString + (r'(?s)`[^`]*`[cwd]?', String), + # -- DoubleQuotedString + (r'(?s)"(\\"|[^"])*"[cwd]?', String), + # -- EscapeSequence + (r"""\\(['"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}""" + r"""|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)""", + String + ), + # -- HexString + (r'(?s)x"[0-9a-fA-F_\s]*"[cwd]?', String), + # Tokens + (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>=' + r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)' + r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Text #Punctuation + ), + # Identifier + (r'[a-zA-Z_]\w*', Name), + ], + 'nestedcomment': [ + (r'[^+/]', Comment), + (r'/\+', Comment, '#push'), + (r'\+/', Comment, '#pop'), + (r'[+/]', Comment), + ], + } + + class DelphiLexer(Lexer): """ For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal), |