Update RapydScript

This commit is contained in:
Kovid Goyal 2016-03-14 11:10:13 +05:30
parent f27e2bb85e
commit 29e3817acd
6 changed files with 50 additions and 50 deletions

Binary file not shown.

View File

@ -50,7 +50,7 @@ def _makeelement(tag, *args, **kwargs):
ans.setAttribute(vattr, val)
for arg in args:
if type(arg) == 'string':
if type(arg) is 'string':
arg = this.createTextNode(arg)
ans.appendChild(arg)
return ans
@ -62,7 +62,7 @@ def maker_for_document(document):
Object.defineProperty(E, tag, {'value':_makeelement.bind(document, tag)})
return E
if type(document) == 'undefined':
if type(document) is 'undefined':
E = maker_for_document({
'createTextNode': def(value): return value;,
'createElement': def(name):

View File

@ -505,7 +505,7 @@ def _get_plural_forms_function(plural_forms_string):
_gettext = def(text): return text
_ngettext = def(text, plural, n): return text if n == 1 else plural
_ngettext = def(text, plural, n): return text if n is 1 else plural
def gettext(text):
return _gettext(text)
@ -542,8 +542,8 @@ class Translations:
m = t['entries']
if Object.prototype.hasOwnProperty.call(m, text):
idx = t['func'](n)
return m[text][idx] or (text if n == 1 else plural)
return text if n == 1 else plural
return m[text][idx] or (text if n is 1 else plural)
return text if n is 1 else plural
def install(self):
nonlocal _gettext, _ngettext

View File

@ -32,11 +32,11 @@ def copysign(x, y):
def fabs(x):
return Math.abs(x)
def factorial(x):
if Math.abs(int(x)) != x:
if Math.abs(int(x)) is not x:
raise ValueError("factorial() only accepts integral values")
factorial.cache = []
r = def(n):
if n == 0 or n == 1:
if n is 0 or n is 1:
return 1
if not factorial.cache[n]:
factorial.cache[n] = r(n-1) * n
@ -103,7 +103,7 @@ def log1p(x):
if x < 0 or x > 1:
return Math.log(1 + x)
for i in range(1, n):
if i % 2 == 0:
if i % 2 is 0:
ret -= Math.pow(x, i) / i
else:
ret += Math.pow(x, i) / i
@ -114,9 +114,9 @@ def log10(x):
# I didn't find a more accurate algorithm so I'm using the basic implementation
return Math.log(x)/Math.LN10
def pow(x, y):
if x < 0 and int(y) != y:
if x < 0 and int(y) is not y:
raise ValueError('math domain error')
if isnan(y) and x == 1:
if isnan(y) and x is 1:
return 1
return Math.pow(x, y)
def sqrt(x):

View File

@ -5,7 +5,7 @@ div = __div__ = def(x, y): return x / y
lt = __lt__ = def(x, y): return x < y
le = __le__ = def(x, y): return x <= y
eq = __eq__ = def(x, y): return x == y
ne = __ne__ = def(x, y): return x != y
eq = __eq__ = def(x, y): return x is y
ne = __ne__ = def(x, y): return x is not y
ge = __ge__ = def(x, y): return x >= y
gt = __gt__ = def(x, y): return x > y

View File

@ -48,7 +48,7 @@ def _expand(groups, repl, group_name_map):
def read_digits(count, pat, base, maxval, prefix):
ans = prefix or ''
greedy = count == Number.MAX_VALUE
greedy = count is Number.MAX_VALUE
while count > 0:
count -= 1
if not pat.test(peek()):
@ -64,18 +64,18 @@ def _expand(groups, repl, group_name_map):
def read_escape_sequence():
nonlocal i
q = next()
if not q or q == '\\':
if not q or q is '\\':
return '\\'
if '"\''.indexOf(q) != -1:
if '"\''.indexOf(q) is not -1:
return q
if _ASCII_CONTROL_CHARS.hasOwnProperty(q):
return String.fromCharCode(_ASCII_CONTROL_CHARS[q])
if '0' <= q <= '9':
ans = read_digits(Number.MAX_VALUE, _NUM_PAT, 10, Number.MAX_VALUE, q)
if type(ans) == 'number':
if type(ans) is 'number':
return groups[ans] or ''
return '\\' + ans
if q == 'g':
if q is 'g':
m = _GROUP_PAT.exec(repl[i:])
if m is not None:
i += m[0].length
@ -85,30 +85,30 @@ def _expand(groups, repl, group_name_map):
return ''
gn = group_name_map[gn][-1]
return groups[gn] or ''
if q == 'x':
if q is 'x':
code = read_digits(2, _HEX_PAT, 16, 0x10FFFF)
if type(code) == 'number':
if type(code) is 'number':
return String.fromCharCode(code)
return '\\x' + code
if q == 'u':
if q is 'u':
code = read_digits(4, _HEX_PAT, 16, 0x10FFFF)
if type(code) == 'number':
if type(code) is 'number':
return String.fromCharCode(code)
return '\\u' + code
if q == 'U':
if q is 'U':
code = read_digits(8, _HEX_PAT, 16, 0x10FFFF)
if type(code) == 'number':
if type(code) is 'number':
if code <= 0xFFFF:
return String.fromCharCode(code)
code -= 0x10000
return String.fromCharCode(0xD800+(code>>10), 0xDC00+(code&0x3FF))
return '\\U' + code
if q == 'N' and peek() == '{':
if q is 'N' and peek() is '{':
next()
name = ''
while _NAME_PAT.test(peek()):
name += next()
if peek() != '}':
if peek() is not '}':
return '\\N{' + name
next()
key = (name or '').toLowerCase()
@ -124,7 +124,7 @@ def _expand(groups, repl, group_name_map):
ans = ch = ''
while (ch = next()):
if ch == '\\':
if ch is '\\':
ans += read_escape_sequence()
else:
ans += ch
@ -146,33 +146,33 @@ def transform_regex(source, flags):
continue
if in_class:
if ch == ']':
if ch is ']':
in_class = False
ans += ch
continue
if ch == '\\':
if ch is '\\':
previous_backslash = True
continue
if ch == '[':
if ch is '[':
in_class = True
if source[pos] == ']': # in python the empty set is not allowed, instead []] is the same as [\]]
if source[pos] is ']': # in python the empty set is not allowed, instead []] is the same as [\]]
pos += 1
ch = r'[\]'
elif ch == '(':
if source[pos] == '?':
elif ch is '(':
if source[pos] is '?':
extension = source[pos + 1]
if extension == '#':
if extension is '#':
close = source.indexOf(')', pos + 1)
if close == -1:
if close is -1:
raise ValueError('Expecting a closing )')
pos = close + 1
continue
if 'aiLmsux'.indexOf(extension) != -1:
if 'aiLmsux'.indexOf(extension) is not -1:
flag_map = {'a':ASCII, 'i':IGNORECASE, 'L':LOCALE, 'm':MULTILINE, 's':DOTALL, 'u':UNICODE, 'x':VERBOSE}
close = source.indexOf(')', pos + 1)
if close == -1:
if close is -1:
raise SyntaxError('Expecting a closing )')
flgs = source[pos+1:close]
for v'var i = 0; i < flgs.length; i++':
@ -182,25 +182,25 @@ def transform_regex(source, flags):
flags |= flag_map[q]
pos = close + 1
continue
if extension == '<':
if extension is '<':
raise SyntaxError('Look behind assertions are not supported in JavaScript')
if extension == '(':
if extension is '(':
raise SyntaxError('Group existence assertions are not supported in JavaScript')
if extension == 'P':
if extension is 'P':
pos += 2
q = source[pos]
if q == '<':
if q is '<':
close = source.indexOf('>', pos)
if close == -1:
if close is -1:
raise SyntaxError('Named group not closed, expecting >')
name = source[pos+1:close]
if not Object.prototype.hasOwnProperty.call(group_map, name):
group_map[name] = v'[]'
group_map[name].push(v'++group_count')
pos = close + 1
elif q == '=':
elif q is '=':
close = source.indexOf(')', pos)
if close == -1:
if close is -1:
raise SyntaxError('Named group back-reference not closed, expecting a )')
name = source[pos+1:close]
if not isNaN(parseInt(name, 10)):
@ -215,7 +215,7 @@ def transform_regex(source, flags):
raise SyntaxError('Expecting < or = after (?P')
else:
group_count += 1
elif ch == '.' and (flags & DOTALL):
elif ch is '.' and (flags & DOTALL):
ans += r'[\s\S]' # JavaScript has no DOTALL
continue
@ -245,7 +245,7 @@ class MatchObject:
for v'var i = 1; i < match.length; i++':
g = match[i]
loc = extent.indexOf(g, loc)
if loc == -1:
if loc is -1:
self._start[i] = self._start[i-1]
self._end[i] = self._end[i-1]
else:
@ -263,7 +263,7 @@ class MatchObject:
return ans
def _group_number(self, g):
if type(g) == 'number':
if type(g) is 'number':
return g
if Object.prototype.hasOwnProperty.call(self.re.group_name_map, g):
return self.re.group_name_map[g][-1]
@ -271,7 +271,7 @@ class MatchObject:
def _group_val(self, q, defval):
val = undefined
if type(q) == 'number' and -1 < q < self._groups.length:
if type(q) is 'number' and -1 < q < self._groups.length:
val = self._groups[q]
else:
if Object.prototype.hasOwnProperty.call(self.re.group_name_map, q):
@ -281,13 +281,13 @@ class MatchObject:
return val
def group(self):
if arguments.length == 0:
if arguments.length is 0:
return self._groups[0]
ans = v'[]'
for v'var i = 0; i < arguments.length; i++':
q = arguments[i] # noqa:undef
ans.push(self._group_val(q, None))
return ans[0] if ans.length == 1 else ans
return ans[0] if ans.length is 1 else ans
def start(self, g):
if self._start is undefined:
@ -399,7 +399,7 @@ class RegexObject:
def subn(self, repl, string, count=0):
expand = _expand
if type(repl) == 'function':
if type(repl) is 'function':
expand = def(m, repl, gnm): return '' + repl(MatchObject(self, m, 0, None))
this._pattern.lastIndex = 0
num = 0