~ubuntu-branches/ubuntu/trusty/python-babel/trusty

« back to all changes in this revision

Viewing changes to babel/messages/jslexer.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-28 10:11:31 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131028101131-zwbmm8sc29iemmlr
Tags: 1.3-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/rules: Run the testsuite during builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
#
3
 
# Copyright (C) 2008 Edgewall Software
4
 
# All rights reserved.
5
 
#
6
 
# This software is licensed as described in the file COPYING, which
7
 
# you should have received as part of this distribution. The terms
8
 
# are also available at http://babel.edgewall.org/wiki/License.
9
 
#
10
 
# This software consists of voluntary contributions made by many
11
 
# individuals. For the exact contribution history, see the revision
12
 
# history and logs, available at http://babel.edgewall.org/log/.
13
 
 
14
 
"""A simple JavaScript 1.5 lexer which is used for the JavaScript
15
 
extractor.
16
 
"""
17
 
 
 
2
"""
 
3
    babel.messages.jslexer
 
4
    ~~~~~~~~~~~~~~~~~~~~~~
 
5
 
 
6
    A simple JavaScript 1.5 lexer which is used for the JavaScript
 
7
    extractor.
 
8
 
 
9
    :copyright: (c) 2013 by the Babel Team.
 
10
    :license: BSD, see LICENSE for more details.
 
11
"""
 
12
 
 
13
from operator import itemgetter
18
14
import re
19
 
 
20
 
from babel.util import itemgetter
21
 
 
 
15
from babel._compat import unichr
22
16
 
23
17
operators = [
24
18
    '+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=',
26
20
    '>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')',
27
21
    '[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':'
28
22
]
29
 
operators.sort(lambda a, b: cmp(-len(a), -len(b)))
 
23
operators.sort(key=lambda a: -len(a))
30
24
 
31
25
escapes = {'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t'}
32
26
 
80
74
def unquote_string(string):
81
75
    """Unquote a string with JavaScript rules.  The string has to start with
82
76
    string delimiters (``'`` or ``"``.)
83
 
 
84
 
    :return: a string
85
77
    """
86
78
    assert string and string[0] == string[-1] and string[0] in '"\'', \
87
79
        'string provided is not properly delimited'
136
128
 
137
129
 
138
130
def tokenize(source):
139
 
    """Tokenize a JavaScript source.
140
 
 
141
 
    :return: generator of `Token`\s
 
131
    """Tokenize a JavaScript source.  Returns a generator of tokens.
142
132
    """
143
133
    may_divide = False
144
134
    pos = 0