pygmentize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/LICENSE +19 -0
  2. data/lib/pygments.rb +23 -0
  3. data/pygmentize.gemspec +11 -0
  4. data/test/pygments.rb +19 -0
  5. data/vendor/pygmentize.py +7 -0
  6. data/vendor/pygments/AUTHORS +73 -0
  7. data/vendor/pygments/LICENSE +25 -0
  8. data/vendor/pygments/__init__.py +91 -0
  9. data/vendor/pygments/__init__.pyc +0 -0
  10. data/vendor/pygments/cmdline.py +430 -0
  11. data/vendor/pygments/cmdline.pyc +0 -0
  12. data/vendor/pygments/console.py +74 -0
  13. data/vendor/pygments/console.pyc +0 -0
  14. data/vendor/pygments/filter.py +74 -0
  15. data/vendor/pygments/filter.pyc +0 -0
  16. data/vendor/pygments/filters/__init__.py +357 -0
  17. data/vendor/pygments/filters/__init__.pyc +0 -0
  18. data/vendor/pygments/formatter.py +92 -0
  19. data/vendor/pygments/formatter.pyc +0 -0
  20. data/vendor/pygments/formatters/__init__.py +68 -0
  21. data/vendor/pygments/formatters/__init__.pyc +0 -0
  22. data/vendor/pygments/formatters/_mapping.py +92 -0
  23. data/vendor/pygments/formatters/_mapping.pyc +0 -0
  24. data/vendor/pygments/formatters/bbcode.py +109 -0
  25. data/vendor/pygments/formatters/bbcode.pyc +0 -0
  26. data/vendor/pygments/formatters/html.py +723 -0
  27. data/vendor/pygments/formatters/html.pyc +0 -0
  28. data/vendor/pygments/formatters/img.py +553 -0
  29. data/vendor/pygments/formatters/img.pyc +0 -0
  30. data/vendor/pygments/formatters/latex.py +354 -0
  31. data/vendor/pygments/formatters/latex.pyc +0 -0
  32. data/vendor/pygments/formatters/other.py +117 -0
  33. data/vendor/pygments/formatters/other.pyc +0 -0
  34. data/vendor/pygments/formatters/rtf.py +136 -0
  35. data/vendor/pygments/formatters/rtf.pyc +0 -0
  36. data/vendor/pygments/formatters/svg.py +154 -0
  37. data/vendor/pygments/formatters/svg.pyc +0 -0
  38. data/vendor/pygments/formatters/terminal.py +109 -0
  39. data/vendor/pygments/formatters/terminal.pyc +0 -0
  40. data/vendor/pygments/formatters/terminal256.py +219 -0
  41. data/vendor/pygments/formatters/terminal256.pyc +0 -0
  42. data/vendor/pygments/lexer.py +660 -0
  43. data/vendor/pygments/lexer.pyc +0 -0
  44. data/vendor/pygments/lexers/__init__.py +226 -0
  45. data/vendor/pygments/lexers/__init__.pyc +0 -0
  46. data/vendor/pygments/lexers/_asybuiltins.py +1645 -0
  47. data/vendor/pygments/lexers/_clbuiltins.py +232 -0
  48. data/vendor/pygments/lexers/_luabuiltins.py +256 -0
  49. data/vendor/pygments/lexers/_mapping.py +234 -0
  50. data/vendor/pygments/lexers/_mapping.pyc +0 -0
  51. data/vendor/pygments/lexers/_phpbuiltins.py +3389 -0
  52. data/vendor/pygments/lexers/_vimbuiltins.py +3 -0
  53. data/vendor/pygments/lexers/agile.py +1485 -0
  54. data/vendor/pygments/lexers/agile.pyc +0 -0
  55. data/vendor/pygments/lexers/asm.py +353 -0
  56. data/vendor/pygments/lexers/compiled.py +2365 -0
  57. data/vendor/pygments/lexers/dotnet.py +355 -0
  58. data/vendor/pygments/lexers/functional.py +756 -0
  59. data/vendor/pygments/lexers/functional.pyc +0 -0
  60. data/vendor/pygments/lexers/math.py +461 -0
  61. data/vendor/pygments/lexers/other.py +2297 -0
  62. data/vendor/pygments/lexers/parsers.py +695 -0
  63. data/vendor/pygments/lexers/special.py +100 -0
  64. data/vendor/pygments/lexers/special.pyc +0 -0
  65. data/vendor/pygments/lexers/templates.py +1387 -0
  66. data/vendor/pygments/lexers/text.py +1586 -0
  67. data/vendor/pygments/lexers/web.py +1619 -0
  68. data/vendor/pygments/lexers/web.pyc +0 -0
  69. data/vendor/pygments/plugin.py +74 -0
  70. data/vendor/pygments/plugin.pyc +0 -0
  71. data/vendor/pygments/scanner.py +104 -0
  72. data/vendor/pygments/style.py +117 -0
  73. data/vendor/pygments/style.pyc +0 -0
  74. data/vendor/pygments/styles/__init__.py +68 -0
  75. data/vendor/pygments/styles/__init__.pyc +0 -0
  76. data/vendor/pygments/styles/autumn.py +65 -0
  77. data/vendor/pygments/styles/borland.py +51 -0
  78. data/vendor/pygments/styles/bw.py +49 -0
  79. data/vendor/pygments/styles/colorful.py +81 -0
  80. data/vendor/pygments/styles/default.py +73 -0
  81. data/vendor/pygments/styles/default.pyc +0 -0
  82. data/vendor/pygments/styles/emacs.py +72 -0
  83. data/vendor/pygments/styles/friendly.py +72 -0
  84. data/vendor/pygments/styles/fruity.py +43 -0
  85. data/vendor/pygments/styles/manni.py +75 -0
  86. data/vendor/pygments/styles/monokai.py +106 -0
  87. data/vendor/pygments/styles/murphy.py +80 -0
  88. data/vendor/pygments/styles/native.py +65 -0
  89. data/vendor/pygments/styles/pastie.py +75 -0
  90. data/vendor/pygments/styles/perldoc.py +69 -0
  91. data/vendor/pygments/styles/tango.py +141 -0
  92. data/vendor/pygments/styles/trac.py +63 -0
  93. data/vendor/pygments/styles/vim.py +63 -0
  94. data/vendor/pygments/styles/vs.py +38 -0
  95. data/vendor/pygments/token.py +198 -0
  96. data/vendor/pygments/token.pyc +0 -0
  97. data/vendor/pygments/unistring.py +130 -0
  98. data/vendor/pygments/unistring.pyc +0 -0
  99. data/vendor/pygments/util.py +226 -0
  100. data/vendor/pygments/util.pyc +0 -0
  101. metadata +166 -0
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.plugin
4
+ ~~~~~~~~~~~~~~~
5
+
6
+ Pygments setuptools plugin interface. The methods defined
7
+ here also work if setuptools isn't installed but they just
8
+ return nothing.
9
+
10
+ lexer plugins::
11
+
12
+ [pygments.lexers]
13
+ yourlexer = yourmodule:YourLexer
14
+
15
+ formatter plugins::
16
+
17
+ [pygments.formatters]
18
+ yourformatter = yourformatter:YourFormatter
19
+ /.ext = yourformatter:YourFormatter
20
+
21
+ As you can see, you can define extensions for the formatter
22
+ with a leading slash.
23
+
24
+ syntax plugins::
25
+
26
+ [pygments.styles]
27
+ yourstyle = yourstyle:YourStyle
28
+
29
+ filter plugin::
30
+
31
+ [pygments.filter]
32
+ yourfilter = yourfilter:YourFilter
33
+
34
+
35
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
36
+ :license: BSD, see LICENSE for details.
37
+ """
38
+ try:
39
+ import pkg_resources
40
+ except ImportError:
41
+ pkg_resources = None
42
+
43
+ LEXER_ENTRY_POINT = 'pygments.lexers'
44
+ FORMATTER_ENTRY_POINT = 'pygments.formatters'
45
+ STYLE_ENTRY_POINT = 'pygments.styles'
46
+ FILTER_ENTRY_POINT = 'pygments.filters'
47
+
48
+
49
+ def find_plugin_lexers():
50
+ if pkg_resources is None:
51
+ return
52
+ for entrypoint in pkg_resources.iter_entry_points(LEXER_ENTRY_POINT):
53
+ yield entrypoint.load()
54
+
55
+
56
+ def find_plugin_formatters():
57
+ if pkg_resources is None:
58
+ return
59
+ for entrypoint in pkg_resources.iter_entry_points(FORMATTER_ENTRY_POINT):
60
+ yield entrypoint.name, entrypoint.load()
61
+
62
+
63
+ def find_plugin_styles():
64
+ if pkg_resources is None:
65
+ return
66
+ for entrypoint in pkg_resources.iter_entry_points(STYLE_ENTRY_POINT):
67
+ yield entrypoint.name, entrypoint.load()
68
+
69
+
70
+ def find_plugin_filters():
71
+ if pkg_resources is None:
72
+ return
73
+ for entrypoint in pkg_resources.iter_entry_points(FILTER_ENTRY_POINT):
74
+ yield entrypoint.name, entrypoint.load()
@@ -0,0 +1,104 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.scanner
4
+ ~~~~~~~~~~~~~~~~
5
+
6
+ This library implements a regex based scanner. Some languages
7
+ like Pascal are easy to parse but have some keywords that
8
+ depend on the context. Because of this it's impossible to lex
9
+ that just by using a regular expression lexer like the
10
+ `RegexLexer`.
11
+
12
+ Have a look at the `DelphiLexer` to get an idea of how to use
13
+ this scanner.
14
+
15
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
16
+ :license: BSD, see LICENSE for details.
17
+ """
18
+ import re
19
+
20
+
21
+ class EndOfText(RuntimeError):
22
+ """
23
+ Raise if end of text is reached and the user
24
+ tried to call a match function.
25
+ """
26
+
27
+
28
+ class Scanner(object):
29
+ """
30
+ Simple scanner
31
+
32
+ All method patterns are regular expression strings (not
33
+ compiled expressions!)
34
+ """
35
+
36
+ def __init__(self, text, flags=0):
37
+ """
38
+ :param text: The text which should be scanned
39
+ :param flags: default regular expression flags
40
+ """
41
+ self.data = text
42
+ self.data_length = len(text)
43
+ self.start_pos = 0
44
+ self.pos = 0
45
+ self.flags = flags
46
+ self.last = None
47
+ self.match = None
48
+ self._re_cache = {}
49
+
50
+ def eos(self):
51
+ """`True` if the scanner reached the end of text."""
52
+ return self.pos >= self.data_length
53
+ eos = property(eos, eos.__doc__)
54
+
55
+ def check(self, pattern):
56
+ """
57
+ Apply `pattern` on the current position and return
58
+ the match object. (Doesn't touch pos). Use this for
59
+ lookahead.
60
+ """
61
+ if self.eos:
62
+ raise EndOfText()
63
+ if pattern not in self._re_cache:
64
+ self._re_cache[pattern] = re.compile(pattern, self.flags)
65
+ return self._re_cache[pattern].match(self.data, self.pos)
66
+
67
+ def test(self, pattern):
68
+ """Apply a pattern on the current position and check
69
+ if it patches. Doesn't touch pos."""
70
+ return self.check(pattern) is not None
71
+
72
+ def scan(self, pattern):
73
+ """
74
+ Scan the text for the given pattern and update pos/match
75
+ and related fields. The return value is a boolen that
76
+ indicates if the pattern matched. The matched value is
77
+ stored on the instance as ``match``, the last value is
78
+ stored as ``last``. ``start_pos`` is the position of the
79
+ pointer before the pattern was matched, ``pos`` is the
80
+ end position.
81
+ """
82
+ if self.eos:
83
+ raise EndOfText()
84
+ if pattern not in self._re_cache:
85
+ self._re_cache[pattern] = re.compile(pattern, self.flags)
86
+ self.last = self.match
87
+ m = self._re_cache[pattern].match(self.data, self.pos)
88
+ if m is None:
89
+ return False
90
+ self.start_pos = m.start()
91
+ self.pos = m.end()
92
+ self.match = m.group()
93
+ return True
94
+
95
+ def get_char(self):
96
+ """Scan exactly one char."""
97
+ self.scan('.')
98
+
99
+ def __repr__(self):
100
+ return '<%s %d/%d>' % (
101
+ self.__class__.__name__,
102
+ self.pos,
103
+ self.data_length
104
+ )
@@ -0,0 +1,117 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.style
4
+ ~~~~~~~~~~~~~~
5
+
6
+ Basic style object.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ from pygments.token import Token, STANDARD_TYPES
13
+
14
+
15
+ class StyleMeta(type):
16
+
17
+ def __new__(mcs, name, bases, dct):
18
+ obj = type.__new__(mcs, name, bases, dct)
19
+ for token in STANDARD_TYPES:
20
+ if token not in obj.styles:
21
+ obj.styles[token] = ''
22
+
23
+ def colorformat(text):
24
+ if text[0:1] == '#':
25
+ col = text[1:]
26
+ if len(col) == 6:
27
+ return col
28
+ elif len(col) == 3:
29
+ return col[0]+'0'+col[1]+'0'+col[2]+'0'
30
+ elif text == '':
31
+ return ''
32
+ assert False, "wrong color format %r" % text
33
+
34
+ _styles = obj._styles = {}
35
+
36
+ for ttype in obj.styles:
37
+ for token in ttype.split():
38
+ if token in _styles:
39
+ continue
40
+ ndef = _styles.get(token.parent, None)
41
+ styledefs = obj.styles.get(token, '').split()
42
+ if not ndef or token is None:
43
+ ndef = ['', 0, 0, 0, '', '', 0, 0, 0]
44
+ elif 'noinherit' in styledefs and token is not Token:
45
+ ndef = _styles[Token][:]
46
+ else:
47
+ ndef = ndef[:]
48
+ _styles[token] = ndef
49
+ for styledef in obj.styles.get(token, '').split():
50
+ if styledef == 'noinherit':
51
+ pass
52
+ elif styledef == 'bold':
53
+ ndef[1] = 1
54
+ elif styledef == 'nobold':
55
+ ndef[1] = 0
56
+ elif styledef == 'italic':
57
+ ndef[2] = 1
58
+ elif styledef == 'noitalic':
59
+ ndef[2] = 0
60
+ elif styledef == 'underline':
61
+ ndef[3] = 1
62
+ elif styledef == 'nounderline':
63
+ ndef[3] = 0
64
+ elif styledef[:3] == 'bg:':
65
+ ndef[4] = colorformat(styledef[3:])
66
+ elif styledef[:7] == 'border:':
67
+ ndef[5] = colorformat(styledef[7:])
68
+ elif styledef == 'roman':
69
+ ndef[6] = 1
70
+ elif styledef == 'sans':
71
+ ndef[7] = 1
72
+ elif styledef == 'mono':
73
+ ndef[8] = 1
74
+ else:
75
+ ndef[0] = colorformat(styledef)
76
+
77
+ return obj
78
+
79
+ def style_for_token(cls, token):
80
+ t = cls._styles[token]
81
+ return {
82
+ 'color': t[0] or None,
83
+ 'bold': bool(t[1]),
84
+ 'italic': bool(t[2]),
85
+ 'underline': bool(t[3]),
86
+ 'bgcolor': t[4] or None,
87
+ 'border': t[5] or None,
88
+ 'roman': bool(t[6]) or None,
89
+ 'sans': bool(t[7]) or None,
90
+ 'mono': bool(t[8]) or None,
91
+ }
92
+
93
+ def list_styles(cls):
94
+ return list(cls)
95
+
96
+ def styles_token(cls, ttype):
97
+ return ttype in cls._styles
98
+
99
+ def __iter__(cls):
100
+ for token in cls._styles:
101
+ yield token, cls.style_for_token(token)
102
+
103
+ def __len__(cls):
104
+ return len(cls._styles)
105
+
106
+
107
+ class Style(object):
108
+ __metaclass__ = StyleMeta
109
+
110
+ #: overall background color (``None`` means transparent)
111
+ background_color = '#ffffff'
112
+
113
+ #: highlight background color
114
+ highlight_color = '#ffffcc'
115
+
116
+ #: Style definitions for individual token types.
117
+ styles = {}
Binary file
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.styles
4
+ ~~~~~~~~~~~~~~~
5
+
6
+ Contains built-in styles.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ from pygments.plugin import find_plugin_styles
13
+ from pygments.util import ClassNotFound
14
+
15
+
16
+ #: Maps style names to 'submodule::classname'.
17
+ STYLE_MAP = {
18
+ 'default': 'default::DefaultStyle',
19
+ 'emacs': 'emacs::EmacsStyle',
20
+ 'friendly': 'friendly::FriendlyStyle',
21
+ 'colorful': 'colorful::ColorfulStyle',
22
+ 'autumn': 'autumn::AutumnStyle',
23
+ 'murphy': 'murphy::MurphyStyle',
24
+ 'manni': 'manni::ManniStyle',
25
+ 'monokai': 'monokai::MonokaiStyle',
26
+ 'perldoc': 'perldoc::PerldocStyle',
27
+ 'pastie': 'pastie::PastieStyle',
28
+ 'borland': 'borland::BorlandStyle',
29
+ 'trac': 'trac::TracStyle',
30
+ 'native': 'native::NativeStyle',
31
+ 'fruity': 'fruity::FruityStyle',
32
+ 'bw': 'bw::BlackWhiteStyle',
33
+ 'vs': 'vs::VisualStudioStyle',
34
+ 'tango': 'tango::TangoStyle',
35
+ }
36
+
37
+
38
+ def get_style_by_name(name):
39
+ if name in STYLE_MAP:
40
+ mod, cls = STYLE_MAP[name].split('::')
41
+ builtin = "yes"
42
+ else:
43
+ for found_name, style in find_plugin_styles():
44
+ if name == found_name:
45
+ return style
46
+ # perhaps it got dropped into our styles package
47
+ builtin = ""
48
+ mod = name
49
+ cls = name.title() + "Style"
50
+
51
+ try:
52
+ mod = __import__('pygments.styles.' + mod, None, None, [cls])
53
+ except ImportError:
54
+ raise ClassNotFound("Could not find style module %r" % mod +
55
+ (builtin and ", though it should be builtin") + ".")
56
+ try:
57
+ return getattr(mod, cls)
58
+ except AttributeError:
59
+ raise ClassNotFound("Could not find style class %r in style module." % cls)
60
+
61
+
62
+ def get_all_styles():
63
+ """Return an generator for all styles by name,
64
+ both builtin and plugin."""
65
+ for name in STYLE_MAP:
66
+ yield name
67
+ for name, _ in find_plugin_styles():
68
+ yield name
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.styles.autumn
4
+ ~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ A colorful style, inspired by the terminal highlighting style.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ from pygments.style import Style
13
+ from pygments.token import Keyword, Name, Comment, String, Error, \
14
+ Number, Operator, Generic, Whitespace
15
+
16
+
17
+ class AutumnStyle(Style):
18
+ """
19
+ A colorful style, inspired by the terminal highlighting style.
20
+ """
21
+
22
+ default_style = ""
23
+
24
+ styles = {
25
+ Whitespace: '#bbbbbb',
26
+
27
+ Comment: 'italic #aaaaaa',
28
+ Comment.Preproc: 'noitalic #4c8317',
29
+ Comment.Special: 'italic #0000aa',
30
+
31
+ Keyword: '#0000aa',
32
+ Keyword.Type: '#00aaaa',
33
+
34
+ Operator.Word: '#0000aa',
35
+
36
+ Name.Builtin: '#00aaaa',
37
+ Name.Function: '#00aa00',
38
+ Name.Class: 'underline #00aa00',
39
+ Name.Namespace: 'underline #00aaaa',
40
+ Name.Variable: '#aa0000',
41
+ Name.Constant: '#aa0000',
42
+ Name.Entity: 'bold #800',
43
+ Name.Attribute: '#1e90ff',
44
+ Name.Tag: 'bold #1e90ff',
45
+ Name.Decorator: '#888888',
46
+
47
+ String: '#aa5500',
48
+ String.Symbol: '#0000aa',
49
+ String.Regex: '#009999',
50
+
51
+ Number: '#009999',
52
+
53
+ Generic.Heading: 'bold #000080',
54
+ Generic.Subheading: 'bold #800080',
55
+ Generic.Deleted: '#aa0000',
56
+ Generic.Inserted: '#00aa00',
57
+ Generic.Error: '#aa0000',
58
+ Generic.Emph: 'italic',
59
+ Generic.Strong: 'bold',
60
+ Generic.Prompt: '#555555',
61
+ Generic.Output: '#888888',
62
+ Generic.Traceback: '#aa0000',
63
+
64
+ Error: '#F00 bg:#FAA'
65
+ }
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.styles.borland
4
+ ~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ Style similar to the style used in the Borland IDEs.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ from pygments.style import Style
13
+ from pygments.token import Keyword, Name, Comment, String, Error, \
14
+ Number, Operator, Generic, Whitespace
15
+
16
+
17
+ class BorlandStyle(Style):
18
+ """
19
+ Style similar to the style used in the borland IDEs.
20
+ """
21
+
22
+ default_style = ''
23
+
24
+ styles = {
25
+ Whitespace: '#bbbbbb',
26
+
27
+ Comment: 'italic #008800',
28
+ Comment.Preproc: 'noitalic #008080',
29
+ Comment.Special: 'noitalic bold',
30
+
31
+ String: '#0000FF',
32
+ String.Char: '#800080',
33
+ Number: '#0000FF',
34
+ Keyword: 'bold #000080',
35
+ Operator.Word: 'bold',
36
+ Name.Tag: 'bold #000080',
37
+ Name.Attribute: '#FF0000',
38
+
39
+ Generic.Heading: '#999999',
40
+ Generic.Subheading: '#aaaaaa',
41
+ Generic.Deleted: 'bg:#ffdddd #000000',
42
+ Generic.Inserted: 'bg:#ddffdd #000000',
43
+ Generic.Error: '#aa0000',
44
+ Generic.Emph: 'italic',
45
+ Generic.Strong: 'bold',
46
+ Generic.Prompt: '#555555',
47
+ Generic.Output: '#888888',
48
+ Generic.Traceback: '#aa0000',
49
+
50
+ Error: 'bg:#e3d2d2 #a61717'
51
+ }