3 pygments.lexers.text |
3 pygments.lexers.text |
4 ~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for non-source code file types. |
6 Lexers for non-source code file types. |
7 |
7 |
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2010 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 try: |
|
14 set |
|
15 except NameError: |
|
16 from sets import Set as set |
|
17 from bisect import bisect |
13 from bisect import bisect |
18 |
14 |
19 from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, \ |
15 from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, \ |
20 bygroups, include, using, this, do_insertions |
16 bygroups, include, using, this, do_insertions |
21 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \ |
17 from pygments.token import Punctuation, Text, Comment, Keyword, Name, String, \ |
26 __all__ = ['IniLexer', 'SourcesListLexer', 'BaseMakefileLexer', |
22 __all__ = ['IniLexer', 'SourcesListLexer', 'BaseMakefileLexer', |
27 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer', |
23 'MakefileLexer', 'DiffLexer', 'IrcLogsLexer', 'TexLexer', |
28 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer', |
24 'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer', |
29 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer', |
25 'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer', |
30 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer', |
26 'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer', |
31 'LighttpdConfLexer', 'NginxConfLexer'] |
27 'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer'] |
32 |
28 |
33 |
29 |
34 class IniLexer(RegexLexer): |
30 class IniLexer(RegexLexer): |
35 """ |
31 """ |
36 Lexer for configuration files in INI style. |
32 Lexer for configuration files in INI style. |
169 (r'export\s+', Keyword), |
165 (r'export\s+', Keyword), |
170 # assignment |
166 # assignment |
171 (r'([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n|.*\n)+)', |
167 (r'([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n|.*\n)+)', |
172 bygroups(Name.Variable, Text, Operator, Text, using(BashLexer))), |
168 bygroups(Name.Variable, Text, Operator, Text, using(BashLexer))), |
173 # strings |
169 # strings |
174 (r'"(\\\\|\\"|[^"])*"', String.Double), |
170 (r'(?s)"(\\\\|\\.|[^"\\])*"', String.Double), |
175 (r"'(\\\\|\\'|[^'])*'", String.Single), |
171 (r"(?s)'(\\\\|\\.|[^'\\])*'", String.Single), |
176 # targets |
172 # targets |
177 (r'([^\n:]+)(:+)([ \t]*)', bygroups(Name.Function, Operator, Text), |
173 (r'([^\n:]+)(:+)([ \t]*)', bygroups(Name.Function, Operator, Text), |
178 'block-header'), |
174 'block-header'), |
179 # TODO: add paren handling (grr) |
175 # TODO: add paren handling (grr) |
180 ], |
176 ], |
636 yield item |
632 yield item |
637 |
633 |
638 tokens = { |
634 tokens = { |
639 'root': [ |
635 'root': [ |
640 # Heading with overline |
636 # Heading with overline |
641 (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)(.+)(\n)(\1)(\n)', |
637 (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)' |
|
638 r'(.+)(\n)(\1)(\n)', |
642 bygroups(Generic.Heading, Text, Generic.Heading, |
639 bygroups(Generic.Heading, Text, Generic.Heading, |
643 Text, Generic.Heading, Text)), |
640 Text, Generic.Heading, Text)), |
644 # Plain heading |
641 # Plain heading |
645 (r'^(\S.*)(\n)(={3,}|-{3,}|`{3,}|:{3,}|\.{3,}|\'{3,}|"{3,}|' |
642 (r'^(\S.*)(\n)(={3,}|-{3,}|`{3,}|:{3,}|\.{3,}|\'{3,}|"{3,}|' |
646 r'~{3,}|\^{3,}|_{3,}|\*{3,}|\+{3,}|#{3,})(\n)', |
643 r'~{3,}|\^{3,}|_{3,}|\*{3,}|\+{3,}|#{3,})(\n)', |
656 # Numbered, but keep words at BOL from becoming lists |
653 # Numbered, but keep words at BOL from becoming lists |
657 (r'^(\s*)([A-Z]+\.)( .+\n(?:\1 .+\n)+)', |
654 (r'^(\s*)([A-Z]+\.)( .+\n(?:\1 .+\n)+)', |
658 bygroups(Text, Number, using(this, state='inline'))), |
655 bygroups(Text, Number, using(this, state='inline'))), |
659 (r'^(\s*)(\(?[A-Za-z]+\))( .+\n(?:\1 .+\n)+)', |
656 (r'^(\s*)(\(?[A-Za-z]+\))( .+\n(?:\1 .+\n)+)', |
660 bygroups(Text, Number, using(this, state='inline'))), |
657 bygroups(Text, Number, using(this, state='inline'))), |
|
658 # Line blocks |
|
659 (r'^(\s*)(\|)( .+\n(?:\| .+\n)*)', |
|
660 bygroups(Text, Operator, using(this, state='inline'))), |
661 # Sourcecode directives |
661 # Sourcecode directives |
662 (r'^( *\.\.)(\s*)((?:source)?code)(::)([ \t]*)([^\n]+)' |
662 (r'^( *\.\.)(\s*)((?:source)?code)(::)([ \t]*)([^\n]+)' |
663 r'(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)', |
663 r'(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)', |
664 _handle_sourcecode), |
664 _handle_sourcecode), |
665 # A directive |
665 # A directive |
666 (r'^( *\.\.)(\s*)([\w-]+)(::)(?:([ \t]*)(.+))?', |
666 (r'^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))', |
667 bygroups(Punctuation, Text, Operator.Word, Punctuation, Text, Keyword)), |
667 bygroups(Punctuation, Text, Operator.Word, Punctuation, Text, |
|
668 using(this, state='inline'))), |
668 # A reference target |
669 # A reference target |
669 (r'^( *\.\.)(\s*)([\w\t ]+:)(.*?)$', |
670 (r'^( *\.\.)(\s*)([\w\t ]+:)(.*?)$', |
670 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), |
671 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), |
671 # A footnote target |
672 # A footnote target |
672 (r'^( *\.\.)(\s*)(\[.+\])(.*?)$', |
673 (r'^( *\.\.)(\s*)(\[.+\])(.*?)$', |
673 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), |
674 bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))), |
|
675 # A substitution def |
|
676 (r'^( *\.\.)(\s*)(\|.+\|)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))', |
|
677 bygroups(Punctuation, Text, Name.Tag, Text, Operator.Word, |
|
678 Punctuation, Text, using(this, state='inline'))), |
674 # Comments |
679 # Comments |
675 (r'^ *\.\..*(\n( +.*\n|\n)+)?', Comment.Preproc), |
680 (r'^ *\.\..*(\n( +.*\n|\n)+)?', Comment.Preproc), |
676 # Field list |
681 # Field list |
677 (r'^( *)(:.*?:)([ \t]+)(.*?)$', bygroups(Text, Name.Class, Text, |
682 (r'^( *)(:[a-zA-Z-]+:)(\s*)$', bygroups(Text, Name.Class, Text)), |
678 Name.Function)), |
683 (r'^( *)(:.*?:)([ \t]+)(.*?)$', |
|
684 bygroups(Text, Name.Class, Text, Name.Function)), |
679 # Definition list |
685 # Definition list |
680 (r'^([^ ].*(?<!::)\n)((?:(?: +.*)\n)+)', |
686 (r'^([^ ].*(?<!::)\n)((?:(?: +.*)\n)+)', |
681 bygroups(using(this, state='inline'), using(this, state='inline'))), |
687 bygroups(using(this, state='inline'), using(this, state='inline'))), |
682 # Code blocks |
688 # Code blocks |
683 (r'(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*|)\n)+)', |
689 (r'(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*|)\n)+)', |
685 include('inline'), |
691 include('inline'), |
686 ], |
692 ], |
687 'inline': [ |
693 'inline': [ |
688 (r'\\.', Text), # escape |
694 (r'\\.', Text), # escape |
689 (r'``', String, 'literal'), # code |
695 (r'``', String, 'literal'), # code |
690 (r'(`)(.+?)(`__?)', |
696 (r'(`.+?)(<.+?>)(`__?)', # reference with inline target |
691 bygroups(Punctuation, using(this), Punctuation)), # reference |
697 bygroups(String, String.Interpol, String)), |
692 (r'(`.+?`)(:[a-zA-Z0-9-]+?:)?', |
698 (r'`.+?`__?', String), # reference |
|
699 (r'(`.+?`)(:[a-zA-Z0-9:-]+?:)?', |
693 bygroups(Name.Variable, Name.Attribute)), # role |
700 bygroups(Name.Variable, Name.Attribute)), # role |
694 (r'(:[a-zA-Z0-9-]+?:)(`.+?`)', |
701 (r'(:[a-zA-Z0-9:-]+?:)(`.+?`)', |
695 bygroups(Name.Attribute, Name.Variable)), # user-defined role |
702 bygroups(Name.Attribute, Name.Variable)), # role (content first) |
696 (r'\*\*.+?\*\*', Generic.Strong), # Strong emphasis |
703 (r'\*\*.+?\*\*', Generic.Strong), # Strong emphasis |
697 (r'\*.+?\*', Generic.Emph), # Emphasis |
704 (r'\*.+?\*', Generic.Emph), # Emphasis |
698 (r'\[.*?\]_', String), # Footnote or citation |
705 (r'\[.*?\]_', String), # Footnote or citation |
699 (r'<.+?>', Name.Tag), # Hyperlink |
706 (r'<.+?>', Name.Tag), # Hyperlink |
700 (r'[^\\\n\[*`:]+', Text), |
707 (r'[^\\\n\[*`:]+', Text), |
1011 (r'[\s]+', Text), |
1018 (r'[\s]+', Text), |
1012 (r'[}\)]\s*$', Text, '#pop'), |
1019 (r'[}\)]\s*$', Text, '#pop'), |
1013 (r'[}]', Text), |
1020 (r'[}]', Text), |
1014 (r'[^,]$', Name.Function, '#pop'), |
1021 (r'[^,]$', Name.Function, '#pop'), |
1015 (r'([\+\.a-zA-Z0-9-][\s\n]*)', Name.Function), |
1022 (r'([\+\.a-zA-Z0-9-][\s\n]*)', Name.Function), |
|
1023 (r'\[.*?\]', Name.Entity), |
1016 ], |
1024 ], |
1017 'depend_vers': [ |
1025 'depend_vers': [ |
1018 (r'\),', Text, '#pop'), |
1026 (r'\),', Text, '#pop'), |
1019 (r'\)[^,]', Text, '#pop:2'), |
1027 (r'\)[^,]', Text, '#pop:2'), |
1020 (r'([><=]+)(\s*)([^\)]+)', bygroups(Operator, Text, Number)) |
1028 (r'([><=]+)(\s*)([^\)]+)', bygroups(Operator, Text, Number)) |
1501 (r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Text, String.Regex)), |
1509 (r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Text, String.Regex)), |
1502 (r'[:=~]', Punctuation), |
1510 (r'[:=~]', Punctuation), |
1503 (r'[^\s;#{}$]+', String), # catch all |
1511 (r'[^\s;#{}$]+', String), # catch all |
1504 (r'/[^\s;#]*', Name), # pathname |
1512 (r'/[^\s;#]*', Name), # pathname |
1505 (r'\s+', Text), |
1513 (r'\s+', Text), |
1506 ], |
1514 (r'[$;]', Text), # leftover characters |
1507 } |
1515 ], |
|
1516 } |
|
1517 |
|
1518 |
|
1519 class CMakeLexer(RegexLexer): |
|
1520 """ |
|
1521 Lexer for `CMake <http://cmake.org/Wiki/CMake>`_ files. |
|
1522 |
|
1523 *New in Pygments 1.2.* |
|
1524 """ |
|
1525 name = 'CMake' |
|
1526 aliases = ['cmake'] |
|
1527 filenames = ['*.cmake'] |
|
1528 mimetypes = ['text/x-cmake'] |
|
1529 |
|
1530 tokens = { |
|
1531 'root': [ |
|
1532 #(r'(ADD_CUSTOM_COMMAND|ADD_CUSTOM_TARGET|ADD_DEFINITIONS|' |
|
1533 # r'ADD_DEPENDENCIES|ADD_EXECUTABLE|ADD_LIBRARY|ADD_SUBDIRECTORY|' |
|
1534 # r'ADD_TEST|AUX_SOURCE_DIRECTORY|BUILD_COMMAND|BUILD_NAME|' |
|
1535 # r'CMAKE_MINIMUM_REQUIRED|CONFIGURE_FILE|CREATE_TEST_SOURCELIST|' |
|
1536 # r'ELSE|ELSEIF|ENABLE_LANGUAGE|ENABLE_TESTING|ENDFOREACH|' |
|
1537 # r'ENDFUNCTION|ENDIF|ENDMACRO|ENDWHILE|EXEC_PROGRAM|' |
|
1538 # r'EXECUTE_PROCESS|EXPORT_LIBRARY_DEPENDENCIES|FILE|FIND_FILE|' |
|
1539 # r'FIND_LIBRARY|FIND_PACKAGE|FIND_PATH|FIND_PROGRAM|FLTK_WRAP_UI|' |
|
1540 # r'FOREACH|FUNCTION|GET_CMAKE_PROPERTY|GET_DIRECTORY_PROPERTY|' |
|
1541 # r'GET_FILENAME_COMPONENT|GET_SOURCE_FILE_PROPERTY|' |
|
1542 # r'GET_TARGET_PROPERTY|GET_TEST_PROPERTY|IF|INCLUDE|' |
|
1543 # r'INCLUDE_DIRECTORIES|INCLUDE_EXTERNAL_MSPROJECT|' |
|
1544 # r'INCLUDE_REGULAR_EXPRESSION|INSTALL|INSTALL_FILES|' |
|
1545 # r'INSTALL_PROGRAMS|INSTALL_TARGETS|LINK_DIRECTORIES|' |
|
1546 # r'LINK_LIBRARIES|LIST|LOAD_CACHE|LOAD_COMMAND|MACRO|' |
|
1547 # r'MAKE_DIRECTORY|MARK_AS_ADVANCED|MATH|MESSAGE|OPTION|' |
|
1548 # r'OUTPUT_REQUIRED_FILES|PROJECT|QT_WRAP_CPP|QT_WRAP_UI|REMOVE|' |
|
1549 # r'REMOVE_DEFINITIONS|SEPARATE_ARGUMENTS|SET|' |
|
1550 # r'SET_DIRECTORY_PROPERTIES|SET_SOURCE_FILES_PROPERTIES|' |
|
1551 # r'SET_TARGET_PROPERTIES|SET_TESTS_PROPERTIES|SITE_NAME|' |
|
1552 # r'SOURCE_GROUP|STRING|SUBDIR_DEPENDS|SUBDIRS|' |
|
1553 # r'TARGET_LINK_LIBRARIES|TRY_COMPILE|TRY_RUN|UNSET|' |
|
1554 # r'USE_MANGLED_MESA|UTILITY_SOURCE|VARIABLE_REQUIRES|' |
|
1555 # r'VTK_MAKE_INSTANTIATOR|VTK_WRAP_JAVA|VTK_WRAP_PYTHON|' |
|
1556 # r'VTK_WRAP_TCL|WHILE|WRITE_FILE|' |
|
1557 # r'COUNTARGS)\b', Name.Builtin, 'args'), |
|
1558 (r'\b([A-Za-z_]+)([ \t]*)(\()', bygroups(Name.Builtin, Text, |
|
1559 Punctuation), 'args'), |
|
1560 include('keywords'), |
|
1561 include('ws') |
|
1562 ], |
|
1563 'args': [ |
|
1564 (r'\(', Punctuation, '#push'), |
|
1565 (r'\)', Punctuation, '#pop'), |
|
1566 (r'(\${)(.+?)(})', bygroups(Operator, Name.Variable, Operator)), |
|
1567 (r'(?s)".*?"', String.Double), |
|
1568 (r'\\\S+', String), |
|
1569 (r'[^\)$"# \t\n]+', String), |
|
1570 (r'\n', Text), # explicitly legal |
|
1571 include('keywords'), |
|
1572 include('ws') |
|
1573 ], |
|
1574 'string': [ |
|
1575 |
|
1576 ], |
|
1577 'keywords': [ |
|
1578 (r'\b(WIN32|UNIX|APPLE|CYGWIN|BORLAND|MINGW|MSVC|MSVC_IDE|MSVC60|' |
|
1579 r'MSVC70|MSVC71|MSVC80|MSVC90)\b', Keyword), |
|
1580 ], |
|
1581 'ws': [ |
|
1582 (r'[ \t]+', Text), |
|
1583 (r'#.+\n', Comment), |
|
1584 ] |
|
1585 } |
|
1586 |