summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Sholik <alcosholik@gmail.com>2014-08-15 03:19:44 +0300
committerAlexei Sholik <alcosholik@gmail.com>2014-08-15 03:19:44 +0300
commit423b7668dce62f50b29cc38f2faf31619f021cee (patch)
tree63751e2cdd0655dd815050afa1846f9169a1ebd6
parent318f724a204eacd8b3fef8300e23468c71dc5ed7 (diff)
downloadpygments-423b7668dce62f50b29cc38f2faf31619f021cee.tar.gz
[Elixir] No longer balance sigil terminators
-rw-r--r--pygments/lexers/functional.py44
-rw-r--r--tests/examplefiles/example_elixir.ex2
2 files changed, 14 insertions, 32 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index dd823fe3..5a796433 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -3218,20 +3218,19 @@ class ElixirLexer(RegexLexer):
yield index, token, value
def gen_elixir_sigil_rules():
- # these braces are balanced inside the sigil string
- braces = [
+ # all valid sigil terminators (excluding heredocs)
+ terminators = [
(r'\{', r'\}', 'cb'),
(r'\[', r'\]', 'sb'),
(r'\(', r'\)', 'pa'),
(r'\<', r'\>', 'ab'),
+ (r'/', r'/', 'slas'),
+ (r'\|', r'\|', 'pipe'),
+ ('"', '"', 'quot'),
+ ("'", "'", 'apos'),
]
- # these are also valid sigil terminators, they are not balanced
- terms = [
- (r'/', 'slas'), (r'\|', 'pipe'), ('"', 'quot'), ("'", 'apos'),
- ]
-
- # heredocs have slightly different rules, they are not balanced
+ # heredocs have slightly different rules
triquotes = [(r'"""', 'triquot'), (r"'''", 'triapos')]
token = String.Other
@@ -3255,33 +3254,14 @@ class ElixirLexer(RegexLexer):
include('heredoc_no_interpol'),
]
- for term, name in terms:
+ for lterm, rterm, name in terminators:
states['sigils'] += [
- (r'~[a-z]' + term, token, name + '-intp'),
- (r'~[A-Z]' + term, token, name + '-no-intp'),
+ (r'~[a-z]' + lterm, token, name + '-intp'),
+ (r'~[A-Z]' + lterm, token, name + '-no-intp'),
]
-
- # Similar states to the braced sigils, but no balancing of
- # terminators
- states[name +'-intp'] = gen_elixir_sigstr_rules(term, token)
+ states[name +'-intp'] = gen_elixir_sigstr_rules(rterm, token)
states[name +'-no-intp'] = \
- gen_elixir_sigstr_rules(term, token, interpol=False)
-
- for lbrace, rbrace, name in braces:
- states['sigils'] += [
- (r'~[a-z]' + lbrace, token, name + '-intp'),
- (r'~[A-Z]' + lbrace, token, name + '-no-intp')
- ]
-
- states[name +'-intp'] = [
- (r'\\.', token),
- (lbrace, token, '#push'),
- ] + gen_elixir_sigstr_rules(rbrace, token)
-
- states[name +'-no-intp'] = [
- (r'\\.', token),
- (lbrace, token, '#push'),
- ] + gen_elixir_sigstr_rules(rbrace, token, interpol=False)
+ gen_elixir_sigstr_rules(rterm, token, interpol=False)
return states
diff --git a/tests/examplefiles/example_elixir.ex b/tests/examplefiles/example_elixir.ex
index 09870443..775b30cc 100644
--- a/tests/examplefiles/example_elixir.ex
+++ b/tests/examplefiles/example_elixir.ex
@@ -45,6 +45,8 @@ atom"
~w(hello #{ ["has" <> "123", '\c\d', "\123 interpol" | []] } world)s
~W(hello #{no "123" \c\d \123 interpol} world)s
+~s{Escapes terminators \{ and \}, but no {balancing} # outside of sigil here }
+
~S"No escapes \s\t\n and no #{interpolation}"
:"atoms work #{"to" <> "o"}"