ThirdParty/Pygments/pygments/lexers/shell.py

changeset 2426
da76c71624de
parent 1705
b0fbc9300f2b
child 2525
8b507a9a2d40
--- a/ThirdParty/Pygments/pygments/lexers/shell.py	Sun Feb 17 19:05:40 2013 +0100
+++ b/ThirdParty/Pygments/pygments/lexers/shell.py	Sun Feb 17 19:07:15 2013 +0100
@@ -5,7 +5,7 @@
 
     Lexers for various shells.
 
-    :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
@@ -18,7 +18,7 @@
 
 
 __all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
-           'PowerShellLexer']
+           'PowerShellLexer', 'ShellSessionLexer']
 
 line_re  = re.compile('.*?\n')
 
@@ -60,6 +60,7 @@
             (r'\\[\w\W]', String.Escape),
             (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
             (r'[\[\]{}()=]', Operator),
+            (r'<<<', Operator),  # here-string
             (r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
             (r'&&|\|\|', Operator),
         ],
@@ -152,6 +153,52 @@
                 yield pos+i, t, v
 
 
+class ShellSessionLexer(Lexer):
+    """
+    Lexer for shell sessions that works with different command prompts
+
+    *New in Pygments 1.6.*
+    """
+
+    name = 'Shell Session'
+    aliases = ['shell-session']
+    filenames = ['*.shell-session']
+    mimetypes = ['application/x-sh-session']
+
+    def get_tokens_unprocessed(self, text):
+        bashlexer = BashLexer(**self.options)
+
+        pos = 0
+        curcode = ''
+        insertions = []
+
+        for match in line_re.finditer(text):
+            line = match.group()
+            m = re.match(r'^((?:\[?\S+@[^$#%]+)[$#%])(.*\n?)', line)
+            if m:
+                # To support output lexers (say diff output), the output
+                # needs to be broken by prompts whenever the output lexer
+                # changes.
+                if not insertions:
+                    pos = match.start()
+
+                insertions.append((len(curcode),
+                                   [(0, Generic.Prompt, m.group(1))]))
+                curcode += m.group(2)
+            else:
+                if insertions:
+                    toks = bashlexer.get_tokens_unprocessed(curcode)
+                    for i, t, v in do_insertions(insertions, toks):
+                        yield pos+i, t, v
+                yield match.start(), Generic.Output, line
+                insertions = []
+                curcode = ''
+        if insertions:
+            for i, t, v in do_insertions(insertions,
+                                         bashlexer.get_tokens_unprocessed(curcode)):
+                yield pos+i, t, v
+
+
 class BatchLexer(RegexLexer):
     """
     Lexer for the DOS/Windows Batch file format.
@@ -328,6 +375,8 @@
             (r'(&lt;|<)#', Comment.Multiline, 'multline'),
             (r'@"\n.*?\n"@', String.Heredoc),
             (r"@'\n.*?\n'@", String.Heredoc),
+            # escaped syntax
+            (r'`[\'"$@-]', Punctuation),
             (r'"', String.Double, 'string'),
             (r"'([^']|'')*'", String.Single),
             (r'(\$|@@|@)((global|script|private|env):)?[a-z0-9_]+',

eric ide

mercurial