As part of a larger project I decided that I wanted highlighting for
Darcs Patches. This would be output of commands such as darcs
annotate --patch and darcs send --output
What I've arrived at (attached) is a lexer for the Pygments syntax
highlighting library[1]. I built it largely from trial and error, but
this version seems to work against a wide range of patches I've been
testing it against.
I'd love any feedback on it. Following further testing and usage I'd
like to submit to the Pygments team for inclusion as a core lexer.
[1] http://pygments.pocoo.org
--
--Max Battcher--
http://www.worldmaker.net/
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
"""
Lexers for use with Pygments Syntax Highlighting
"""
class DarcsPatchLexer(RegexLexer):
"""
DarcsPatchLexer is a lexer for the various versions of the darcs patch
format. Examples of this format are derived by commands such as
``darcs annotate --patch`` and ``darcs send``.
"""
name='Darcs Patch'
aliases=['dpatch']
filenames=['*.dpatch', '*.darcspatch']
tokens = {
'root': [
(r'<', Operator),
(r'>', Operator),
(r'{', Operator, 'patch'),
(r'(\[)((?:TAG )?)(.*)(\n)(.*)(\*\*)(\d+)(\s?)', bygroups(Operator,
Keyword, Name, Text,
Name, Operator, Literal.Date, Text), 'comment'),
(r'New patches:', Generic.Heading),
(r'Context:', Generic.Heading),
(r'Patch bundle hash:', Generic.Heading),
(r'\s+|\w+', Text),
],
'comment': [
(r' .*\n', Comment),
(r'\]', Operator, "#pop"),
],
'patch': [
(r'}', Operator, "#pop"),
(r'(\w+)(.*\n)', bygroups(Keyword, Text)),
(r'\+.*\n', Generic.Inserted),
(r'-.*\n', Generic.Deleted),
(r'.*\n', Text),
],
}
# vim: et ts=4 sts=4 sw=4
_______________________________________________
darcs-users mailing list
[email protected]
http://lists.osuosl.org/mailman/listinfo/darcs-users