summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-01-10 22:08:47 +0100
committerGeorg Brandl <georg@python.org>2013-01-10 22:08:47 +0100
commit9cb1d1bf01faebecd931a52624189866497309c6 (patch)
tree4cda4b0d77de288d0d4131ef323b86007ad98b9a
parent77ba79b75a2660af2cfd8ae9a072b9d56ccd961d (diff)
parent2b9b06b9ef49e0d495fef410e78a7723ddbde9d5 (diff)
downloadpygments-9cb1d1bf01faebecd931a52624189866497309c6.tar.gz
Merged in waywardmonkeys/pygments-main (pull request #149: [dylan] Add DylanConsoleLexer.)
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/compiled.py67
-rw-r--r--tests/examplefiles/classes.dylan2
-rw-r--r--tests/examplefiles/session.dylan-console9
4 files changed, 72 insertions, 7 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index f3b711f4..e273734a 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -88,6 +88,7 @@ LEXERS = {
'DjangoLexer': ('pygments.lexers.templates', 'Django/Jinja', ('django', 'jinja'), (), ('application/x-django-templating', 'application/x-jinja')),
'DtdLexer': ('pygments.lexers.web', 'DTD', ('dtd',), ('*.dtd',), ('application/xml-dtd',)),
'DuelLexer': ('pygments.lexers.web', 'Duel', ('duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST'), ('*.duel', '*.jbst'), ('text/x-duel', 'text/x-jbst')),
+ 'DylanConsoleLexer': ('pygments.lexers.compiled', 'Dylan session', ('dylan-console', 'dylan-repl'), ('*.dylan-console',), ('text/x-dylan-console',)),
'DylanLexer': ('pygments.lexers.compiled', 'Dylan', ('dylan',), ('*.dylan', '*.dyl', '*.intr'), ('text/x-dylan',)),
'DylanLidLexer': ('pygments.lexers.compiled', 'DylanLID', ('dylan-lid', 'lid'), ('*.lid', '*.hdp'), ('text/x-dylan-lid',)),
'ECLLexer': ('pygments.lexers.other', 'ECL', ('ecl',), ('*.ecl',), ('application/x-ecl',)),
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 0336b7e0..65cf2778 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -13,10 +13,10 @@ import re
from string import Template
from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
- this, combined, inherit
+ this, combined, inherit, do_insertions
from pygments.util import get_bool_opt, get_list_opt
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
- Number, Punctuation, Error, Literal
+ Number, Punctuation, Error, Literal, Generic
from pygments.scanner import Scanner
# backwards compatibility
@@ -28,7 +28,8 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer
'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
- 'DylanLidLexer', 'CobolLexer', 'CobolFreeformatLexer', 'LogosLexer']
+ 'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
+ 'CobolFreeformatLexer', 'LogosLexer']
class CFamilyLexer(RegexLexer):
@@ -974,16 +975,17 @@ class DylanLexer(RegexLexer):
def get_tokens_unprocessed(self, text):
for index, token, value in RegexLexer.get_tokens_unprocessed(self, text):
if token is Name:
- if value in self.builtins:
+ lowercase_value = value.lower()
+ if lowercase_value in self.builtins:
yield index, Name.Builtin, value
continue
- if value in self.keywords:
+ if lowercase_value in self.keywords:
yield index, Keyword, value
continue
- if value in self.functions:
+ if lowercase_value in self.functions:
yield index, Name.Builtin, value
continue
- if value in self.operators:
+ if lowercase_value in self.operators:
yield index, Operator, value
continue
yield index, token, value
@@ -1118,6 +1120,57 @@ class DylanLidLexer(RegexLexer):
]
}
+
+class DylanConsoleLexer(Lexer):
+ """
+ For Dylan interactive console output like:
+
+ .. sourcecode:: dylan-console
+
+ ? let a = 1;
+ => 1
+ ? a
+ => 1
+
+ This is based on a copy of the RubyConsoleLexer.
+
+ *New in Pygments 1.6.*
+ """
+ name = 'Dylan session'
+ aliases = ['dylan-console', 'dylan-repl']
+ filenames = ['*.dylan-console']
+ mimetypes = ['text/x-dylan-console']
+
+ _line_re = re.compile('.*?\n')
+ _prompt_re = re.compile('\?| ')
+
+ def get_tokens_unprocessed(self, text):
+ dylexer = DylanLexer(**self.options)
+
+ curcode = ''
+ insertions = []
+ for match in self._line_re.finditer(text):
+ line = match.group()
+ m = self._prompt_re.match(line)
+ if m is not None:
+ end = m.end()
+ insertions.append((len(curcode),
+ [(0, Generic.Prompt, line[:end])]))
+ curcode += line[end:]
+ else:
+ if curcode:
+ for item in do_insertions(insertions,
+ dylexer.get_tokens_unprocessed(curcode)):
+ yield item
+ curcode = ''
+ insertions = []
+ yield match.start(), Generic.Output, line
+ if curcode:
+ for item in do_insertions(insertions,
+ dylexer.get_tokens_unprocessed(curcode)):
+ yield item
+
+
def objective(baselexer):
"""
Generate a subclass of baselexer that accepts the Objective-C syntax
diff --git a/tests/examplefiles/classes.dylan b/tests/examplefiles/classes.dylan
index 7bb88faa..83faf69c 100644
--- a/tests/examplefiles/classes.dylan
+++ b/tests/examplefiles/classes.dylan
@@ -121,3 +121,5 @@ define macro with-decoded-seconds
}
end macro;
+let x = "This size call should be seen as a builtin despite the odd case.".siZe;
+
diff --git a/tests/examplefiles/session.dylan-console b/tests/examplefiles/session.dylan-console
new file mode 100644
index 00000000..6f289c8e
--- /dev/null
+++ b/tests/examplefiles/session.dylan-console
@@ -0,0 +1,9 @@
+? 7 * 52;
+=> 364
+? define variable *your-variable* = $foo;
+? begin
+ let yours = "apple";
+ let mine = yours;
+ mine == yours;
+ end;
+=> #t