diff options
| author | hhsprings <xwhhsprings@gmail.com> | 2015-11-04 17:43:59 +0900 |
|---|---|---|
| committer | hhsprings <xwhhsprings@gmail.com> | 2015-11-04 17:43:59 +0900 |
| commit | b9b77fbceb32da2b4973725a4bda356535429424 (patch) | |
| tree | 979da67daa61c8019d7a28035375a628760d4bc4 /pygments/lexers/diff.py | |
| parent | 39b04c956deca69ff5befcfdcc76c5212f65d972 (diff) | |
| download | pygments-b9b77fbceb32da2b4973725a4bda356535429424.tar.gz | |
Add the lexer for `wdiff <https://www.gnu.org/software/wdiff/>`_ output.
(issue `#960 <https://bitbucket.org/birkenfeld/pygments-main/issues/960/syntax-highlighting-for-wdiff>`_)
Diffstat (limited to 'pygments/lexers/diff.py')
| -rw-r--r-- | pygments/lexers/diff.py | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/pygments/lexers/diff.py b/pygments/lexers/diff.py index d3b1589d..9efb100b 100644 --- a/pygments/lexers/diff.py +++ b/pygments/lexers/diff.py @@ -9,11 +9,13 @@ :license: BSD, see LICENSE for details. """ +import re + from pygments.lexer import RegexLexer, include, bygroups from pygments.token import Text, Comment, Operator, Keyword, Name, Generic, \ Literal -__all__ = ['DiffLexer', 'DarcsPatchLexer'] +__all__ = ['DiffLexer', 'DarcsPatchLexer', 'WDiffLexer'] class DiffLexer(RegexLexer): @@ -104,3 +106,56 @@ class DarcsPatchLexer(RegexLexer): (r'[^\n\[]+', Generic.Deleted), ], } + + +class WDiffLexer(RegexLexer): + """ + A `wdiff <https://www.gnu.org/software/wdiff/>`_ lexer. + + Note that: + + * only to normal output (without option like -l). + * if target files of wdiff contain "[-", "-]", "{+", "+}", + especially they are unbalanced, this lexer will get confusing. + + .. versionadded:: 2.1 + """ + + name = 'WDiff' + aliases = ['wdiff',] + filenames = ['*.wdiff',] + mimetypes = [] + + flags = re.MULTILINE | re.DOTALL + + # We can only assume "[-" after "[-" before "-]" is `nested`, + # for instance wdiff to wdiff outputs. We have no way to + # distinct these marker is of wdiff output from original text. + + ins_op = r"\{\+" + ins_cl = r"\+\}" + del_op = r"\[\-" + del_cl = r"\-\]" + tokens = { + 'root': [ + (ins_op, Generic.Inserted, 'inserted'), + (del_op, Generic.Deleted, 'deleted'), + (r'.', Text), + ], + 'inserted': [ + (ins_op, Generic.Inserted, '#push'), + (del_op, Generic.Inserted, '#push'), + (del_cl, Generic.Inserted, '#pop'), + + (ins_cl, Generic.Inserted, '#pop'), + (r'.', Generic.Inserted), + ], + 'deleted': [ + (del_op, Generic.Deleted, '#push'), + (ins_op, Generic.Deleted, '#push'), + (ins_cl, Generic.Deleted, '#pop'), + + (del_cl, Generic.Deleted, '#pop'), + (r'.', Generic.Deleted), + ], + } |
