diff options
author | Alexei Sholik <alcosholik@gmail.com> | 2014-06-05 19:30:06 +0300 |
---|---|---|
committer | Alexei Sholik <alcosholik@gmail.com> | 2014-06-05 19:30:06 +0300 |
commit | 1eab0e634018f922599e76a636719995fefd48cf (patch) | |
tree | 6038212dc7152023af434b704e02e8fa55d7c839 | |
parent | e471b92d4f147f31849b6deb7d925dd7b37890b5 (diff) | |
download | pygments-1eab0e634018f922599e76a636719995fefd48cf.tar.gz |
Update ElixirConsoleLexer and add example file
-rw-r--r-- | pygments/lexers/functional.py | 12 | ||||
-rw-r--r-- | tests/examplefiles/example_iex | 23 |
2 files changed, 31 insertions, 4 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py index 889e82a2..000be337 100644 --- a/pygments/lexers/functional.py +++ b/pygments/lexers/functional.py @@ -3407,22 +3407,25 @@ class ElixirConsoleLexer(Lexer): 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])])) @@ -3430,14 +3433,15 @@ class ElixirConsoleLexer(Lexer): 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 diff --git a/tests/examplefiles/example_iex b/tests/examplefiles/example_iex new file mode 100644 index 00000000..22407e4e --- /dev/null +++ b/tests/examplefiles/example_iex @@ -0,0 +1,23 @@ +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 |