Changeset View
Changeset View
Standalone View
Standalone View
source/tools/i18n/extractors/jslexer.py
# -*- coding: utf-8 -*- | |||||
# | |||||
# Copyright (C) 2008-2011 Edgewall Software | # Copyright (C) 2008-2011 Edgewall Software | ||||
# Copyright (C) 2013-2014 Wildfire Games. | # Copyright (C) 2013-2014 Wildfire Games. | ||||
# All rights reserved. | # All rights reserved. | ||||
# | # | ||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||||
# following conditions are met: | # following conditions are met: | ||||
# | # | ||||
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following | # Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||||
Show All 15 Lines | |||||
# history and logs: | # history and logs: | ||||
# • http://babel.edgewall.org/log/trunk/babel/messages | # • http://babel.edgewall.org/log/trunk/babel/messages | ||||
# • http://trac.wildfiregames.com/browser/ps/trunk/source/tools/i18n/extractors/jslexer.py | # • http://trac.wildfiregames.com/browser/ps/trunk/source/tools/i18n/extractors/jslexer.py | ||||
"""A simple JavaScript 1.5 lexer which is used for the JavaScript | """A simple JavaScript 1.5 lexer which is used for the JavaScript | ||||
extractor. | extractor. | ||||
""" | """ | ||||
from __future__ import absolute_import, division, print_function, unicode_literals | |||||
from operator import itemgetter | from operator import itemgetter | ||||
import re | import re | ||||
operators = [ | operators = [ | ||||
'+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=', | '+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=', | ||||
'+=', '-=', '*=', '%=', '<<', '>>', '>>>', '<<=', '>>=', | '+=', '-=', '*=', '%=', '<<', '>>', '>>>', '<<=', '>>=', | ||||
'>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')', | '>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')', | ||||
'[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':' | '[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':' | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | while 1: | ||||
# character point. If there is no such character point, put | # character point. If there is no such character point, put | ||||
# all the consumed characters into the string. | # all the consumed characters into the string. | ||||
elif next_char in 'uU': | elif next_char in 'uU': | ||||
escaped = uni_escape_re.match(string, escape_pos + 2) | escaped = uni_escape_re.match(string, escape_pos + 2) | ||||
if escaped is not None: | if escaped is not None: | ||||
escaped_value = escaped.group() | escaped_value = escaped.group() | ||||
if len(escaped_value) == 4: | if len(escaped_value) == 4: | ||||
try: | try: | ||||
add(unichr(int(escaped_value, 16))) | add(chr(int(escaped_value, 16))) | ||||
except ValueError: | except ValueError: | ||||
pass | pass | ||||
else: | else: | ||||
pos = escape_pos + 6 | pos = escape_pos + 6 | ||||
continue | continue | ||||
add(next_char + escaped_value) | add(next_char + escaped_value) | ||||
pos = escaped.end() | pos = escaped.end() | ||||
continue | continue | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator