Commits

Bruce Mitchener committed 531a9c7

[dylan] Add DylanConsoleLexer.

Comments (0)

Files changed (3)

pygments/lexers/_mapping.py

     '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',)),

pygments/lexers/compiled.py

 from string import Template
 
 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
-     this, combined
+     this, combined, 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
            'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
            'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
            'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
-           'DylanLidLexer']
+           'DylanLidLexer', 'DylanConsoleLexer']
 
 
 class CLexer(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.
+    """
+    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
+
+
 class ObjectiveCLexer(RegexLexer):
     """
     For Objective-C source code with preprocessor directives.

tests/examplefiles/session.dylan-console

+? 7 * 52;
+=> 364
+? define variable *your-variable* = $foo;
+? begin
+   let yours = "apple";
+   let mine = yours;
+   mine == yours;
+ end;
+=> #t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.