summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Sholik <alcosholik@gmail.com>2014-08-15 13:26:02 +0300
committerAlexei Sholik <alcosholik@gmail.com>2014-08-15 13:26:02 +0300
commit04e47f0f5ebd530eb9bc4380848d31279f01fb0b (patch)
tree78d5713932fe13c98bab6f72a8f6eeaf7a80882b
parent37368d865858e12278cc31f8bb6b46d27d63fb2c (diff)
downloadpygments-04e47f0f5ebd530eb9bc4380848d31279f01fb0b.tar.gz
[Elixir] Parse maps and tuples to make non-trivial and nested string interpolation work
-rw-r--r--pygments/lexers/functional.py24
-rw-r--r--tests/examplefiles/example_elixir.ex3
2 files changed, 23 insertions, 4 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index b307a7d7..ed63be44 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -3187,12 +3187,12 @@ class ElixirLexer(RegexLexer):
OPERATORS3 = ['<<<', '>>>', '|||', '&&&', '^^^', '~~~', '===', '!==']
OPERATORS2 = [
'==', '!=', '<=', '>=', '&&', '||', '<>', '++', '--', '|>', '=~',
- '->', '<-', '|', '.', '%', '='
+ '->', '<-', '|', '.', '='
]
OPERATORS1 = ['<', '>', '+', '-', '*', '/', '!', '^', '&']
PUNCTUATION = [
- '\\\\', '<<', '>>', '=>', '(', ')', '{', '}', ':', ';', ',', '[', ']'
+ '\\\\', '<<', '>>', '=>', '(', ')', ':', ';', ',', '[', ']'
]
def get_tokens_unprocessed(self, text):
@@ -3321,7 +3321,7 @@ class ElixirLexer(RegexLexer):
# identifiers
(name_re, Name),
- (modname_re, Name.Class),
+ (r'(%%?)(%s)' % (modname_re,), bygroups(Punctuation, Name.Class)),
# numbers
(r'0b[01]+', Number.Bin),
@@ -3337,6 +3337,9 @@ class ElixirLexer(RegexLexer):
(r"'", String.Single, 'string_single'),
include('sigils'),
+
+ (r'%{', Punctuation, 'map_key'),
+ (r'{', Punctuation, 'tuple'),
],
'heredoc_double': [
(r'^\s*"""', String.Heredoc, '#pop'),
@@ -3371,6 +3374,21 @@ class ElixirLexer(RegexLexer):
(r'}', String.Interpol, "#pop"),
include('root')
],
+ 'map_key': [
+ include('root'),
+ (r':', Punctuation, 'map_val'),
+ (r'=>', Punctuation, 'map_val'),
+ (r'}', Punctuation, '#pop'),
+ ],
+ 'map_val': [
+ include('root'),
+ (r',', Punctuation, '#pop'),
+ (r'(?=})', Punctuation, '#pop'),
+ ],
+ 'tuple': [
+ include('root'),
+ (r'}', Punctuation, '#pop'),
+ ],
}
tokens.update(gen_elixir_string_rules('double', '"', String.Double))
tokens.update(gen_elixir_string_rules('single', "'", String.Single))
diff --git a/tests/examplefiles/example_elixir.ex b/tests/examplefiles/example_elixir.ex
index 3c3d72f3..27462268 100644
--- a/tests/examplefiles/example_elixir.ex
+++ b/tests/examplefiles/example_elixir.ex
@@ -129,7 +129,8 @@ end
# Structs
defmodule Second.Module do
s = %Long.Module.Name{name: "Silly"}
- %{s | height: {192, :cm}}
+ %Long.Module.Name{s | height: {192, :cm}}
+ ".. #{%Long.Module.Name{s | height: {192, :cm}}} .."
end
# Types, pseudo-vars, attributes