Anonymous avatar Anonymous committed 951f029

DarcsPatchLexer: Update for Darcs 2

Update DarcsPatchLexer, primarily due to differences in the output in darcs 2.
Specifically:

* Relax patch requirements: operators { and } are no longer special and
±/hunk/etc... are no recognized with or without them.

* Tighten keyword recognition, now uses list of hunk, addfile, etc...

* Keywords now have optional spacing before hand, due to the (common) case
in darcs 2 of: ] hunk ...

* Hunk insertions/deletions now recognize the [_*_] special characters

Comments (0)

Files changed (1)

pygments/lexers/text.py

                 Kumar Appaiah <akumar@ee.iitm.ac.in>,
                 Varun Hiremath <varunhiremath@gmail.com>,
                 Jeremy Thurgood,
-                Max Battcher,
+                Max Battcher <me@worldmaker.net>,
                 Kirill Simonov <xi@resolvent.net>.
     :license: BSD, see LICENSE for more details.
 """
         if text[:4] == '--- ':
             return 0.9
 
+DPATCH_KEYWORDS = ['hunk', 'addfile', 'adddir', 'rmfile', 'rmdir', 'move',
+    'replace']
 
 class DarcsPatchLexer(RegexLexer):
     """
         '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'{', Operator),
+            (r'}', Operator),
+            (r'(\[)((?:TAG )?)(.*)(\n)(.*)(\*\*)(\d+)(\s?)(\])', bygroups(Operator, Keyword, Name, Text,
+                Name, Operator, Literal.Date, Text, Operator)),
+            (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),
+            (r'(\s*)(%s)(.*\n)' % '|'.join(DPATCH_KEYWORDS),
+                bygroups(Text, Keyword, Text)),
+            (r'\+', Generic.Inserted, "insert"),
+            (r'-', Generic.Deleted, "delete"),
+            (r'.*\n', Text),
         ],
         'comment': [
-            (r' .*\n', 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),
+        'specialText': [ # darcs add [_CODE_] special operators for clarity
+            (r'\n', Text, "#pop"), # line-based
+            (r'\[_[^_]*_]', Operator),
+        ],
+        'insert': [
+            include('specialText'),
+            (r'\[', Generic.Inserted),
+            (r'[^\n\[]*', Generic.Inserted),
+        ],
+        'delete': [
+            include('specialText'),
+            (r'\[', Generic.Deleted),
+            (r'[^\n\[]*', Generic.Deleted),
         ],
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.