diff --git a/AUTHORS b/AUTHORS index 6faa171e31..8b0f51a75f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -222,6 +222,7 @@ answer newbie questions, and generally made Django that much better: Janos Guljas Thomas Güttler Horst Gutmann + Antti Haapala Scot Hacker dAniel hAhler hambaloney diff --git a/django/utils/jslex.py b/django/utils/jslex.py index 88a22ec67d..c465647001 100644 --- a/django/utils/jslex.py +++ b/django/utils/jslex.py @@ -51,19 +51,25 @@ class Lexer(object): Yields pairs (`name`, `tokentext`). """ - while text: - eaten = 0 - for match in self.regexes[self.state].finditer(text): - for name, toktext in match.groupdict().iteritems(): - if toktext is not None: - tok = self.toks[name] - new_state = tok.next - eaten += len(toktext) - yield (tok.name, toktext) - if new_state: - self.state = new_state + end = len(text) + state = self.state + regexes = self.regexes + toks = self.toks + start = 0 + + while start < end: + for match in regexes[state].finditer(text, start): + name = match.lastgroup + tok = toks[name] + toktext = match.group(name) + start += len(toktext) + yield (tok.name, toktext) + + if tok.next: + state = tok.next break - text = text[eaten:] + + self.state = state class JsLexer(Lexer):