Commits

megajoule committed b9d98b9

Update ElixirConsoleLexer and add example file

  • Participants
  • Parent commits b9e4312

Comments (0)

Files changed (2)

File pygments/lexers/functional.py

     aliases = ['iex']
     mimetypes = ['text/x-elixir-shellsession']
 
-    _prompt_re = re.compile('(iex|\.{3})> ')
+    _prompt_re = re.compile('(iex|\.{3})(\(\d+\))?> ')
 
     def get_tokens_unprocessed(self, text):
         exlexer = ElixirLexer(**self.options)
 
         curcode = ''
+        in_error = False
         insertions = []
         for match in line_re.finditer(text):
             line = match.group()
             if line.startswith(u'** '):
+                in_error = True
                 insertions.append((len(curcode),
                                    [(0, Generic.Error, line[:-1])]))
                 curcode += line[-1:]
             else:
                 m = self._prompt_re.match(line)
                 if m is not None:
+                    in_error = False
                     end = m.end()
                     insertions.append((len(curcode),
                                        [(0, Generic.Prompt, line[:end])]))
                 else:
                     if curcode:
                         for item in do_insertions(insertions,
-                                        exlexer.get_tokens_unprocessed(curcode)):
+                                    exlexer.get_tokens_unprocessed(curcode)):
                             yield item
                         curcode = ''
                         insertions = []
-                    yield match.start(), Generic.Output, line
+                    token = Generic.Error if in_error else Generic.Output
+                    yield match.start(), token, line
         if curcode:
             for item in do_insertions(insertions,
-                                      exlexer.get_tokens_unprocessed(curcode)):
+                                  exlexer.get_tokens_unprocessed(curcode)):
                 yield item
 
 

File tests/examplefiles/example_iex

+iex> :" multi
+...>  line ' \s \123 \x20
+...> atom"
+:" multi\n line '   S  \natom"
+
+iex(1)> <<"hello"::binary, c :: utf8, x::[4, unit(2)]>> = "hello™1"
+"hello™1"
+
+iex(2)> c
+8482
+
+iex> 1 + :atom
+** (ArithmeticError) bad argument in arithmetic expression
+    :erlang.+(1, :atom)
+
+iex(3)> 1 +
+...(3)> 2 +
+...(3)> 3
+6
+
+iex> IO.puts "Hello world"
+Hello world
+:ok