eric6/ThirdParty/Pygments/pygments/lexers/textfmts.py

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
--- a/eric6/ThirdParty/Pygments/pygments/lexers/textfmts.py	Tue Apr 21 19:44:19 2020 +0200
+++ b/eric6/ThirdParty/Pygments/pygments/lexers/textfmts.py	Tue Apr 21 19:47:10 2020 +0200
@@ -5,18 +5,20 @@
 
     Lexers for various text formats.
 
-    :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
 import re
 
-from pygments.lexer import RegexLexer, bygroups
+from pygments.lexers import guess_lexer, get_lexer_by_name
+from pygments.lexer import RegexLexer, bygroups, default, include
 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Generic, Literal
+    Number, Generic, Literal, Punctuation
 from pygments.util import ClassNotFound
 
-__all__ = ['IrcLogsLexer', 'TodotxtLexer', 'HttpLexer', 'GettextLexer']
+__all__ = ['IrcLogsLexer', 'TodotxtLexer', 'HttpLexer', 'GettextLexer',
+           'NotmuchLexer', 'KernelLogLexer']
 
 
 class IrcLogsLexer(RegexLexer):
@@ -173,13 +175,13 @@
     tokens = {
         'root': [
             (r'(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH)( +)([^ ]+)( +)'
-             r'(HTTP)(/)(1\.[01])(\r?\n|\Z)',
+             r'(HTTP)(/)(1\.[01]|2|3)(\r?\n|\Z)',
              bygroups(Name.Function, Text, Name.Namespace, Text,
                       Keyword.Reserved, Operator, Number, Text),
              'headers'),
-            (r'(HTTP)(/)(1\.[01])( +)(\d{3})( +)([^\r\n]+)(\r?\n|\Z)',
-             bygroups(Keyword.Reserved, Operator, Number, Text, Number,
-                      Text, Name.Exception, Text),
+            (r'(HTTP)(/)(1\.[01]|2|3)( +)(\d{3})(?:( +)([^\r\n]+))?(\r?\n|\Z)',
+             bygroups(Keyword.Reserved, Operator, Number, Text, Number, Text,
+                      Name.Exception, Text),
              'headers'),
         ],
         'headers': [
@@ -295,3 +297,135 @@
             (r'\s+', IncompleteTaskText),
         ],
     }
+
+
+class NotmuchLexer(RegexLexer):
+    """
+    For `Notmuch <https://notmuchmail.org/>`_ email text format.
+
+    .. versionadded:: 2.5
+
+    Additional options accepted:
+
+    `body_lexer`
+        If given, highlight the contents of the message body with the specified
+        lexer, else guess it according to the body content (default: ``None``).
+    """
+
+    name = 'Notmuch'
+    aliases = ['notmuch']
+
+    def _highlight_code(self, match):
+        code = match.group(1)
+
+        try:
+            if self.body_lexer:
+                lexer = get_lexer_by_name(self.body_lexer)
+            else:
+                lexer = guess_lexer(code.strip())
+        except ClassNotFound:
+            lexer = get_lexer_by_name('text')
+
+        for item in lexer.get_tokens_unprocessed(code):
+            yield item
+
+    tokens = {
+        'root': [
+            (r'\fmessage{\s*', Keyword, ('message', 'message-attr')),
+        ],
+        'message-attr': [
+            (r'(\s*id:\s*)([^\s]+)', bygroups(Name.Attribute, String)),
+            (r'(\s*(?:depth|match|excluded):\s*)(\d+)',
+             bygroups(Name.Attribute, Number.Integer)),
+            (r'(\s*filename:\s*)(.+\n)',
+             bygroups(Name.Attribute, String)),
+            default('#pop'),
+        ],
+        'message': [
+            (r'\fmessage}\n', Keyword, '#pop'),
+            (r'\fheader{\n', Keyword, 'header'),
+            (r'\fbody{\n', Keyword, 'body'),
+        ],
+        'header': [
+            (r'\fheader}\n', Keyword, '#pop'),
+            (r'((?:Subject|From|To|Cc|Date):\s*)(.*\n)',
+             bygroups(Name.Attribute, String)),
+            (r'(.*)(\s*\(.*\))(\s*\(.*\)\n)',
+             bygroups(Generic.Strong, Literal, Name.Tag)),
+        ],
+        'body': [
+            (r'\fpart{\n', Keyword, 'part'),
+            (r'\f(part|attachment){\s*', Keyword, ('part', 'part-attr')),
+            (r'\fbody}\n', Keyword, '#pop'),
+        ],
+        'part-attr': [
+            (r'(ID:\s*)(\d+)', bygroups(Name.Attribute, Number.Integer)),
+            (r'(,\s*)((?:Filename|Content-id):\s*)([^,]+)',
+             bygroups(Punctuation, Name.Attribute, String)),
+            (r'(,\s*)(Content-type:\s*)(.+\n)',
+             bygroups(Punctuation, Name.Attribute, String)),
+            default('#pop'),
+        ],
+        'part': [
+            (r'\f(?:part|attachment)}\n', Keyword, '#pop'),
+            (r'\f(?:part|attachment){\s*', Keyword, ('#push', 'part-attr')),
+            (r'^Non-text part: .*\n', Comment),
+            (r'(?s)(.*?(?=\f(?:part|attachment)}\n))', _highlight_code),
+        ],
+    }
+
+    def analyse_text(text):
+        return 1.0 if text.startswith('\fmessage{') else 0.0
+
+    def __init__(self, **options):
+        self.body_lexer = options.get('body_lexer', None)
+        RegexLexer.__init__(self, **options)
+
+
+class KernelLogLexer(RegexLexer):
+    """
+    For Linux Kernel log ("dmesg") output.
+
+    .. versionadded:: 2.6
+    """
+    name = 'Kernel log'
+    aliases = ['kmsg', 'dmesg']
+    filenames = ['*.kmsg', '*.dmesg']
+
+    tokens = {
+        'root': [
+            (r'^[^:]+:debug : (?=\[)', Text, 'debug'),
+            (r'^[^:]+:info  : (?=\[)', Text, 'info'),
+            (r'^[^:]+:warn  : (?=\[)', Text, 'warn'),
+            (r'^[^:]+:notice: (?=\[)', Text, 'warn'),
+            (r'^[^:]+:err   : (?=\[)', Text, 'error'),
+            (r'^[^:]+:crit  : (?=\[)', Text, 'error'),
+            (r'^(?=\[)', Text, 'unknown'),
+        ],
+        'unknown': [
+            (r'^(?=.+(warning|notice|audit|deprecated))', Text, 'warn'),
+            (r'^(?=.+(error|critical|fail|Bug))', Text, 'error'),
+            default('info'),
+        ],
+        'base': [
+            (r'\[[0-9\. ]+\] ', Number),
+            (r'(?<=\] ).+?:', Keyword),
+            (r'\n', Text, '#pop'),
+        ],
+        'debug': [
+            include('base'),
+            (r'.+\n', Comment, '#pop')
+        ],
+        'info': [
+            include('base'),
+            (r'.+\n', Text, '#pop')
+        ],
+        'warn': [
+            include('base'),
+            (r'.+\n', Generic.Strong, '#pop')
+        ],
+        'error': [
+            include('base'),
+            (r'.+\n', Generic.Error, '#pop')
+        ]
+    }

eric ide

mercurial