Commits

Rob Hoelz  committed e83d1a4 Merge

Merge commits from main pygments repo

Hg: changed pygments/__init__.py

  • Participants
  • Parent commits ebe0a42, 0710694

Comments (0)

Files changed (15)

 8ad6d35dd2ab0530a1e2c088ab7fe0e00426b5f9 1.4
 eff3aee4abff2b72564ddfde77fcc82adbba52ad 1.5
 2c262bfc66b05a8aecc1109c3acc5b9447a5213c 1.6rc1
+7c962dcb484cb73394aec7f41709940340dc8a9c 1.6
 * Kumar Appaiah -- Debian control lexer
 * Ali Afshar -- image formatter
 * Andreas Amann -- AppleScript lexer
+* Timothy Armstrong -- Dart lexer fixes
 * Jeffrey Arnold -- R/S, Rd, BUGS, Jags, and Stan lexers
 * Jeremy Ashkenas -- CoffeeScript lexer
 * Stefan Matthias Aust -- Smalltalk lexer
 * Hiram Chirino -- Scaml and Jade lexers
 * Ian Cooper -- VGL lexer
 * Leaf Corcoran -- MoonScript lexer
+* Christian Jann -- ShellSession lexer
 * Christopher Creutzig -- MuPAD lexer
 * Pete Curry -- bugfixes
 * Owen Durni -- haXe lexer
 
 Version 1.6
 -----------
-(in development)
+(released Feb 3, 2013)
 
 - Lexers added:
 
   * Dylan console (PR#149)
   * Logos (PR#150)
+  * Shell sessions (PR#158)
 
 - Fix guessed lexers not receiving lexer options (#838).
 
+- Fix unquoted HTML attribute lexing in Opa (#841).
+
+- Fixes to the Dart lexer (PR#160).
+
 
 Version 1.6rc1
 --------------

File pygments/__init__.py

     :license: BSD, see LICENSE for details.
 """
 
-__version__ = '1.6rc1'
+__version__ = '1.6'
 __docformat__ = 'restructuredtext'
 
 __all__ = ['lex', 'format', 'highlight']

File pygments/formatters/html.py

 
     `tagurlformat`
         A string formatting pattern used to generate links to ctags definitions.
-        Avaliabe variable are `%(path)s`, `%(fname)s` and `%(fext)s`.
+        Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
         Defaults to an empty string, resulting in just `#prefix-number` links.
         *New in Pygments 1.6.*
 
                 filename, linenumber = self._lookup_ctag(value)
                 if linenumber:
                     base, filename = os.path.split(filename)
+                    if base:
+                        base += '/'
                     filename, extension = os.path.splitext(filename)
                     url = self.tagurlformat % {'path': base, 'fname': filename,
                                                'fext': extension}

File pygments/lexers/_mapping.py

     'SchemeLexer': ('pygments.lexers.functional', 'Scheme', ('scheme', 'scm'), ('*.scm', '*.ss'), ('text/x-scheme', 'application/x-scheme')),
     'ScilabLexer': ('pygments.lexers.math', 'Scilab', ('scilab',), ('*.sci', '*.sce', '*.tst'), ('text/scilab',)),
     'ScssLexer': ('pygments.lexers.web', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)),
+    'ShellSessionLexer': ('pygments.lexers.shell', 'Shell Session', ('shell-session',), ('*.shell-session',), ('application/x-sh-session',)),
     'SmaliLexer': ('pygments.lexers.dalvik', 'Smali', ('smali',), ('*.smali',), ('text/smali',)),
     'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)),
     'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)),

File pygments/lexers/asm.py

              r'|align|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
 
              r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
-             r'|arm_aapcscc|arm_aapcs_vfpcc'
+             r'|arm_aapcscc|arm_aapcs_vfpcc|ptx_device|ptx_kernel'
 
              r'|cc|c'
 

File pygments/lexers/functional.py

     keywords = [
         'and', 'as', 'begin', 'css', 'database', 'db', 'do', 'else', 'end',
         'external', 'forall', 'if', 'import', 'match', 'package', 'parser',
-        'rec', 'server', 'then', 'type', 'val', 'with', 'xml_parser'
+        'rec', 'server', 'then', 'type', 'val', 'with', 'xml_parser',
     ]
 
     # matches both stuff and `stuff`
             (r'[/*]', Comment),
         ],
 
-        # the coy pasting between string and single-string
+        # the copy pasting between string and single-string
         # is kinda sad. Is there a way to avoid that??
         'string': [
             (r'[^\\"{]+', String.Double),
             (r'"', String.Single, ('#pop', 'string')),
             (r'#'+ident_re, String.Single, '#pop'),
             (r'#(?={)', String.Single, ('#pop', 'root')),
+            (r'[^"\'{`=<>]+', String.Single, '#pop'),
             (r'{', Operator, ('#pop', 'root')), # this is a tail call!
         ],
 
             (r'</', String.Single, ('#pop', 'html-end-tag')),
             (r'<', String.Single, 'html-open-tag'),
             (r'{', Operator, 'root'),
-            (r'.|\s+', String.Single),
+            (r'[^<{]+', String.Single),
         ],
 
         'html-comment': [

File pygments/lexers/shell.py

 
 
 __all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
-           'PowerShellLexer']
+           'PowerShellLexer', 'ShellSessionLexer']
 
 line_re  = re.compile('.*?\n')
 
                 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.

File pygments/lexers/web.py

 
     tokens = {
         'root': [
+            include('string_literal'),
             (r'#!(.*?)$', Comment.Preproc),
-            (r'(#)(import|library|source)', bygroups(Text, Keyword)),
+            (r'\b(import|export)\b', Keyword, 'import_decl'),
+            (r'\b(library|source|part of|part)\b', Keyword),
             (r'[^\S\n]+', Text),
             (r'//.*?\n', Comment.Single),
             (r'/\*.*?\*/', Comment.Multiline),
-            (r'(class|interface)(\s+)',
+            (r'\b(class)\b(\s+)',
              bygroups(Keyword.Declaration, Text), 'class'),
-            (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
+            (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|'
              r'if|in|is|new|return|super|switch|this|throw|try|while)\b',
              Keyword),
-            (r'(abstract|const|extends|factory|final|get|implements|'
+            (r'\b(abstract|const|extends|factory|final|get|implements|'
              r'native|operator|set|static|typedef|var)\b', Keyword.Declaration),
-            (r'(bool|double|Dynamic|int|num|Object|String|void)', Keyword.Type),
-            (r'(false|null|true)', Keyword.Constant),
-            (r'@"(\\\\|\\"|[^"])*"', String.Double), # raw string
-            (r"@'(\\\\|\\'|[^'])*'", String.Single), # raw string
-            (r'"', String.Double, 'string_double'),
-            (r"'", String.Single, 'string_single'),
+            (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type),
+            (r'\b(false|null|true)\b', Keyword.Constant),
+            (r'[~!%^&*+=|?:<>/-]|as', Operator),
             (r'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label),
             (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
-            (r'[~!%^&*+=|?:<>/-]', Operator),
             (r'[(){}\[\],.;]', Punctuation),
             (r'0[xX][0-9a-fA-F]+', Number.Hex),
             # DIGIT+ (‘.’ DIGIT*)? EXPONENT?
         'class': [
             (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name.Class, '#pop')
         ],
+        'import_decl': [
+            include('string_literal'),
+            (r'\s+', Text),
+            (r'\b(as|show|hide)\b', Keyword),
+            (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
+            (r'\,', Punctuation),
+            (r'\;', Punctuation, '#pop')
+        ],
+        'string_literal': [
+            # Raw strings.
+            (r'r"""([\s|\S]*?)"""', String.Double),
+            (r"r'''([\s|\S]*?)'''", String.Single),
+            (r'r"(.*?)"', String.Double),
+            (r"r'(.*?)'", String.Single),
+            # Normal Strings.
+            (r'"""', String.Double, 'string_double_multiline'),
+            (r"'''", String.Single, 'string_single_multiline'),
+            (r'"', String.Double, 'string_double'),
+            (r"'", String.Single, 'string_single')
+        ],
+        'string_common': [
+            (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])",
+             String.Escape),
+            (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
+            (r'(\$\{)(.*?)(\})',
+             bygroups(String.Interpol, using(this), String.Interpol))
+        ],
         'string_double': [
             (r'"', String.Double, '#pop'),
-            (r'[^"$]+', String.Double),
-            (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
-            (r'(\$\{)(.*?)(\})',
-             bygroups(String.Interpol, using(this), String.Interpol)),
+            (r'[^\"$\\\n]+', String.Double),
+            include('string_common'),
             (r'\$+', String.Double)
         ],
+        'string_double_multiline': [
+            (r'"""', String.Double, '#pop'),
+            (r'[^\"$\\]+', String.Double),
+            include('string_common'),
+            (r'(\$|\")+', String.Double)
+        ],
         'string_single': [
             (r"'", String.Single, '#pop'),
-            (r"[^'$]+", String.Single),
-            (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
-            (r'(\$\{)(.*?)(\})',
-             bygroups(String.Interpol, using(this), String.Interpol)),
+            (r"[^\'$\\\n]+", String.Single),
+            include('string_common'),
             (r'\$+', String.Single)
+        ],
+        'string_single_multiline': [
+            (r"'''", String.Single, '#pop'),
+            (r'[^\'$\\]+', String.Single),
+            include('string_common'),
+            (r'(\$|\')+', String.Single)
         ]
     }
 
 
 [aliases]
 release = egg_info -RDb ''
+upload = upload --sign --identity=36580288
 
 setup(
     name = 'Pygments',
-    version = '1.6rc1',
+    version = '1.6',
     url = 'http://pygments.org/',
     license = 'BSD License',
     author = 'Georg Brandl',

File tests/examplefiles/example.shell-session

+[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi-  clean
+rm -rf *.sb
+rm -f sd_mmc_bootstream.raw
+rm -f linux_prep/board/*.o
+...
+Files:
+rm -f power_prep.o eabi.o
+Build output:
+make[1]: Leaving directory `/home/...'
+[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi-
+make[1]: Entering directory `/home/...'
+...
+#@echo "generating U-Boot boot stream image"
+#elftosb2 -z -c ./uboot_prebuilt.db -o imx23_uboot.sb
+echo "generating kernel bootstream file sd_mmc_bootstream.raw"
+generating kernel bootstream file sd_mmc_bootstream.raw
+#Please use cfimager to burn xxx_linux.sb. The below way will no
+#work at imx28 platform.
+> test
+$ test
+rm -f sd_mmc_bootstream.raw
+[user@linuxbox imx-bootlets-src-10.05.02]$
+pi@raspberrypi ~ $ sudo sh -c "echo 17 > /sys/class/gpio/export"
+pi@raspberrypi ~ $ sudo sh -c "echo out > /sys/class/gpio/gpio17/direction"
+pi@raspberrypi ~ $ sudo sh -c "echo 1 > /sys/class/gpio/gpio17/value"
+pi@raspberrypi ~ $ sudo sh -c "echo 0 > /sys/class/gpio/gpio17/value"
+pi@raspberrypi ~ $
+[user@linuxbox ~]$ # copy other stuff to the SD card
+root@imx233-olinuxino-micro:~# lsmod
+  Not tainted
+[user@linuxbox ~]$ tail -n 2 /mnt/rpi/etc/inittab
+#Spawn a getty on Raspberry Pi serial line
+T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
+pi@raspberrypi:~/Adafruit-WebIDE$ mkdir tmp
+pi@raspberrypi:~/Adafruit-WebIDE$ npm config set tmp tmp
+pi@raspberrypi:~/Adafruit-WebIDE$ npm install
+pi@raspberrypi ~/Adafruit-WebIDE $ ifconfig eth0
+eth0      Link encap:Ethernet  HWaddr b5:33:ff:33:ee:aq
+          inet addr:10.42.0.60  Bcast:10.42.0.255  Mask:255.255.255.0
+          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
+          RX packets:21867 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:8684 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:1000
+          RX bytes:27338495 (26.0 MiB)  TX bytes:1268356 (1.2 MiB)
+

File tests/examplefiles/test.opa

+function sample_page() {
+  <header>
+    <h3>HTML in Opa</h3>
+  </header>
+  <article>
+    <div class=container>
+      <p>Learning by examples.</p>
+    </div>
+  </article>
+}

File tests/test_basic_api.py

             'SqliteConsoleLexer', 'MatlabSessionLexer', 'ErlangShellLexer',
             'BashSessionLexer', 'LiterateHaskellLexer', 'PostgresConsoleLexer',
             'ElixirConsoleLexer', 'JuliaConsoleLexer', 'RobotFrameworkLexer',
-            'DylanConsoleLexer'):
+            'DylanConsoleLexer', 'ShellSessionLexer'):
             inst = cls(ensurenl=False)
             ensure(inst.get_tokens('a\nb'), 'a\nb')
             inst = cls(ensurenl=False, stripall=True)