~ubuntu-branches/debian/squeeze/pygments/squeeze

« back to all changes in this revision

Viewing changes to pygments/lexers/text.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2010-03-02 20:06:16 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100302200616-gp11whnuehwj27cr
Tags: 1.3+dfsg-1
* New upstream release
  - install Bash completion script for pygmentize
* Standards-Version bumped to 3.8.4 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
"""
11
11
 
12
12
import re
13
 
try:
14
 
    set
15
 
except NameError:
16
 
    from sets import Set as set
17
13
from bisect import bisect
18
14
 
19
15
from pygments.lexer import Lexer, LexerContext, RegexLexer, ExtendedRegexLexer, \
638
634
    tokens = {
639
635
        'root': [
640
636
            # Heading with overline
641
 
            (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)(.+)(\n)(\1)(\n)',
 
637
            (r'^(=+|-+|`+|:+|\.+|\'+|"+|~+|\^+|_+|\*+|\++|#+)([ \t]*\n)'
 
638
             r'(.+)(\n)(\1)(\n)',
642
639
             bygroups(Generic.Heading, Text, Generic.Heading,
643
640
                      Text, Generic.Heading, Text)),
644
641
            # Plain heading
658
655
             bygroups(Text, Number, using(this, state='inline'))),
659
656
            (r'^(\s*)(\(?[A-Za-z]+\))( .+\n(?:\1  .+\n)+)',
660
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
661
            # Sourcecode directives
662
662
            (r'^( *\.\.)(\s*)((?:source)?code)(::)([ \t]*)([^\n]+)'
663
663
             r'(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)',
664
664
             _handle_sourcecode),
665
665
            # A directive
666
 
            (r'^( *\.\.)(\s*)([\w-]+)(::)(?:([ \t]*)(.+))?',
667
 
             bygroups(Punctuation, Text, Operator.Word, Punctuation, Text, Keyword)),
 
666
            (r'^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))',
 
667
             bygroups(Punctuation, Text, Operator.Word, Punctuation, Text,
 
668
                      using(this, state='inline'))),
668
669
            # A reference target
669
670
            (r'^( *\.\.)(\s*)([\w\t ]+:)(.*?)$',
670
671
             bygroups(Punctuation, Text, Name.Tag, using(this, state='inline'))),
671
672
            # A footnote target
672
673
            (r'^( *\.\.)(\s*)(\[.+\])(.*?)$',
673
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
679
            # Comments
675
680
            (r'^ *\.\..*(\n( +.*\n|\n)+)?', Comment.Preproc),
676
681
            # Field list
677
 
            (r'^( *)(:.*?:)([ \t]+)(.*?)$', bygroups(Text, Name.Class, Text,
678
 
                                                     Name.Function)),
 
682
            (r'^( *)(:[a-zA-Z-]+:)(\s*)$', bygroups(Text, Name.Class, Text)),
 
683
            (r'^( *)(:.*?:)([ \t]+)(.*?)$',
 
684
             bygroups(Text, Name.Class, Text, Name.Function)),
679
685
            # Definition list
680
686
            (r'^([^ ].*(?<!::)\n)((?:(?: +.*)\n)+)',
681
687
             bygroups(using(this, state='inline'), using(this, state='inline'))),
687
693
        'inline': [
688
694
            (r'\\.', Text), # escape
689
695
            (r'``', String, 'literal'), # code
690
 
            (r'(`)(.+?)(`__?)',
691
 
             bygroups(Punctuation, using(this), Punctuation)), # reference
692
 
            (r'(`.+?`)(:[a-zA-Z0-9-]+?:)?',
 
696
            (r'(`.+?)(<.+?>)(`__?)',  # reference with inline target
 
697
             bygroups(String, String.Interpol, String)),
 
698
            (r'`.+?`__?', String), # reference
 
699
            (r'(`.+?`)(:[a-zA-Z0-9:-]+?:)?',
693
700
             bygroups(Name.Variable, Name.Attribute)), # role
694
 
            (r'(:[a-zA-Z0-9-]+?:)(`.+?`)',
695
 
             bygroups(Name.Attribute, Name.Variable)), # user-defined role
 
701
            (r'(:[a-zA-Z0-9:-]+?:)(`.+?`)',
 
702
             bygroups(Name.Attribute, Name.Variable)), # role (content first)
696
703
            (r'\*\*.+?\*\*', Generic.Strong), # Strong emphasis
697
704
            (r'\*.+?\*', Generic.Emph), # Emphasis
698
705
            (r'\[.*?\]_', String), # Footnote or citation
1013
1020
            (r'[}]', Text),
1014
1021
            (r'[^,]$', Name.Function, '#pop'),
1015
1022
            (r'([\+\.a-zA-Z0-9-][\s\n]*)', Name.Function),
 
1023
            (r'\[.*?\]', Name.Entity),
1016
1024
        ],
1017
1025
        'depend_vers': [
1018
1026
            (r'\),', Text, '#pop'),
1503
1511
            (r'[^\s;#{}$]+', String), # catch all
1504
1512
            (r'/[^\s;#]*', Name), # pathname
1505
1513
            (r'\s+', Text),
 
1514
            (r'[$;]', Text),  # leftover characters
1506
1515
        ],
1507
1516
    }
1508
1517