summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-03 16:30:59 +0100
committerGeorg Brandl <georg@python.org>2011-01-03 16:30:59 +0100
commit2857c39e8b28860f1a142d18e4ffcf52f7187f22 (patch)
treef0018c35c00fd98ac77b32e35824038609498fb7
parenteaf5ad75624ccc66cd499c57fc8e17cb98a44e10 (diff)
downloadpygments-2857c39e8b28860f1a142d18e4ffcf52f7187f22.tar.gz
Fix lexing of Dylan string and char literals (#628).
-rw-r--r--CHANGES2
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/compiled.py13
-rw-r--r--tests/examplefiles/classes.dylan4
4 files changed, 17 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 44c9c597..af40a0eb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -64,6 +64,8 @@ Version 1.4
- Support line continuations in the INI lexer (#494).
+- Fix lexing of Dylan string and char literals (#628).
+
Version 1.3.1
-------------
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 9e922f13..01393f9b 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -71,7 +71,7 @@ LEXERS = {
'DiffLexer': ('pygments.lexers.text', 'Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')),
'DjangoLexer': ('pygments.lexers.templates', 'Django/Jinja', ('django', 'jinja'), (), ('application/x-django-templating', 'application/x-jinja')),
'DuelLexer': ('pygments.lexers.web', 'Duel', ('duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST'), ('*.duel', '*.jbst'), ('text/x-duel', 'text/x-jbst')),
- 'DylanLexer': ('pygments.lexers.compiled', 'Dylan', ('dylan',), ('*.dylan',), ('text/x-dylan',)),
+ 'DylanLexer': ('pygments.lexers.compiled', 'Dylan', ('dylan',), ('*.dylan', '*.dyl'), ('text/x-dylan',)),
'ErbLexer': ('pygments.lexers.templates', 'ERB', ('erb',), (), ('application/x-ruby-templating',)),
'ErlangLexer': ('pygments.lexers.functional', 'Erlang', ('erlang',), ('*.erl', '*.hrl'), ('text/x-erlang',)),
'ErlangShellLexer': ('pygments.lexers.functional', 'Erlang erl session', ('erl',), ('*.erl-sh',), ('text/x-erl-shellsession',)),
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 397ae1eb..5c10a785 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -1051,7 +1051,7 @@ class DylanLexer(RegexLexer):
name = 'Dylan'
aliases = ['dylan']
- filenames = ['*.dylan']
+ filenames = ['*.dylan', '*.dyl']
mimetypes = ['text/x-dylan']
flags = re.DOTALL
@@ -1064,10 +1064,10 @@ class DylanLexer(RegexLexer):
r'|open|primary|sealed|si(deways|ngleton)|slot'
r'|v(ariable|irtual))\b', Name.Builtin),
(r'<\w+>', Keyword.Type),
- (r'#?"(?:\\.|[^"])+?"', String.Double),
(r'//.*?\n', Comment.Single),
(r'/\*[\w\W]*?\*/', Comment.Multiline),
- (r'\'.*?\'', String.Single),
+ (r'"', String, 'string'),
+ (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
(r'=>|\b(a(bove|fterwards)|b(e(gin|low)|y)|c(ase|leanup|reate)'
r'|define|else(|if)|end|f(inally|or|rom)|i[fn]|l(et|ocal)|otherwise'
r'|rename|s(elect|ignal)|t(hen|o)|u(n(less|til)|se)|wh(en|ile))\b',
@@ -1084,6 +1084,13 @@ class DylanLexer(RegexLexer):
(r'#[a-zA-Z0-9-]+', Keyword),
(r'[a-zA-Z0-9-]+', Name.Variable),
],
+ 'string': [
+ (r'"', String, '#pop'),
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
+ (r'[^\\"\n]+', String), # all other characters
+ (r'\\\n', String), # line continuation
+ (r'\\', String), # stray backslash
+ ],
}
diff --git a/tests/examplefiles/classes.dylan b/tests/examplefiles/classes.dylan
index a77956d4..ff435b77 100644
--- a/tests/examplefiles/classes.dylan
+++ b/tests/examplefiles/classes.dylan
@@ -7,6 +7,10 @@ define class <car> (<object>)
init-value: #f;
end class <car>;
+define constant $empty-string = "";
+define constant $escaped-backslash = '\\';
+define constant $escaped-single-quote = '\'';
+
define variable *unique-serial-number* = 0;
define function unique-serial-number() => (usn :: <integer>)