~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/extern/pygments/lexers/functional.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
    Lexers for functional languages.
7
7
 
8
 
    :copyright: 2006-2008 by Georg Brandl, Marek Kubica,
9
 
                Adam Blinkinsop <blinks@acm.org>, Matteo Sasso.
10
 
    :license: BSD, see LICENSE for more details.
 
8
    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
 
9
    :license: BSD, see LICENSE for details.
11
10
"""
12
11
 
13
12
import re
14
 
try:
15
 
    set
16
 
except NameError:
17
 
    from sets import Set as set
18
13
 
19
 
from pygments.lexer import Lexer, RegexLexer, bygroups, using, this, include, \
20
 
     do_insertions
 
14
from pygments.lexer import Lexer, RegexLexer, bygroups, include, do_insertions
21
15
from pygments.token import Text, Comment, Operator, Keyword, Name, \
22
 
     String, Number, Punctuation, Literal
 
16
     String, Number, Punctuation, Literal, Generic
23
17
 
24
18
 
25
19
__all__ = ['SchemeLexer', 'CommonLispLexer', 'HaskellLexer', 'LiterateHaskellLexer',
26
 
           'OcamlLexer', 'ErlangLexer']
 
20
           'OcamlLexer', 'ErlangLexer', 'ErlangShellLexer']
27
21
 
28
22
 
29
23
class SchemeLexer(RegexLexer):
247
241
            (r'#\d*Y.*$', Comment.Special),
248
242
 
249
243
            # strings and characters
250
 
            (r'"(\\.|[^"])*"', String),
 
244
            (r'"(\\.|[^"\\])*"', String),
251
245
            # quoting
252
246
            (r":" + symbol, String.Symbol),
253
247
            (r"'" + symbol, String.Symbol),
354
348
            # Whitespace:
355
349
            (r'\s+', Text),
356
350
            #(r'--\s*|.*$', Comment.Doc),
357
 
            (r'--.*$', Comment.Single),
 
351
            (r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single),
358
352
            (r'{-', Comment.Multiline, 'comment'),
359
353
            # Lexemes:
360
354
            #  Identifiers
387
381
        'import': [
388
382
            # Import statements
389
383
            (r'\s+', Text),
 
384
            (r'"', String, 'string'),
390
385
            # after "funclist" state
391
386
            (r'\)', Punctuation, '#pop'),
392
387
            (r'qualified\b', Keyword),
445
440
            (r'o[0-7]+', String.Escape, '#pop'),
446
441
            (r'x[\da-fA-F]+', String.Escape, '#pop'),
447
442
            (r'\d+', String.Escape, '#pop'),
448
 
            (r'\n\s+\\', String.Escape, '#pop'),
 
443
            (r'\s+\\', String.Escape, '#pop'),
449
444
        ],
450
445
    }
451
446
 
476
471
 
477
472
        style = self.options.get('litstyle')
478
473
        if style is None:
479
 
            style = (text.lstrip()[0] in '%\\') and 'latex' or 'bird'
 
474
            style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'
480
475
 
481
476
        code = ''
482
477
        insertions = []
486
481
                line = match.group()
487
482
                m = bird_re.match(line)
488
483
                if m:
489
 
                    insertions.append((len(code), [(0, Comment.Special, m.group(1))]))
 
484
                    insertions.append((len(code),
 
485
                                       [(0, Comment.Special, m.group(1))]))
490
486
                    code += m.group(2)
491
487
                else:
492
488
                    insertions.append((len(code), [(0, Text, line)]))
555
551
 
556
552
    tokens = {
557
553
        'escape-sequence': [
558
 
            (r'\\[\"\'ntbr]', String.Escape),
 
554
            (r'\\[\\\"\'ntbr]', String.Escape),
559
555
            (r'\\[0-9]{3}', String.Escape),
560
556
            (r'\\x[0-9a-fA-F]{2}', String.Escape),
561
557
        ],
606
602
            (r'\.', Punctuation),
607
603
            (r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace),
608
604
            (r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'),
609
 
            (r'[a-z][a-z0-9_\']*', Name, '#pop'),
 
605
            (r'[a-z_][A-Za-z0-9_\']*', Name, '#pop'),
610
606
        ],
611
607
    }
612
608
 
670
666
 
671
667
    variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
672
668
 
673
 
    escape_re = r'(?:\\(?:[bdefnrstv\'"\\]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
 
669
    escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
674
670
 
675
671
    macro_re = r'(?:'+variable_re+r'|'+atom_re+r')'
676
672
 
693
689
            (r'[+-]?'+base_re+r'#[0-9a-zA-Z]+', Number.Integer),
694
690
            (r'[+-]?\d+', Number.Integer),
695
691
            (r'[+-]?\d+.\d+', Number.Float),
696
 
            (r'[][:_@\".{}()|;,]', Punctuation),
 
692
            (r'[]\[:_@\".{}()|;,]', Punctuation),
697
693
            (variable_re, Name.Variable),
698
694
            (atom_re, Name),
699
695
            (r'\?'+macro_re, Name.Constant),
703
699
        'string': [
704
700
            (escape_re, String.Escape),
705
701
            (r'"', String, '#pop'),
706
 
            (r'~[0-9.*]*[~#+bBcefginpPswWxX]', String.Interpol),
707
 
            (r'[^"\~]+', String),
 
702
            (r'~[0-9.*]*[~#+bBcdefginpPswWxX]', String.Interpol),
 
703
            (r'[^"\\~]+', String),
 
704
            (r'~', String),
708
705
            ],
709
706
        'directive': [
710
707
            (r'(define)(\s*)(\()('+macro_re+r')',
714
711
            (atom_re, Name.Entity, '#pop'),
715
712
            ],
716
713
        }
 
714
 
 
715
 
 
716
class ErlangShellLexer(Lexer):
 
717
    """
 
718
    Shell sessions in erl (for Erlang code).
 
719
 
 
720
    *New in Pygments 1.1.*
 
721
    """
 
722
    name = 'Erlang erl session'
 
723
    aliases = ['erl']
 
724
    filenames = ['*.erl-sh']
 
725
    mimetypes = ['text/x-erl-shellsession']
 
726
 
 
727
    _prompt_re = re.compile(r'\d+>(?=\s|\Z)')
 
728
 
 
729
    def get_tokens_unprocessed(self, text):
 
730
        erlexer = ErlangLexer(**self.options)
 
731
 
 
732
        curcode = ''
 
733
        insertions = []
 
734
        for match in line_re.finditer(text):
 
735
            line = match.group()
 
736
            m = self._prompt_re.match(line)
 
737
            if m is not None:
 
738
                end = m.end()
 
739
                insertions.append((len(curcode),
 
740
                                   [(0, Generic.Prompt, line[:end])]))
 
741
                curcode += line[end:]
 
742
            else:
 
743
                if curcode:
 
744
                    for item in do_insertions(insertions,
 
745
                                    erlexer.get_tokens_unprocessed(curcode)):
 
746
                        yield item
 
747
                    curcode = ''
 
748
                    insertions = []
 
749
                if line.startswith('*'):
 
750
                    yield match.start(), Generic.Traceback, line
 
751
                else:
 
752
                    yield match.start(), Generic.Output, line
 
753
        if curcode:
 
754
            for item in do_insertions(insertions,
 
755
                                      erlexer.get_tokens_unprocessed(curcode)):
 
756
                yield item
 
757