pygments.rb 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. data/lib/pygments/version.rb +1 -1
  2. data/vendor/pygments-main/AUTHORS +14 -0
  3. data/vendor/pygments-main/CHANGES +34 -3
  4. data/vendor/pygments-main/Makefile +1 -1
  5. data/vendor/pygments-main/docs/generate.py +1 -1
  6. data/vendor/pygments-main/external/markdown-processor.py +1 -1
  7. data/vendor/pygments-main/external/moin-parser.py +1 -1
  8. data/vendor/pygments-main/external/rst-directive-old.py +1 -1
  9. data/vendor/pygments-main/external/rst-directive.py +1 -1
  10. data/vendor/pygments-main/pygments/__init__.py +1 -1
  11. data/vendor/pygments-main/pygments/cmdline.py +4 -1
  12. data/vendor/pygments-main/pygments/console.py +1 -1
  13. data/vendor/pygments-main/pygments/filter.py +1 -1
  14. data/vendor/pygments-main/pygments/filters/__init__.py +1 -1
  15. data/vendor/pygments-main/pygments/formatter.py +1 -1
  16. data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
  17. data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -1
  18. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  19. data/vendor/pygments-main/pygments/formatters/html.py +2 -2
  20. data/vendor/pygments-main/pygments/formatters/img.py +1 -1
  21. data/vendor/pygments-main/pygments/formatters/latex.py +3 -2
  22. data/vendor/pygments-main/pygments/formatters/other.py +1 -1
  23. data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
  24. data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
  25. data/vendor/pygments-main/pygments/formatters/terminal.py +5 -2
  26. data/vendor/pygments-main/pygments/formatters/terminal256.py +5 -2
  27. data/vendor/pygments-main/pygments/lexer.py +29 -10
  28. data/vendor/pygments-main/pygments/lexers/__init__.py +14 -11
  29. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
  30. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
  31. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
  32. data/vendor/pygments-main/pygments/lexers/_mapping.py +41 -23
  33. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1 -1
  34. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +1 -1
  35. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
  36. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -3
  37. data/vendor/pygments-main/pygments/lexers/agile.py +148 -443
  38. data/vendor/pygments-main/pygments/lexers/asm.py +5 -3
  39. data/vendor/pygments-main/pygments/lexers/compiled.py +298 -294
  40. data/vendor/pygments-main/pygments/lexers/dotnet.py +40 -34
  41. data/vendor/pygments-main/pygments/lexers/functional.py +723 -4
  42. data/vendor/pygments-main/pygments/lexers/hdl.py +228 -6
  43. data/vendor/pygments-main/pygments/lexers/jvm.py +678 -0
  44. data/vendor/pygments-main/pygments/lexers/math.py +65 -2
  45. data/vendor/pygments-main/pygments/lexers/other.py +875 -481
  46. data/vendor/pygments-main/pygments/lexers/parsers.py +1 -1
  47. data/vendor/pygments-main/pygments/lexers/shell.py +360 -0
  48. data/vendor/pygments-main/pygments/lexers/special.py +1 -1
  49. data/vendor/pygments-main/pygments/lexers/sql.py +565 -0
  50. data/vendor/pygments-main/pygments/lexers/templates.py +1 -1
  51. data/vendor/pygments-main/pygments/lexers/text.py +237 -100
  52. data/vendor/pygments-main/pygments/lexers/web.py +146 -10
  53. data/vendor/pygments-main/pygments/plugin.py +1 -1
  54. data/vendor/pygments-main/pygments/scanner.py +1 -1
  55. data/vendor/pygments-main/pygments/style.py +1 -1
  56. data/vendor/pygments-main/pygments/styles/__init__.py +2 -1
  57. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  58. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  59. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  60. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  61. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  62. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  63. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  64. data/vendor/pygments-main/pygments/styles/fruity.py +1 -2
  65. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  66. data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
  67. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  68. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  69. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  70. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  71. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  72. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  73. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  74. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  75. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  76. data/vendor/pygments-main/pygments/token.py +1 -1
  77. data/vendor/pygments-main/pygments/unistring.py +1 -1
  78. data/vendor/pygments-main/pygments/util.py +2 -2
  79. data/vendor/pygments-main/scripts/check_sources.py +2 -2
  80. data/vendor/pygments-main/scripts/find_codetags.py +1 -1
  81. data/vendor/pygments-main/scripts/find_error.py +5 -2
  82. data/vendor/pygments-main/scripts/get_vimkw.py +9 -4
  83. data/vendor/pygments-main/setup.py +1 -1
  84. data/vendor/pygments-main/tests/examplefiles/classes.dylan +16 -0
  85. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  86. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  87. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  88. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  89. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  90. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  91. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  92. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  93. data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
  94. data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
  95. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  96. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  97. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +4 -2
  98. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  99. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  100. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  101. data/vendor/pygments-main/tests/examplefiles/test.cs +23 -0
  102. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  103. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  104. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  105. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  106. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  107. data/vendor/pygments-main/tests/old_run.py +1 -1
  108. data/vendor/pygments-main/tests/run.py +1 -1
  109. data/vendor/pygments-main/tests/test_basic_api.py +4 -3
  110. data/vendor/pygments-main/tests/test_clexer.py +1 -1
  111. data/vendor/pygments-main/tests/test_cmdline.py +1 -1
  112. data/vendor/pygments-main/tests/test_examplefiles.py +4 -3
  113. data/vendor/pygments-main/tests/test_html_formatter.py +33 -1
  114. data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
  115. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  116. data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
  117. data/vendor/pygments-main/tests/test_token.py +1 -1
  118. data/vendor/pygments-main/tests/test_using_api.py +1 -1
  119. data/vendor/pygments-main/tests/test_util.py +35 -5
  120. metadata +30 -4
@@ -1,3 +1,3 @@
1
1
  module Pygments
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.6'
3
3
  end
@@ -22,12 +22,14 @@ Other contributors, listed alphabetically, are:
22
22
  * Frits van Bommel -- assembler lexers
23
23
  * Pierre Bourdon -- bugfixes
24
24
  * Hiram Chirino -- Scaml and Jade lexers
25
+ * Leaf Corcoran -- MoonScript lexer
25
26
  * Christopher Creutzig -- MuPAD lexer
26
27
  * Pete Curry -- bugfixes
27
28
  * Owen Durni -- haXe lexer
28
29
  * Nick Efford -- Python 3 lexer
29
30
  * Artem Egorkine -- terminal256 formatter
30
31
  * James H. Fisher -- PostScript lexer
32
+ * Carlos Galdino -- Elixir and Elixir Console lexers
31
33
  * Naveen Garg -- Autohotkey lexer
32
34
  * Laurent Gautier -- R/S lexer
33
35
  * Alex Gaynor -- PyPy log lexer
@@ -36,6 +38,7 @@ Other contributors, listed alphabetically, are:
36
38
  * Matt Good -- Genshi, Cheetah lexers
37
39
  * Patrick Gotthardt -- PHP namespaces support
38
40
  * Olivier Guibe -- Asymptote lexer
41
+ * Martin Harriman -- SNOBOL lexer
39
42
  * Matthew Harrison -- SVG formatter
40
43
  * Steven Hazel -- Tcl lexer
41
44
  * Aslak Hellesøy -- Gherkin lexer
@@ -44,18 +47,25 @@ Other contributors, listed alphabetically, are:
44
47
  * Varun Hiremath -- Debian control lexer
45
48
  * Ben Hollis -- Mason lexer
46
49
  * Tim Howard -- BlitzMax lexer
50
+ * Ivan Inozemtsev -- Fantom lexer
47
51
  * Dennis Kaarsemaker -- sources.list lexer
52
+ * Igor Kalnitsky -- vhdl lexer
53
+ * Adam Koprowski -- Opa lexer
48
54
  * Benjamin Kowarsch -- Modula-2 lexer
49
55
  * Marek Kubica -- Scheme lexer
50
56
  * Jochen Kupperschmidt -- Markdown processor
51
57
  * Gerd Kurzbach -- Modelica lexer
58
+ * Olov Lassus -- Dart lexer
59
+ * Sylvestre Ledru -- Scilab lexer
52
60
  * Mark Lee -- Vala lexer
53
61
  * Ben Mabey -- Gherkin lexer
54
62
  * Simone Margaritelli -- Hybris lexer
55
63
  * Kirk McDonald -- D lexer
64
+ * Gordon McGregor -- SystemVerilog lexer
56
65
  * Stephen McKamey -- Duel/JBST lexer
57
66
  * Brian McKenna -- F# lexer
58
67
  * Lukas Meuser -- BBCode formatter, Lua lexer
68
+ * Hong Minhee -- HTTP lexer
59
69
  * Michael Mior -- Awk lexer
60
70
  * Paulo Moura -- Logtalk lexer
61
71
  * Mher Movsisyan -- DTD lexer
@@ -68,7 +78,9 @@ Other contributors, listed alphabetically, are:
68
78
  * Ronny Pfannschmidt -- BBCode lexer
69
79
  * Benjamin Peterson -- Test suite refactoring
70
80
  * Dominik Picheta -- Nimrod lexer
81
+ * Clément Prévost -- UrbiScript lexer
71
82
  * Justin Reidy -- MXML lexer
83
+ * Norman Richards -- JSON lexer
72
84
  * Lubomir Rintel -- GoodData MAQL and CL lexers
73
85
  * Andre Roberge -- Tango style
74
86
  * Konrad Rudolph -- LaTeX formatter enhancements
@@ -87,7 +99,9 @@ Other contributors, listed alphabetically, are:
87
99
  * Jeremy Thurgood -- Erlang, Squid config lexers
88
100
  * Erick Tryzelaar -- Felix lexer
89
101
  * Daniele Varrazzo -- PostgreSQL lexers
102
+ * Abe Voelker -- OpenEdge ABL lexer
90
103
  * Whitney Young -- ObjectiveC lexer
104
+ * Matthias Vallentin -- Bro lexer
91
105
  * Nathan Weizenbaum -- Haml and Sass lexers
92
106
  * Dietmar Winkler -- Modelica lexer
93
107
  * Nils Winter -- Smalltalk lexer
@@ -6,7 +6,7 @@ http://bitbucket.org/birkenfeld/pygments-main/issues.
6
6
 
7
7
  Version 1.5
8
8
  -----------
9
- (codename not decided, released Jul xx, 2011)
9
+ (codename not decided, released 2012)
10
10
 
11
11
  - Lexers added:
12
12
 
@@ -20,10 +20,30 @@ Version 1.5
20
20
  * Groovy (#501)
21
21
  * PostgreSQL (#660)
22
22
  * DTD
23
- * Gosu
23
+ * Gosu (#634)
24
24
  * Octave (PR#22)
25
25
  * Standard ML (PR#14)
26
26
  * CFengine3 (#601)
27
+ * Opa (PR#37)
28
+ * HTTP sessions (PR#42)
29
+ * JSON (PR#31)
30
+ * SNOBOL (PR#30)
31
+ * MoonScript (PR#43)
32
+ * ECL (PR#29)
33
+ * Urbiscript (PR#17)
34
+ * OpenEdge ABL (PR#27)
35
+ * SystemVerilog (PR#35)
36
+ * Coq (#734)
37
+ * PowerShell (#654)
38
+ * Dart (#715)
39
+ * Fantom (PR#36)
40
+ * Bro (PR#5)
41
+ * NewLISP (PR#26)
42
+ * VHDL (PR#45)
43
+ * Scilab (#740)
44
+ * Elixir (PR#57)
45
+
46
+ - Fix Python 3 terminal highlighting with pygmentize (#691).
27
47
 
28
48
  - In the LaTeX formatter, escape special &, < and > chars (#648).
29
49
 
@@ -38,7 +58,7 @@ Version 1.5
38
58
 
39
59
  - Fix Lua "class" highlighting: it does not have classes (#665).
40
60
 
41
- - Fix degenerate regex in Scala lexer (#671).
61
+ - Fix degenerate regex in Scala lexer (#671) and highlighting bugs (#713, 708).
42
62
 
43
63
  - Fix number pattern order in Ocaml lexer (#647).
44
64
 
@@ -46,6 +66,17 @@ Version 1.5
46
66
 
47
67
  - Fixes to the Clojure lexer (PR#9).
48
68
 
69
+ - Fix degenerate regex in Nemerle lexer (#706).
70
+
71
+ - Fix infinite looping in CoffeeScript lexer (#729).
72
+
73
+ - Fix crashes and analysis with ObjectiveC lexer (#693, #696).
74
+
75
+ - Add some Fortran 2003 keywords.
76
+
77
+ - Fix Boo string regexes (#679).
78
+
79
+ - Add "rrt" style (#727).
49
80
 
50
81
  Version 1.4
51
82
  -----------
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Combines scripts for common tasks.
6
6
  #
7
- # :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
7
+ # :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
8
8
  # :license: BSD, see LICENSE for details.
9
9
  #
10
10
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  Generates a bunch of html files containing the documentation.
8
8
 
9
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
9
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
10
10
  :license: BSD, see LICENSE for details.
11
11
  """
12
12
 
@@ -27,7 +27,7 @@
27
27
 
28
28
  .. _Markdown: http://www.freewisdom.org/projects/python-markdown/
29
29
 
30
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
30
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
31
31
  :license: BSD, see LICENSE for details.
32
32
  """
33
33
 
@@ -31,7 +31,7 @@
31
31
  If you do not want to do that and are willing to accept larger HTML
32
32
  output, you can set the INLINESTYLES option below to True.
33
33
 
34
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
34
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
35
35
  :license: BSD, see LICENSE for details.
36
36
  """
37
37
 
@@ -31,7 +31,7 @@
31
31
  .. _directive documentation:
32
32
  http://docutils.sourceforge.net/docs/howto/rst-directives.html
33
33
 
34
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
34
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
35
35
  :license: BSD, see LICENSE for details.
36
36
  """
37
37
 
@@ -31,7 +31,7 @@
31
31
  .. _directive documentation:
32
32
  http://docutils.sourceforge.net/docs/howto/rst-directives.html
33
33
 
34
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
34
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
35
35
  :license: BSD, see LICENSE for details.
36
36
  """
37
37
 
@@ -22,7 +22,7 @@
22
22
  .. _Pygments tip:
23
23
  http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
24
24
 
25
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
25
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
26
26
  :license: BSD, see LICENSE for details.
27
27
  """
28
28
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Command line interface.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
  import sys
@@ -408,6 +408,9 @@ def main(args=sys.argv):
408
408
  None) or 'ascii'
409
409
  fmter.encoding = getattr(sys.stdout, 'encoding',
410
410
  None) or 'ascii'
411
+ elif not outfn and sys.version_info > (3,):
412
+ # output to terminal with encoding -> use .buffer
413
+ outfile = sys.stdout.buffer
411
414
 
412
415
  # ... and do it!
413
416
  try:
@@ -5,7 +5,7 @@
5
5
 
6
6
  Format colored console output.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Module that implements the default filter.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -6,7 +6,7 @@
6
6
  Module containing filter lookup functions and default
7
7
  filters.
8
8
 
9
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
9
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
10
10
  :license: BSD, see LICENSE for details.
11
11
  """
12
12
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Base formatter class.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Pygments formatters.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
  import os.path
@@ -9,7 +9,7 @@
9
9
 
10
10
  Do not alter the FORMATTERS dictionary by hand.
11
11
 
12
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
12
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
13
13
  :license: BSD, see LICENSE for details.
14
14
  """
15
15
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  BBcode formatter.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Formatter for HTML output.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -596,7 +596,7 @@ class HtmlFormatter(Formatter):
596
596
 
597
597
  def _wrap_lineanchors(self, inner):
598
598
  s = self.lineanchors
599
- i = 0
599
+ i = self.linenostart - 1 # subtract 1 since we have to increment i *before* yielding
600
600
  for t, line in inner:
601
601
  if t:
602
602
  i += 1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Formatter for Pixmap output.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Formatter for LaTeX fancyvrb output.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -286,7 +286,8 @@ class LatexFormatter(Formatter):
286
286
  cp = self.commandprefix
287
287
  styles = []
288
288
  for name, definition in self.cmd2def.iteritems():
289
- styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' % (cp, name, definition))
289
+ styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
290
+ (cp, name, definition))
290
291
  return STYLE_TEMPLATE % {'cp': self.commandprefix,
291
292
  'styles': '\n'.join(styles)}
292
293
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Other formatters: NullFormatter, RawTokenFormatter.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  A formatter that generates RTF files.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Formatter for SVG output.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,10 +5,12 @@
5
5
 
6
6
  Formatter for terminal output with ANSI sequences.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
12
+ import sys
13
+
12
14
  from pygments.formatter import Formatter
13
15
  from pygments.token import Keyword, Name, Comment, String, Error, \
14
16
  Number, Operator, Generic, Token, Whitespace
@@ -86,7 +88,8 @@ class TerminalFormatter(Formatter):
86
88
  # hack: if the output is a terminal and has an encoding set,
87
89
  # use that to avoid unicode encode problems
88
90
  if not self.encoding and hasattr(outfile, "encoding") and \
89
- hasattr(outfile, "isatty") and outfile.isatty():
91
+ hasattr(outfile, "isatty") and outfile.isatty() and \
92
+ sys.version_info < (3,):
90
93
  self.encoding = outfile.encoding
91
94
  return Formatter.format(self, tokensource, outfile)
92
95
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  Formatter version 1.
13
13
 
14
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
14
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
15
15
  :license: BSD, see LICENSE for details.
16
16
  """
17
17
 
@@ -24,6 +24,8 @@
24
24
  # black-on-while, so colors like "white background" need to be converted
25
25
  # to "white background, black foreground", etc...
26
26
 
27
+ import sys
28
+
27
29
  from pygments.formatter import Formatter
28
30
 
29
31
 
@@ -185,7 +187,8 @@ class Terminal256Formatter(Formatter):
185
187
  # hack: if the output is a terminal and has an encoding set,
186
188
  # use that to avoid unicode encode problems
187
189
  if not self.encoding and hasattr(outfile, "encoding") and \
188
- hasattr(outfile, "isatty") and outfile.isatty():
190
+ hasattr(outfile, "isatty") and outfile.isatty() and \
191
+ sys.version_info < (3,):
189
192
  self.encoding = outfile.encoding
190
193
  return Formatter.format(self, tokensource, outfile)
191
194
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Base lexer classes.
7
7
 
8
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
  import re
@@ -21,6 +21,12 @@ __all__ = ['Lexer', 'RegexLexer', 'ExtendedRegexLexer', 'DelegatingLexer',
21
21
  'LexerContext', 'include', 'bygroups', 'using', 'this']
22
22
 
23
23
 
24
+ _encoding_map = [('\xef\xbb\xbf', 'utf-8'),
25
+ ('\xff\xfe\0\0', 'utf-32'),
26
+ ('\0\0\xfe\xff', 'utf-32be'),
27
+ ('\xff\xfe', 'utf-16'),
28
+ ('\xfe\xff', 'utf-16be')]
29
+
24
30
  _default_analyse = staticmethod(lambda x: 0.0)
25
31
 
26
32
 
@@ -142,8 +148,19 @@ class Lexer(object):
142
148
  raise ImportError('To enable chardet encoding guessing, '
143
149
  'please install the chardet library '
144
150
  'from http://chardet.feedparser.org/')
145
- enc = chardet.detect(text)
146
- text = text.decode(enc['encoding'])
151
+ # check for BOM first
152
+ decoded = None
153
+ for bom, encoding in _encoding_map:
154
+ if text.startswith(bom):
155
+ decoded = unicode(text[len(bom):], encoding,
156
+ errors='replace')
157
+ break
158
+ # no BOM found, so use chardet
159
+ if decoded is None:
160
+ enc = chardet.detect(text[:1024]) # Guess using first 1KB
161
+ decoded = unicode(text, enc.get('encoding') or 'utf-8',
162
+ errors='replace')
163
+ text = decoded
147
164
  else:
148
165
  text = text.decode(self.encoding)
149
166
  # text now *is* a unicode string
@@ -274,12 +291,14 @@ def bygroups(*args):
274
291
  if data:
275
292
  yield match.start(i + 1), action, data
276
293
  else:
277
- if ctx:
278
- ctx.pos = match.start(i + 1)
279
- for item in action(lexer, _PseudoMatch(match.start(i + 1),
280
- match.group(i + 1)), ctx):
281
- if item:
282
- yield item
294
+ data = match.group(i + 1)
295
+ if data is not None:
296
+ if ctx:
297
+ ctx.pos = match.start(i + 1)
298
+ for item in action(lexer, _PseudoMatch(match.start(i + 1),
299
+ data), ctx):
300
+ if item:
301
+ yield item
283
302
  if ctx:
284
303
  ctx.pos = match.end()
285
304
  return callback
@@ -439,7 +458,7 @@ class RegexLexerMeta(LexerMeta):
439
458
 
440
459
  def __call__(cls, *args, **kwds):
441
460
  """Instantiate cls after preprocessing its token definitions."""
442
- if not hasattr(cls, '_tokens'):
461
+ if '_tokens' not in cls.__dict__:
443
462
  cls._all_tokens = {}
444
463
  cls._tmpname = 0
445
464
  if hasattr(cls, 'token_variants') and cls.token_variants: