6
6
Lexers for functional languages.
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.
17
from sets import Set as set
19
from pygments.lexer import Lexer, RegexLexer, bygroups, using, this, include, \
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
25
19
__all__ = ['SchemeLexer', 'CommonLispLexer', 'HaskellLexer', 'LiterateHaskellLexer',
26
'OcamlLexer', 'ErlangLexer']
20
'OcamlLexer', 'ErlangLexer', 'ErlangShellLexer']
29
23
class SchemeLexer(RegexLexer):
247
241
(r'#\d*Y.*$', Comment.Special),
249
243
# strings and characters
250
(r'"(\\.|[^"])*"', String),
244
(r'"(\\.|[^"\\])*"', String),
252
246
(r":" + symbol, String.Symbol),
253
247
(r"'" + symbol, String.Symbol),
356
350
#(r'--\s*|.*$', Comment.Doc),
357
(r'--.*$', Comment.Single),
351
(r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single),
358
352
(r'{-', Comment.Multiline, 'comment'),
388
382
# Import statements
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'),
486
481
line = match.group()
487
482
m = bird_re.match(line)
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)
492
488
insertions.append((len(code), [(0, Text, line)]))
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),
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'),
671
667
variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
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]))'
675
671
macro_re = r'(?:'+variable_re+r'|'+atom_re+r')'
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),
699
695
(r'\?'+macro_re, Name.Constant),
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),
710
707
(r'(define)(\s*)(\()('+macro_re+r')',
714
711
(atom_re, Name.Entity, '#pop'),
716
class ErlangShellLexer(Lexer):
718
Shell sessions in erl (for Erlang code).
720
*New in Pygments 1.1.*
722
name = 'Erlang erl session'
724
filenames = ['*.erl-sh']
725
mimetypes = ['text/x-erl-shellsession']
727
_prompt_re = re.compile(r'\d+>(?=\s|\Z)')
729
def get_tokens_unprocessed(self, text):
730
erlexer = ErlangLexer(**self.options)
734
for match in line_re.finditer(text):
736
m = self._prompt_re.match(line)
739
insertions.append((len(curcode),
740
[(0, Generic.Prompt, line[:end])]))
741
curcode += line[end:]
744
for item in do_insertions(insertions,
745
erlexer.get_tokens_unprocessed(curcode)):
749
if line.startswith('*'):
750
yield match.start(), Generic.Traceback, line
752
yield match.start(), Generic.Output, line
754
for item in do_insertions(insertions,
755
erlexer.get_tokens_unprocessed(curcode)):