summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <devnull@localhost>2014-08-15 12:11:02 +0300
committerAlex <devnull@localhost>2014-08-15 12:11:02 +0300
commiteeaff14517a7779c28d1e3eaacdc9ad501e862e8 (patch)
treec45ba652c67b24769d937c12d3f6d6699642e3d9
parent5bd7fce68011149a7850aa011889292bb5277dd2 (diff)
downloadpygments-eeaff14517a7779c28d1e3eaacdc9ad501e862e8.tar.gz
[Elixir] Update character escape rules
-rw-r--r--pygments/lexers/functional.py19
-rw-r--r--tests/examplefiles/example_elixir.ex8
2 files changed, 15 insertions, 12 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index 83c5d04e..9c010b1e 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -3276,20 +3276,22 @@ class ElixirLexer(RegexLexer):
complex_name_re = r'(?:%s|%s|%s)' % (name_re, modname_re, ops_re)
special_atom_re = r'(?:\.\.\.|<<>>|%{}|%|{})'
+ long_hex_char_re = r'(\\x{)([\da-fA-F]+)(})'
+ hex_char_re = r'(\\x[\da-fA-F]{1,2})'
+ escape_char_re = r'(\\[abdefnrstv])'
+
tokens = {
'root': [
(r'\s+', Text),
(r'#.*$', Comment.Single),
# Various kinds of characters
- (r'(?i)(\?)(\\x{)([\da-f]+)(})',
+ (r'(\?)' + long_hex_char_re,
bygroups(String.Char,
String.Escape, Number.Hex, String.Escape)),
- (r'(?i)(\?)(\\x[\da-f]{1,2})',
- bygroups(String.Char, String.Escape)),
- (r'(\?)(\\[0-7]{1,3})',
+ (r'(\?)' + hex_char_re,
bygroups(String.Char, String.Escape)),
- (r'(\?)(\\[abdefnrstv])',
+ (r'(\?)' + escape_char_re,
bygroups(String.Char, String.Escape)),
(r'\?\\?.', String.Char),
@@ -3353,11 +3355,10 @@ class ElixirLexer(RegexLexer):
(r'\n+', String.Heredoc),
],
'escapes': [
- (r'(?i)(\\x{)([\da-f]+)(})',
+ (long_hex_char_re,
bygroups(String.Escape, Number.Hex, String.Escape)),
- (r'(?i)\\x[\da-f]{1,2}', String.Escape),
- (r'\\[0-7]{1,3}', String.Escape),
- (r'\\[abdefnrstv]', String.Escape),
+ (hex_char_re, String.Escape),
+ (escape_char_re, String.Escape),
],
'interpol': [
(r'#{', String.Interpol, 'interpol_string'),
diff --git a/tests/examplefiles/example_elixir.ex b/tests/examplefiles/example_elixir.ex
index b2b4dc28..6a525ace 100644
--- a/tests/examplefiles/example_elixir.ex
+++ b/tests/examplefiles/example_elixir.ex
@@ -11,7 +11,9 @@
# Characters
?a ; ?1 ; ?\n ; ?\s ; ?\c ; ? ; ?,
?\x{12} ; ?\x{abcd}
-?\x34 ; ?\xf
+?\x34 ; ?\xF
+
+# these show that only the first digit is part of the character
?\123 ; ?\12 ; ?\7
# Atoms
@@ -26,8 +28,8 @@ atom"
# Strings
"Hello world"
-"Interspersed \x{ff} codes \7 \8 \65 \016 and \t\s\z\+ \\ escapes"
-"Quotes ' inside \" \123 the \"\" \xF string \\\" end"
+"Interspersed \x{ff} codes \7 \8 \65 \016 and \t\s\\s\z\+ \\ escapes"
+"Quotes ' inside \" \123 the \"\" \xF \\xF string \\\" end"
"Multiline
string"