17 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \ |
17 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \ |
18 Generic, Operator, Number, Whitespace, Literal |
18 Generic, Operator, Number, Whitespace, Literal |
19 from pygments.util import get_bool_opt |
19 from pygments.util import get_bool_opt |
20 from pygments.lexers.other import BashLexer |
20 from pygments.lexers.other import BashLexer |
21 |
21 |
22 __all__ = ['IniLexer', 'SourcesListLexer', 'BaseMakefileLexer', |
22 __all__ = ['IniLexer', 'PropertiesLexer', 'SourcesListLexer', 'BaseMakefileLexer', |
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'] |
27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer'] |
32 Lexer for configuration files in INI style. |
32 Lexer for configuration files in INI style. |
33 """ |
33 """ |
34 |
34 |
35 name = 'INI' |
35 name = 'INI' |
36 aliases = ['ini', 'cfg'] |
36 aliases = ['ini', 'cfg'] |
37 filenames = ['*.ini', '*.cfg', '*.properties'] |
37 filenames = ['*.ini', '*.cfg'] |
38 mimetypes = ['text/x-ini'] |
38 mimetypes = ['text/x-ini'] |
39 |
39 |
40 tokens = { |
40 tokens = { |
41 'root': [ |
41 'root': [ |
42 (r'\s+', Text), |
42 (r'\s+', Text), |
43 (r'[;#].*?$', Comment), |
43 (r'[;#].*?$', Comment), |
44 (r'\[.*?\]$', Keyword), |
44 (r'\[.*?\]$', Keyword), |
45 (r'(.*?)([ \t]*)(=)([ \t]*)(.*?)$', |
45 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
46 bygroups(Name.Attribute, Text, Operator, Text, String)) |
46 bygroups(Name.Attribute, Text, Operator, Text, String)) |
47 ] |
47 ] |
48 } |
48 } |
49 |
49 |
50 def analyse_text(text): |
50 def analyse_text(text): |
51 npos = text.find('\n') |
51 npos = text.find('\n') |
52 if npos < 3: |
52 if npos < 3: |
53 return False |
53 return False |
54 return text[0] == '[' and text[npos-1] == ']' |
54 return text[0] == '[' and text[npos-1] == ']' |
|
55 |
|
56 |
|
57 class PropertiesLexer(RegexLexer): |
|
58 """ |
|
59 Lexer for configuration files in Java's properties format. |
|
60 |
|
61 *New in Pygments 1.4.* |
|
62 """ |
|
63 |
|
64 name = 'Properties' |
|
65 aliases = ['properties'] |
|
66 filenames = ['*.properties'] |
|
67 mimetypes = ['text/x-java-properties'] |
|
68 |
|
69 tokens = { |
|
70 'root': [ |
|
71 (r'\s+', Text), |
|
72 (r'(?:[;#]|//).*$', Comment), |
|
73 (r'(.*?)([ \t]*)([=:])([ \t]*)(.*(?:(?<=\\)\n.*)*)', |
|
74 bygroups(Name.Attribute, Text, Operator, Text, String)), |
|
75 ], |
|
76 } |
55 |
77 |
56 |
78 |
57 class SourcesListLexer(RegexLexer): |
79 class SourcesListLexer(RegexLexer): |
58 """ |
80 """ |
59 Lexer that highlights debian sources.list files. |
81 Lexer that highlights debian sources.list files. |
828 'root': [ |
850 'root': [ |
829 (r'^#,\s.*?$', Keyword.Type), |
851 (r'^#,\s.*?$', Keyword.Type), |
830 (r'^#:\s.*?$', Keyword.Declaration), |
852 (r'^#:\s.*?$', Keyword.Declaration), |
831 #(r'^#$', Comment), |
853 #(r'^#$', Comment), |
832 (r'^(#|#\.\s|#\|\s|#~\s|#\s).*$', Comment.Single), |
854 (r'^(#|#\.\s|#\|\s|#~\s|#\s).*$', Comment.Single), |
833 (r'^(")([\w-]*:)(.*")$', |
855 (r'^(")([A-Za-z-]+:)(.*")$', |
834 bygroups(String, Name.Property, String)), |
856 bygroups(String, Name.Property, String)), |
835 (r'^".*"$', String), |
857 (r'^".*"$', String), |
836 (r'^(msgid|msgid_plural|msgstr)(\s+)(".*")$', |
858 (r'^(msgid|msgid_plural|msgstr)(\s+)(".*")$', |
837 bygroups(Name.Variable, Text, String)), |
859 bygroups(Name.Variable, Text, String)), |
838 (r'^(msgstr\[)(\d)(\])(\s+)(".*")$', |
860 (r'^(msgstr\[)(\d)(\])(\s+)(".*")$', |