3 pygments.lexers.configs |
3 pygments.lexers.configs |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for configuration file formats. |
6 Lexers for configuration file formats. |
7 |
7 |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
37 'root': [ |
37 'root': [ |
38 (r'\s+', Text), |
38 (r'\s+', Text), |
39 (r'[;#].*', Comment.Single), |
39 (r'[;#].*', Comment.Single), |
40 (r'\[.*?\]$', Keyword), |
40 (r'\[.*?\]$', Keyword), |
41 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
41 (r'(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)', |
42 bygroups(Name.Attribute, Text, Operator, Text, String)) |
42 bygroups(Name.Attribute, Text, Operator, Text, String)), |
43 ] |
43 # standalone option, supported by some INI parsers |
|
44 (r'(.+?)$', Name.Attribute), |
|
45 ], |
44 } |
46 } |
45 |
47 |
46 def analyse_text(text): |
48 def analyse_text(text): |
47 npos = text.find('\n') |
49 npos = text.find('\n') |
48 if npos < 3: |
50 if npos < 3: |
96 |
98 |
97 class PropertiesLexer(RegexLexer): |
99 class PropertiesLexer(RegexLexer): |
98 """ |
100 """ |
99 Lexer for configuration files in Java's properties format. |
101 Lexer for configuration files in Java's properties format. |
100 |
102 |
|
103 Note: trailing whitespace counts as part of the value as per spec |
|
104 |
101 .. versionadded:: 1.4 |
105 .. versionadded:: 1.4 |
102 """ |
106 """ |
103 |
107 |
104 name = 'Properties' |
108 name = 'Properties' |
105 aliases = ['properties', 'jproperties'] |
109 aliases = ['properties', 'jproperties'] |
106 filenames = ['*.properties'] |
110 filenames = ['*.properties'] |
107 mimetypes = ['text/x-java-properties'] |
111 mimetypes = ['text/x-java-properties'] |
108 |
112 |
109 tokens = { |
113 tokens = { |
110 'root': [ |
114 'root': [ |
111 (r'\s+', Text), |
115 (r'^(\w+)([ \t])(\w+\s*)$', bygroups(Name.Attribute, Text, String)), |
112 (r'(?:[;#]|//).*$', Comment), |
116 (r'^\w+(\\[ \t]\w*)*$', Name.Attribute), |
|
117 (r'(^ *)([#!].*)', bygroups(Text, Comment)), |
|
118 # More controversial comments |
|
119 (r'(^ *)((?:;|//).*)', bygroups(Text, Comment)), |
113 (r'(.*?)([ \t]*)([=:])([ \t]*)(.*(?:(?<=\\)\n.*)*)', |
120 (r'(.*?)([ \t]*)([=:])([ \t]*)(.*(?:(?<=\\)\n.*)*)', |
114 bygroups(Name.Attribute, Text, Operator, Text, String)), |
121 bygroups(Name.Attribute, Text, Operator, Text, String)), |
|
122 (r'\s', Text), |
115 ], |
123 ], |
116 } |
124 } |
117 |
125 |
118 |
126 |
119 def _rx_indent(level): |
127 def _rx_indent(level): |
452 |
460 |
453 .. versionadded:: 0.11 |
461 .. versionadded:: 0.11 |
454 """ |
462 """ |
455 name = 'Nginx configuration file' |
463 name = 'Nginx configuration file' |
456 aliases = ['nginx'] |
464 aliases = ['nginx'] |
457 filenames = [] |
465 filenames = ['nginx.conf'] |
458 mimetypes = ['text/x-nginx-conf'] |
466 mimetypes = ['text/x-nginx-conf'] |
459 |
467 |
460 tokens = { |
468 tokens = { |
461 'root': [ |
469 'root': [ |
462 (r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Text, Name)), |
470 (r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Text, Name)), |
596 ], |
604 ], |
597 'string': [ |
605 'string': [ |
598 (r'(".*")', bygroups(String.Double)), |
606 (r'(".*")', bygroups(String.Double)), |
599 ], |
607 ], |
600 'punctuation': [ |
608 'punctuation': [ |
601 (r'[\[\]\(\),.]', Punctuation), |
609 (r'[\[\](),.]', Punctuation), |
602 ], |
610 ], |
603 # Keep this seperate from punctuation - we sometimes want to use different |
611 # Keep this seperate from punctuation - we sometimes want to use different |
604 # Tokens for { } |
612 # Tokens for { } |
605 'curly': [ |
613 'curly': [ |
606 (r'\{', Text.Punctuation), |
614 (r'\{', Text.Punctuation), |
627 This is very simple and minimal. |
635 This is very simple and minimal. |
628 |
636 |
629 .. versionadded:: 2.1 |
637 .. versionadded:: 2.1 |
630 """ |
638 """ |
631 name = 'Termcap' |
639 name = 'Termcap' |
632 aliases = ['termcap',] |
640 aliases = ['termcap'] |
633 |
641 filenames = ['termcap', 'termcap.src'] |
634 filenames = ['termcap', 'termcap.src',] |
|
635 mimetypes = [] |
642 mimetypes = [] |
636 |
643 |
637 # NOTE: |
644 # NOTE: |
638 # * multiline with trailing backslash |
645 # * multiline with trailing backslash |
639 # * separator is ':' |
646 # * separator is ':' |
640 # * to embed colon as data, we must use \072 |
647 # * to embed colon as data, we must use \072 |
641 # * space after separator is not allowed (mayve) |
648 # * space after separator is not allowed (mayve) |
642 tokens = { |
649 tokens = { |
643 'root': [ |
650 'root': [ |
644 (r'^#.*$', Comment), |
651 (r'^#.*$', Comment), |
645 (r'^[^\s#:\|]+', Name.Tag, 'names'), |
652 (r'^[^\s#:|]+', Name.Tag, 'names'), |
646 ], |
653 ], |
647 'names': [ |
654 'names': [ |
648 (r'\n', Text, '#pop'), |
655 (r'\n', Text, '#pop'), |
649 (r':', Punctuation, 'defs'), |
656 (r':', Punctuation, 'defs'), |
650 (r'\|', Punctuation), |
657 (r'\|', Punctuation), |
651 (r'[^:\|]+', Name.Attribute), |
658 (r'[^:|]+', Name.Attribute), |
652 ], |
659 ], |
653 'defs': [ |
660 'defs': [ |
654 (r'\\\n[ \t]*', Text), |
661 (r'\\\n[ \t]*', Text), |
655 (r'\n[ \t]*', Text, '#pop:2'), |
662 (r'\n[ \t]*', Text, '#pop:2'), |
656 (r'(#)([0-9]+)', bygroups(Operator, Number)), |
663 (r'(#)([0-9]+)', bygroups(Operator, Number)), |
674 This is very simple and minimal. |
681 This is very simple and minimal. |
675 |
682 |
676 .. versionadded:: 2.1 |
683 .. versionadded:: 2.1 |
677 """ |
684 """ |
678 name = 'Terminfo' |
685 name = 'Terminfo' |
679 aliases = ['terminfo',] |
686 aliases = ['terminfo'] |
680 |
687 filenames = ['terminfo', 'terminfo.src'] |
681 filenames = ['terminfo', 'terminfo.src',] |
|
682 mimetypes = [] |
688 mimetypes = [] |
683 |
689 |
684 # NOTE: |
690 # NOTE: |
685 # * multiline with leading whitespace |
691 # * multiline with leading whitespace |
686 # * separator is ',' |
692 # * separator is ',' |
687 # * to embed comma as data, we can use \, |
693 # * to embed comma as data, we can use \, |
688 # * space after separator is allowed |
694 # * space after separator is allowed |
689 tokens = { |
695 tokens = { |
690 'root': [ |
696 'root': [ |
691 (r'^#.*$', Comment), |
697 (r'^#.*$', Comment), |
692 (r'^[^\s#,\|]+', Name.Tag, 'names'), |
698 (r'^[^\s#,|]+', Name.Tag, 'names'), |
693 ], |
699 ], |
694 'names': [ |
700 'names': [ |
695 (r'\n', Text, '#pop'), |
701 (r'\n', Text, '#pop'), |
696 (r'(,)([ \t]*)', bygroups(Punctuation, Text), 'defs'), |
702 (r'(,)([ \t]*)', bygroups(Punctuation, Text), 'defs'), |
697 (r'\|', Punctuation), |
703 (r'\|', Punctuation), |
698 (r'[^,\|]+', Name.Attribute), |
704 (r'[^,|]+', Name.Attribute), |
699 ], |
705 ], |
700 'defs': [ |
706 'defs': [ |
701 (r'\n[ \t]+', Text), |
707 (r'\n[ \t]+', Text), |
702 (r'\n', Text, '#pop:2'), |
708 (r'\n', Text, '#pop:2'), |
703 (r'(#)([0-9]+)', bygroups(Operator, Number)), |
709 (r'(#)([0-9]+)', bygroups(Operator, Number)), |