23 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer', |
23 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer', |
24 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer', |
24 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer', |
25 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer', |
25 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer', |
26 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer', |
26 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer', |
27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer', 'HttpLexer', |
27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer', 'HttpLexer', |
28 'PyPyLogLexer'] |
28 'PyPyLogLexer', 'RegeditLexer', 'HxmlLexer'] |
29 |
29 |
30 |
30 |
31 class IniLexer(RegexLexer): |
31 class IniLexer(RegexLexer): |
32 """ |
32 """ |
33 Lexer for configuration files in INI style. |
33 Lexer for configuration files in INI style. |
39 mimetypes = ['text/x-ini'] |
39 mimetypes = ['text/x-ini'] |
40 |
40 |
41 tokens = { |
41 tokens = { |
42 'root': [ |
42 'root': [ |
43 (r'\s+', Text), |
43 (r'\s+', Text), |
44 (r'[;#].*?$', Comment), |
44 (r'[;#].*', Comment.Single), |
45 (r'\[.*?\]$', Keyword), |
45 (r'\[.*?\]$', Keyword), |
46 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
46 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
47 bygroups(Name.Attribute, Text, Operator, Text, String)) |
47 bygroups(Name.Attribute, Text, Operator, Text, String)) |
48 ] |
48 ] |
49 } |
49 } |
51 def analyse_text(text): |
51 def analyse_text(text): |
52 npos = text.find('\n') |
52 npos = text.find('\n') |
53 if npos < 3: |
53 if npos < 3: |
54 return False |
54 return False |
55 return text[0] == '[' and text[npos-1] == ']' |
55 return text[0] == '[' and text[npos-1] == ']' |
|
56 |
|
57 |
|
58 class RegeditLexer(RegexLexer): |
|
59 """ |
|
60 Lexer for `Windows Registry |
|
61 <http://en.wikipedia.org/wiki/Windows_Registry#.REG_files>`_ files produced |
|
62 by regedit. |
|
63 |
|
64 *New in Pygments 1.6.* |
|
65 """ |
|
66 |
|
67 name = 'reg' |
|
68 aliases = ['registry'] |
|
69 filenames = ['*.reg'] |
|
70 mimetypes = ['text/x-windows-registry'] |
|
71 |
|
72 tokens = { |
|
73 'root': [ |
|
74 (r'Windows Registry Editor.*', Text), |
|
75 (r'\s+', Text), |
|
76 (r'[;#].*', Comment.Single), |
|
77 (r'(\[)(-?)(HKEY_[A-Z_]+)(.*?\])$', |
|
78 bygroups(Keyword, Operator, Name.Builtin, Keyword)), |
|
79 # String keys, which obey somewhat normal escaping |
|
80 (r'("(?:\\"|\\\\|[^"])+")([ \t]*)(=)([ \t]*)', |
|
81 bygroups(Name.Attribute, Text, Operator, Text), |
|
82 'value'), |
|
83 # Bare keys (includes @) |
|
84 (r'(.*?)([ \t]*)(=)([ \t]*)', |
|
85 bygroups(Name.Attribute, Text, Operator, Text), |
|
86 'value'), |
|
87 ], |
|
88 'value': [ |
|
89 (r'-', Operator, '#pop'), # delete value |
|
90 (r'(dword|hex(?:\([0-9a-fA-F]\))?)(:)([0-9a-fA-F,]+)', |
|
91 bygroups(Name.Variable, Punctuation, Number), '#pop'), |
|
92 # As far as I know, .reg files do not support line continuation. |
|
93 (r'.*', String, '#pop'), |
|
94 ] |
|
95 } |
|
96 |
|
97 def analyse_text(text): |
|
98 return text.startswith('Windows Registry Editor') |
56 |
99 |
57 |
100 |
58 class PropertiesLexer(RegexLexer): |
101 class PropertiesLexer(RegexLexer): |
59 """ |
102 """ |
60 Lexer for configuration files in Java's properties format. |
103 Lexer for configuration files in Java's properties format. |
185 (r'#.*?\n', Comment), |
228 (r'#.*?\n', Comment), |
186 (r'(export)(\s+)(?=[a-zA-Z0-9_${}\t -]+\n)', |
229 (r'(export)(\s+)(?=[a-zA-Z0-9_${}\t -]+\n)', |
187 bygroups(Keyword, Text), 'export'), |
230 bygroups(Keyword, Text), 'export'), |
188 (r'export\s+', Keyword), |
231 (r'export\s+', Keyword), |
189 # assignment |
232 # assignment |
190 (r'([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n|.*\n)+)', |
233 (r'([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n)+|.*\n)', |
191 bygroups(Name.Variable, Text, Operator, Text, using(BashLexer))), |
234 bygroups(Name.Variable, Text, Operator, Text, using(BashLexer))), |
192 # strings |
235 # strings |
193 (r'(?s)"(\\\\|\\.|[^"\\])*"', String.Double), |
236 (r'(?s)"(\\\\|\\.|[^"\\])*"', String.Double), |
194 (r"(?s)'(\\\\|\\.|[^'\\])*'", String.Single), |
237 (r"(?s)'(\\\\|\\.|[^'\\])*'", String.Single), |
195 # targets |
238 # targets |
526 'root': [ |
569 'root': [ |
527 (r'\s+', Text), |
570 (r'\s+', Text), |
528 (r'(#.*?)$', Comment), |
571 (r'(#.*?)$', Comment), |
529 (r'(<[^\s>]+)(?:(\s+)(.*?))?(>)', |
572 (r'(<[^\s>]+)(?:(\s+)(.*?))?(>)', |
530 bygroups(Name.Tag, Text, String, Name.Tag)), |
573 bygroups(Name.Tag, Text, String, Name.Tag)), |
531 (r'([a-zA-Z][a-zA-Z0-9]*)(\s+)', |
574 (r'([a-zA-Z][a-zA-Z0-9_]*)(\s+)', |
532 bygroups(Name.Builtin, Text), 'value'), |
575 bygroups(Name.Builtin, Text), 'value'), |
533 (r'\.+', Text), |
576 (r'\.+', Text), |
534 ], |
577 ], |
535 'value': [ |
578 'value': [ |
536 (r'$', Text, '#pop'), |
579 (r'$', Text, '#pop'), |
571 # Literal code blocks, with optional shebang |
614 # Literal code blocks, with optional shebang |
572 (r'({{{)(\n#!.+)?', bygroups(Name.Builtin, Name.Namespace), 'codeblock'), |
615 (r'({{{)(\n#!.+)?', bygroups(Name.Builtin, Name.Namespace), 'codeblock'), |
573 (r'(\'\'\'?|\|\||`|__|~~|\^|,,|::)', Comment), # Formatting |
616 (r'(\'\'\'?|\|\||`|__|~~|\^|,,|::)', Comment), # Formatting |
574 # Lists |
617 # Lists |
575 (r'^( +)([.*-])( )', bygroups(Text, Name.Builtin, Text)), |
618 (r'^( +)([.*-])( )', bygroups(Text, Name.Builtin, Text)), |
576 (r'^( +)([a-zivx]{1,5}\.)( )', bygroups(Text, Name.Builtin, Text)), |
619 (r'^( +)([a-z]{1,5}\.)( )', bygroups(Text, Name.Builtin, Text)), |
577 # Other Formatting |
620 # Other Formatting |
578 (r'\[\[\w+.*?\]\]', Keyword), # Macro |
621 (r'\[\[\w+.*?\]\]', Keyword), # Macro |
579 (r'(\[[^\s\]]+)(\s+[^\]]+?)?(\])', |
622 (r'(\[[^\s\]]+)(\s+[^\]]+?)?(\])', |
580 bygroups(Keyword, String, Keyword)), # Link |
623 bygroups(Keyword, String, Keyword)), # Link |
581 (r'^----+$', Keyword), # Horizontal rules |
624 (r'^----+$', Keyword), # Horizontal rules |
1641 yield match.start(3), Operator, match.group(3) |
1684 yield match.start(3), Operator, match.group(3) |
1642 yield match.start(4), Text, match.group(4) |
1685 yield match.start(4), Text, match.group(4) |
1643 yield match.start(5), Literal, match.group(5) |
1686 yield match.start(5), Literal, match.group(5) |
1644 yield match.start(6), Text, match.group(6) |
1687 yield match.start(6), Text, match.group(6) |
1645 |
1688 |
|
1689 def continuous_header_callback(self, match): |
|
1690 yield match.start(1), Text, match.group(1) |
|
1691 yield match.start(2), Literal, match.group(2) |
|
1692 yield match.start(3), Text, match.group(3) |
|
1693 |
1646 def content_callback(self, match): |
1694 def content_callback(self, match): |
1647 content_type = getattr(self, 'content_type', None) |
1695 content_type = getattr(self, 'content_type', None) |
1648 content = match.group() |
1696 content = match.group() |
1649 offset = match.start() |
1697 offset = match.start() |
1650 if content_type: |
1698 if content_type: |
1671 Text, Name.Exception, Text), |
1719 Text, Name.Exception, Text), |
1672 'headers'), |
1720 'headers'), |
1673 ], |
1721 ], |
1674 'headers': [ |
1722 'headers': [ |
1675 (r'([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|$)', header_callback), |
1723 (r'([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|$)', header_callback), |
|
1724 (r'([\t ]+)([^\r\n]+)(\r?\n|$)', continuous_header_callback), |
1676 (r'\r?\n', Text, 'content') |
1725 (r'\r?\n', Text, 'content') |
1677 ], |
1726 ], |
1678 'content': [ |
1727 'content': [ |
1679 (r'.+', content_callback) |
1728 (r'.+', content_callback) |
1680 ] |
1729 ] |
1698 (r"\[\w+\] {jit-backend-counts$", Keyword, "jit-backend-counts"), |
1747 (r"\[\w+\] {jit-backend-counts$", Keyword, "jit-backend-counts"), |
1699 include("extra-stuff"), |
1748 include("extra-stuff"), |
1700 ], |
1749 ], |
1701 "jit-log": [ |
1750 "jit-log": [ |
1702 (r"\[\w+\] jit-log-.*?}$", Keyword, "#pop"), |
1751 (r"\[\w+\] jit-log-.*?}$", Keyword, "#pop"), |
1703 |
|
1704 (r"^\+\d+: ", Comment), |
1752 (r"^\+\d+: ", Comment), |
|
1753 (r"--end of the loop--", Comment), |
1705 (r"[ifp]\d+", Name), |
1754 (r"[ifp]\d+", Name), |
1706 (r"ptr\d+", Name), |
1755 (r"ptr\d+", Name), |
1707 (r"(\()(\w+(?:\.\w+)?)(\))", |
1756 (r"(\()(\w+(?:\.\w+)?)(\))", |
1708 bygroups(Punctuation, Name.Builtin, Punctuation)), |
1757 bygroups(Punctuation, Name.Builtin, Punctuation)), |
1709 (r"[\[\]=,()]", Punctuation), |
1758 (r"[\[\]=,()]", Punctuation), |
1710 (r"(\d+\.\d+|inf|-inf)", Number.Float), |
1759 (r"(\d+\.\d+|inf|-inf)", Number.Float), |
1711 (r"-?\d+", Number.Integer), |
1760 (r"-?\d+", Number.Integer), |
1712 (r"'.*'", String), |
1761 (r"'.*'", String), |
1713 (r"(None|descr|ConstClass|ConstPtr|TargetToken)", Name), |
1762 (r"(None|descr|ConstClass|ConstPtr|TargetToken)", Name), |
1714 (r"<.*?>", Name.Builtin), |
1763 (r"<.*?>+", Name.Builtin), |
1715 (r"(label|debug_merge_point|jump|finish)", Name.Class), |
1764 (r"(label|debug_merge_point|jump|finish)", Name.Class), |
1716 (r"(int_add_ovf|int_add|int_sub_ovf|int_sub|int_mul_ovf|int_mul|" |
1765 (r"(int_add_ovf|int_add|int_sub_ovf|int_sub|int_mul_ovf|int_mul|" |
1717 r"int_floordiv|int_mod|int_lshift|int_rshift|int_and|int_or|" |
1766 r"int_floordiv|int_mod|int_lshift|int_rshift|int_and|int_or|" |
1718 r"int_xor|int_eq|int_ne|int_ge|int_gt|int_le|int_lt|int_is_zero|" |
1767 r"int_xor|int_eq|int_ne|int_ge|int_gt|int_le|int_lt|int_is_zero|" |
1719 r"int_is_true|" |
1768 r"int_is_true|" |
1720 r"uint_floordiv|uint_ge|uint_lt|" |
1769 r"uint_floordiv|uint_ge|uint_lt|" |
1721 r"float_add|float_sub|float_mul|float_truediv|" |
1770 r"float_add|float_sub|float_mul|float_truediv|float_neg|" |
1722 r"float_eq|float_ne|float_ge|float_gt|float_le|float_lt|float_abs|" |
1771 r"float_eq|float_ne|float_ge|float_gt|float_le|float_lt|float_abs|" |
1723 r"ptr_eq|ptr_ne|instance_ptr_eq|instance_ptr_ne|" |
1772 r"ptr_eq|ptr_ne|instance_ptr_eq|instance_ptr_ne|" |
1724 r"cast_int_to_float|cast_float_to_int|" |
1773 r"cast_int_to_float|cast_float_to_int|" |
1725 r"force_token|quasiimmut_field|same_as|virtual_ref_finish|" |
1774 r"force_token|quasiimmut_field|same_as|virtual_ref_finish|" |
1726 r"virtual_ref|mark_opaque_ptr|" |
1775 r"virtual_ref|mark_opaque_ptr|" |
1749 "extra-stuff": [ |
1798 "extra-stuff": [ |
1750 (r"\s+", Text), |
1799 (r"\s+", Text), |
1751 (r"#.*?$", Comment), |
1800 (r"#.*?$", Comment), |
1752 ], |
1801 ], |
1753 } |
1802 } |
|
1803 |
|
1804 |
|
1805 class HxmlLexer(RegexLexer): |
|
1806 """ |
|
1807 Lexer for `haXe build <http://haxe.org/doc/compiler>`_ files. |
|
1808 |
|
1809 *New in Pygments 1.6.* |
|
1810 """ |
|
1811 name = 'Hxml' |
|
1812 aliases = ['haxeml', 'hxml'] |
|
1813 filenames = ['*.hxml'] |
|
1814 |
|
1815 tokens = { |
|
1816 'root': [ |
|
1817 # Seperator |
|
1818 (r'(--)(next)', bygroups(Punctuation, Generic.Heading)), |
|
1819 # Compiler switches with one dash |
|
1820 (r'(-)(prompt|debug|v)', bygroups(Punctuation, Keyword.Keyword)), |
|
1821 # Compilerswitches with two dashes |
|
1822 (r'(--)(neko-source|flash-strict|flash-use-stage|no-opt|no-traces|' |
|
1823 r'no-inline|times|no-output)', bygroups(Punctuation, Keyword)), |
|
1824 # Targets and other options that take an argument |
|
1825 (r'(-)(cpp|js|neko|x|as3|swf9?|swf-lib|php|xml|main|lib|D|resource|' |
|
1826 r'cp|cmd)( +)(.+)', |
|
1827 bygroups(Punctuation, Keyword, Whitespace, String)), |
|
1828 # Options that take only numerical arguments |
|
1829 (r'(-)(swf-version)( +)(\d+)', |
|
1830 bygroups(Punctuation, Keyword, Number.Integer)), |
|
1831 # An Option that defines the size, the fps and the background |
|
1832 # color of an flash movie |
|
1833 (r'(-)(swf-header)( +)(\d+)(:)(\d+)(:)(\d+)(:)([A-Fa-f0-9]{6})', |
|
1834 bygroups(Punctuation, Keyword, Whitespace, Number.Integer, |
|
1835 Punctuation, Number.Integer, Punctuation, Number.Integer, |
|
1836 Punctuation, Number.Hex)), |
|
1837 # options with two dashes that takes arguments |
|
1838 (r'(--)(js-namespace|php-front|php-lib|remap|gen-hx-classes)( +)' |
|
1839 r'(.+)', bygroups(Punctuation, Keyword, Whitespace, String)), |
|
1840 # Single line comment, multiline ones are not allowed. |
|
1841 (r'#.*', Comment.Single) |
|
1842 ] |
|
1843 } |