# HG changeset patch # User aronacher # Date 1213481261 0 # Node ID 6dae6a9e1096695ae40c8ba2705d3692fbfcc712 # Parent 603192024857c9f6da88e572ffdd8a0b40803ba9 JavaScript lexer falls back silently now on syntax errors and tries to recover. diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py --- a/babel/messages/jslexer.py +++ b/babel/messages/jslexer.py @@ -23,7 +23,7 @@ '+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=', '+=', '-=', '*=', '%=', '<<', '>>', '>>>', '<<=', '>>=', '>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')', - '[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.' + '[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':' ] operators.sort(lambda a, b: cmp(-len(a), -len(b))) @@ -55,10 +55,6 @@ uni_escape_re = re.compile(r'[a-fA-F0-9]{1,4}') -class TokenError(ValueError): - """Raised if the tokenizer stumbled upon invalid tokens.""" - - class Token(tuple): """Represents a token as returned by `tokenize`.""" __slots__ = () @@ -166,7 +162,9 @@ match = regex_re.match(source, pos) token_type = 'regexp' if match is None: - raise TokenError('invalid syntax around line %d' % lineno) + # woops. invalid syntax. jump one char ahead and try again. + pos += 1 + continue token_value = match.group() if token_type is not None: