rapydscript-ng 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/build.ts +29 -0
  3. package/package.json +1 -1
  4. package/release/baselib-plain-pretty.js +85 -61
  5. package/release/baselib-plain-ugly.js +3 -3
  6. package/release/compiler.js +2543 -2432
  7. package/release/signatures.json +26 -26
  8. package/src/ast.pyj +170 -58
  9. package/src/baselib-builtins.pyj +35 -14
  10. package/src/baselib-containers.pyj +70 -40
  11. package/src/baselib-internal.pyj +20 -8
  12. package/src/baselib-itertools.pyj +6 -2
  13. package/src/baselib-str.pyj +74 -28
  14. package/src/errors.pyj +4 -1
  15. package/src/lib/aes.pyj +664 -35
  16. package/src/lib/elementmaker.pyj +105 -13
  17. package/src/lib/encodings.pyj +31 -7
  18. package/src/lib/gettext.pyj +6 -3
  19. package/src/lib/math.pyj +38 -22
  20. package/src/lib/pythonize.pyj +5 -3
  21. package/src/lib/random.pyj +13 -5
  22. package/src/lib/re.pyj +81 -18
  23. package/src/lib/traceback.pyj +42 -10
  24. package/src/lib/uuid.pyj +2 -1
  25. package/src/output/classes.pyj +70 -26
  26. package/src/output/codegen.pyj +92 -20
  27. package/src/output/comments.pyj +11 -4
  28. package/src/output/exceptions.pyj +17 -4
  29. package/src/output/functions.pyj +34 -13
  30. package/src/output/literals.pyj +7 -2
  31. package/src/output/loops.pyj +50 -16
  32. package/src/output/modules.pyj +41 -12
  33. package/src/output/operators.pyj +154 -31
  34. package/src/output/statements.pyj +38 -10
  35. package/src/output/stream.pyj +43 -12
  36. package/src/output/utils.pyj +10 -3
  37. package/src/parse.pyj +740 -259
  38. package/src/string_interpolation.pyj +4 -1
  39. package/src/tokenizer.pyj +300 -55
  40. package/src/unicode_aliases.pyj +4 -2
  41. package/src/utils.pyj +19 -5
  42. package/test/functions.pyj +8 -0
  43. package/test/generic.pyj +9 -0
  44. package/test/lsp.pyj +16 -0
  45. package/tools/compiler.mjs +0 -6
  46. package/tools/fmt.mjs +41 -2
  47. package/tools/lint-worker.mjs +7 -1
  48. package/tools/lint.mjs +12 -5
  49. package/tools/lsp.mjs +11 -1
@@ -2,19 +2,111 @@
2
2
  # License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
3
 
4
4
  html_elements = {
5
- 'a', 'abbr', 'acronym', 'address', 'area',
6
- 'article', 'aside', 'audio', 'b', 'base', 'big', 'body', 'blockquote', 'br', 'button',
7
- 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
8
- 'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
9
- 'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
10
- 'figcaption', 'figure', 'footer', 'font', 'form', 'header', 'h1',
11
- 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'head', 'i', 'iframe', 'img', 'input', 'ins',
12
- 'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',
13
- 'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
14
- 'p', 'pre', 'progress', 'q', 's', 'samp', 'script', 'section', 'select',
15
- 'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong', 'style',
16
- 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
17
- 'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video'
5
+ 'a',
6
+ 'abbr',
7
+ 'acronym',
8
+ 'address',
9
+ 'area',
10
+ 'article',
11
+ 'aside',
12
+ 'audio',
13
+ 'b',
14
+ 'base',
15
+ 'big',
16
+ 'body',
17
+ 'blockquote',
18
+ 'br',
19
+ 'button',
20
+ 'canvas',
21
+ 'caption',
22
+ 'center',
23
+ 'cite',
24
+ 'code',
25
+ 'col',
26
+ 'colgroup',
27
+ 'command',
28
+ 'datagrid',
29
+ 'datalist',
30
+ 'dd',
31
+ 'del',
32
+ 'details',
33
+ 'dfn',
34
+ 'dialog',
35
+ 'dir',
36
+ 'div',
37
+ 'dl',
38
+ 'dt',
39
+ 'em',
40
+ 'event-source',
41
+ 'fieldset',
42
+ 'figcaption',
43
+ 'figure',
44
+ 'footer',
45
+ 'font',
46
+ 'form',
47
+ 'header',
48
+ 'h1',
49
+ 'h2',
50
+ 'h3',
51
+ 'h4',
52
+ 'h5',
53
+ 'h6',
54
+ 'hr',
55
+ 'head',
56
+ 'i',
57
+ 'iframe',
58
+ 'img',
59
+ 'input',
60
+ 'ins',
61
+ 'keygen',
62
+ 'kbd',
63
+ 'label',
64
+ 'legend',
65
+ 'li',
66
+ 'm',
67
+ 'map',
68
+ 'menu',
69
+ 'meter',
70
+ 'multicol',
71
+ 'nav',
72
+ 'nextid',
73
+ 'ol',
74
+ 'output',
75
+ 'optgroup',
76
+ 'option',
77
+ 'p',
78
+ 'pre',
79
+ 'progress',
80
+ 'q',
81
+ 's',
82
+ 'samp',
83
+ 'script',
84
+ 'section',
85
+ 'select',
86
+ 'small',
87
+ 'sound',
88
+ 'source',
89
+ 'spacer',
90
+ 'span',
91
+ 'strike',
92
+ 'strong',
93
+ 'style',
94
+ 'sub',
95
+ 'sup',
96
+ 'table',
97
+ 'tbody',
98
+ 'td',
99
+ 'textarea',
100
+ 'time',
101
+ 'tfoot',
102
+ 'th',
103
+ 'thead',
104
+ 'tr',
105
+ 'tt',
106
+ 'u',
107
+ 'ul',
108
+ 'var',
109
+ 'video',
18
110
  }
19
111
 
20
112
  mathml_elements = {
@@ -7,18 +7,36 @@ def base64encode(bytes, altchars, pad_char):
7
7
  l = bytes.length
8
8
  remainder = l % 3
9
9
  main_length = l - remainder
10
- encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + (altchars or '+/')
10
+ encodings = (
11
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' +
12
+ (altchars or '+/')
13
+ )
11
14
  pad_char = '=' if pad_char is undefined else pad_char
12
15
  ans = v'[]'
13
16
  for v'var i = 0; i < main_length; i += 3':
14
17
  chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
15
- ans.push(encodings[(chunk & 16515072) >> 18], encodings[(chunk & 258048) >> 12], encodings[(chunk & 4032) >> 6], encodings[chunk & 63])
18
+ ans.push(
19
+ encodings[(chunk & 16515072) >> 18],
20
+ encodings[(chunk & 258048) >> 12],
21
+ encodings[(chunk & 4032) >> 6],
22
+ encodings[chunk & 63]
23
+ )
16
24
  if remainder is 1:
17
25
  chunk = bytes[main_length]
18
- ans.push(encodings[(chunk & 252) >> 2], encodings[(chunk & 3) << 4], pad_char, pad_char)
26
+ ans.push(
27
+ encodings[(chunk & 252) >> 2],
28
+ encodings[(chunk & 3) << 4],
29
+ pad_char,
30
+ pad_char
31
+ )
19
32
  elif remainder is 2:
20
33
  chunk = (bytes[main_length] << 8) | bytes[main_length + 1]
21
- ans.push(encodings[(chunk & 64512) >> 10], encodings[(chunk & 1008) >> 4], encodings[(chunk & 15) << 2], pad_char)
34
+ ans.push(
35
+ encodings[(chunk & 64512) >> 10],
36
+ encodings[(chunk & 1008) >> 4],
37
+ encodings[(chunk & 15) << 2],
38
+ pad_char
39
+ )
22
40
  return ans.join('')
23
41
 
24
42
 
@@ -40,7 +58,10 @@ def urlsafe_b64encode(bytes, pad_char):
40
58
 
41
59
 
42
60
  def urlsafe_b64decode(string):
43
- string = String.prototype.replace.call(string, /[_-]/g, def (m): return '+' if m is '-' else '/';)
61
+ string = String.prototype.replace.call(
62
+ string, /[_-]/g, def (m):
63
+ return '+' if m is '-' else '/'
64
+ )
44
65
  return base64decode(string)
45
66
 
46
67
 
@@ -99,13 +120,16 @@ def utf8_decode(bytes, errors, replacement):
99
120
  for v'var i = 0, l = bytes.length; i < l; i++': # noqa
100
121
  byte = bytes[i]
101
122
  typ = utf8_decoder_table[byte]
102
- codep = (byte & 0x3f) | (codep << 6) if state is not 0 else (0xff >> typ) & (byte)
123
+ codep = (((byte & 0x3f) | (codep << 6)) if state is not 0 else ((0xff >> typ) & (byte)))
103
124
  state = utf8_decoder_table[256 + state * 16 + typ]
104
125
  if state is 0:
105
126
  ans.push(_from_code_point(codep))
106
127
  elif state is 1:
107
128
  if not errors or errors is 'strict':
108
- raise UnicodeDecodeError(str.format('The byte 0x{:02x} at position {} is not valid UTF-8', byte, i))
129
+ raise UnicodeDecodeError(str.format(
130
+ 'The byte 0x{:02x} at position {} is not valid UTF-8',
131
+ byte, i
132
+ ))
109
133
  elif errors is 'replace':
110
134
  ans.push(replacement or '?')
111
135
  return ans.join('')
@@ -4,7 +4,8 @@
4
4
  # noqa: eol-semicolon
5
5
 
6
6
  # The Plural-Forms parser {{{
7
- # From: https://github.com/SlexAxton/Jed/blob/master/jed.js licensed under the WTFPL
7
+ # From: https://github.com/SlexAxton/Jed/blob/master/jed.js
8
+ # licensed under the WTFPL
8
9
 
9
10
  Jed = {}
10
11
 
@@ -502,7 +503,8 @@ plural_forms_parser = Jed.PF
502
503
 
503
504
 
504
505
  def _get_plural_forms_function(plural_forms_string):
505
- return plural_forms_parser.compile(plural_forms_string or 'nplurals=2; plural=(n != 1);')
506
+ return plural_forms_parser.compile(
507
+ plural_forms_string or 'nplurals=2; plural=(n != 1);')
506
508
 
507
509
  _gettext = def (text): return text
508
510
 
@@ -527,7 +529,8 @@ def install(translation_data):
527
529
  pass
528
530
  return t
529
531
 
530
- has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)
532
+ has_prop = Object.prototype.hasOwnProperty.call.bind(
533
+ Object.prototype.hasOwnProperty)
531
534
 
532
535
 
533
536
  def register_callback(func):
package/src/lib/math.pyj CHANGED
@@ -10,14 +10,15 @@
10
10
 
11
11
  # basic implementation of Python's 'math' library
12
12
 
13
- # NOTE: this is only meant to aid those porting lots of Python code into RapydScript,
14
- # if you're writing a new RapydScript application, in most cases you probably want to
15
- # use JavaScript's Math module directly instead
13
+ # NOTE: this is only meant to aid those porting lots of Python code
14
+ # into RapydScript, if you're writing a new RapydScript application,
15
+ # in most cases you probably want to use JavaScript's Math module
16
+ # directly instead
16
17
 
17
18
 
18
19
  pi = Math.PI
19
20
  e = Math.E
20
- inf = Infinity
21
+ inf = Math.Infinity
21
22
 
22
23
 
23
24
  ########################################
@@ -57,14 +58,16 @@ def floor(x):
57
58
 
58
59
 
59
60
  def fmod(x, y):
60
- # javascript's % operator isn't consistent with C fmod implementation, this function is
61
+ # javascript's % operator isn't consistent with C fmod
62
+ # implementation, this function is
61
63
  while y <= x:
62
64
  x -= y
63
65
  return x
64
66
 
65
67
 
66
68
  def fsum(iterable):
67
- # like Python's fsum, this method is much more resilient to rounding errors than regular sum
69
+ # like Python's fsum, this method is much more resilient to
70
+ # rounding errors than regular sum
68
71
  partials = [] # sorted, non-overlapping partial sums
69
72
  for x in iterable:
70
73
  i = 0
@@ -107,8 +110,9 @@ def exp(x):
107
110
 
108
111
 
109
112
  def expm1(x):
110
- # NOTE: Math.expm1() is currently only implemented in Firefox, this provides alternative implementation
111
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1
113
+ # NOTE: Math.expm1() is only in Firefox; this provides an alternative
114
+ # implementation. See MDN: https://developer.mozilla.org/en-US/docs/
115
+ # Web/JavaScript/Reference/Global_Objects/Math/expm1
112
116
  # return Math.expm1(x)
113
117
  if Math.abs(x) < 1e-5:
114
118
  return x + 0.5 * x * x
@@ -121,10 +125,12 @@ def log(x, base=e):
121
125
 
122
126
 
123
127
  def log1p(x):
124
- # NOTE: Math.log1p() is currently only implemented in Firefox, this provides alternative implementation
125
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p
128
+ # NOTE: Math.log1p() is only in Firefox; this provides an alternative
129
+ # implementation. See MDN: https://developer.mozilla.org/en-US/docs/
130
+ # Web/JavaScript/Reference/Global_Objects/Math/log1p
126
131
  # this version has been taken from http://phpjs.org/functions/log1p/
127
- # admittedly it's not as accurate as MDN version, as you can see from math.log1p(1) result
132
+ # admittedly it's not as accurate as MDN version, as you can see
133
+ # from math.log1p(1) result
128
134
  ret = 0
129
135
  n = 50
130
136
  if x <= -1:
@@ -140,9 +146,11 @@ def log1p(x):
140
146
 
141
147
 
142
148
  def log10(x):
143
- # NOTE: Math.log10() is currently only implemented in Firefox, this provides alternative implementation
144
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
145
- # I didn't find a more accurate algorithm so I'm using the basic implementation
149
+ # NOTE: Math.log10() is only in Firefox; this provides an alternative
150
+ # implementation. See MDN: https://developer.mozilla.org/en-US/docs/
151
+ # Web/JavaScript/Reference/Global_Objects/Math/log10
152
+ # I didn't find a more accurate algorithm so I'm using the
153
+ # basic implementation
146
154
  return Math.log(x) / Math.LN10
147
155
 
148
156
 
@@ -199,37 +207,43 @@ def radians(x): return x * pi / 180
199
207
  ########################################
200
208
  def acosh(x):
201
209
  # NOTE: will be replaced with official, when it becomes mainstream
202
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh
210
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
211
+ # Reference/Global_Objects/Math/acosh
203
212
  return Math.log(x + Math.sqrt(x * x - 1))
204
213
 
205
214
 
206
215
  def asinh(x):
207
216
  # NOTE: will be replaced with official, when it becomes mainstream
208
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh
217
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
218
+ # Reference/Global_Objects/Math/asinh
209
219
  return Math.log(x + Math.sqrt(x * x + 1))
210
220
 
211
221
 
212
222
  def atanh(x):
213
223
  # NOTE: will be replaced with official, when it becomes mainstream
214
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh
224
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
225
+ # Reference/Global_Objects/Math/atanh
215
226
  return 0.5 * Math.log((1 + x) / (1 - x))
216
227
 
217
228
 
218
229
  def cosh(x):
219
230
  # NOTE: will be replaced with official, when it becomes mainstream
220
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh
231
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
232
+ # Reference/Global_Objects/Math/cosh
221
233
  return (Math.exp(x) + Math.exp(-x)) / 2
222
234
 
223
235
 
224
236
  def sinh(x):
225
237
  # NOTE: will be replaced with official, when it becomes mainstream
226
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh
238
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
239
+ # Reference/Global_Objects/Math/sinh
227
240
  return (Math.exp(x) - Math.exp(-x)) / 2
228
241
 
229
242
 
230
243
  def tanh(x):
231
244
  # NOTE: will be replaced with official, when it becomes mainstream
232
- # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh
245
+ # https://developer.mozilla.org/en-US/docs/Web/JavaScript/
246
+ # Reference/Global_Objects/Math/tanh
233
247
  return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))
234
248
 
235
249
  # import stdlib
@@ -249,6 +263,8 @@ def tanh(x):
249
263
  # print(math.log(10), math.log(10, 1000))
250
264
  # print(math.log1p(1e-15), math.log1p(1))
251
265
  # print(math.log10(1000), math.log(1000, 10))
252
- # print(math.pow(1, 0), math.pow(1, NaN), math.pow(0, 0), math.pow(NaN, 0), math.pow(4,3), math.pow(100, -2))
266
+ # print(math.pow(1, 0), math.pow(1, NaN), math.pow(0, 0),
267
+ # math.pow(NaN, 0), math.pow(4,3), math.pow(100, -2))
253
268
  # print(math.hypot(3,4))
254
- # print(math.acosh(2), math.asinh(1), math.atanh(0.5), math.cosh(1), math.cosh(-1), math.sinh(1), math.tanh(1))
269
+ # print(math.acosh(2), math.asinh(1), math.atanh(0.5),
270
+ # math.cosh(1), math.cosh(-1), math.sinh(1), math.tanh(1))
@@ -5,9 +5,11 @@
5
5
 
6
6
  def strings():
7
7
  string_funcs = set((
8
- 'capitalize strip lstrip rstrip islower isupper isspace lower upper swapcase'
9
- ' center count endswith startswith find rfind index rindex format join ljust rjust'
10
- ' partition rpartition replace split rsplit splitlines zfill').split(' '))
8
+ 'capitalize strip lstrip rstrip islower isupper isspace'
9
+ ' lower upper swapcase center count endswith startswith'
10
+ ' find rfind index rindex format join ljust rjust'
11
+ ' partition rpartition replace split rsplit splitlines zfill'
12
+ ).split(' '))
11
13
 
12
14
  if not arguments.length:
13
15
  exclude = {'split', 'replace'}
@@ -10,7 +10,8 @@
10
10
 
11
11
  # basic implementation of Python's 'random' library
12
12
 
13
- # JavaScript's Math.random() does not allow seeding its random generator, to bypass that, this module implements its own
13
+ # JavaScript's Math.random() does not allow seeding its random
14
+ # generator, to bypass that, this module implements its own
14
15
  # version that can be seeded. I decided on RC4 algorithm for this.
15
16
 
16
17
  # please don't mess with this from the outside
@@ -23,9 +24,14 @@
23
24
 
24
25
  ρσ_get_random_byte = def ():
25
26
  ρσ_seed_state.key_i = (ρσ_seed_state.key_i + 1) % 256
26
- ρσ_seed_state.key_j = (ρσ_seed_state.key_j + ρσ_seed_state.key[ρσ_seed_state.key_i]) % 256
27
- ρσ_seed_state.key[ρσ_seed_state.key_i], ρσ_seed_state.key[ρσ_seed_state.key_j] = \
28
- ρσ_seed_state.key[ρσ_seed_state.key_j], ρσ_seed_state.key[ρσ_seed_state.key_i]
27
+ ρσ_seed_state.key_j = (
28
+ ρσ_seed_state.key_j + ρσ_seed_state.key[ρσ_seed_state.key_i]
29
+ ) % 256
30
+ (ρσ_seed_state.key[ρσ_seed_state.key_i],
31
+ ρσ_seed_state.key[ρσ_seed_state.key_j]) = (
32
+ ρσ_seed_state.key[ρσ_seed_state.key_j],
33
+ ρσ_seed_state.key[ρσ_seed_state.key_i]
34
+ )
29
35
  return ρσ_seed_state.key[(ρσ_seed_state.key[ρσ_seed_state.key_i] + \
30
36
  ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256]
31
37
 
@@ -41,7 +47,9 @@ def seed(x=Date().getTime()):
41
47
  j = 0
42
48
  for i in range(256):
43
49
  j = (j + ρσ_seed_state.key[i] + x.charCodeAt(i % x.length)) % 256
44
- ρσ_seed_state.key[i], ρσ_seed_state.key[j] = ρσ_seed_state.key[j], ρσ_seed_state.key[i]
50
+ (ρσ_seed_state.key[i],
51
+ ρσ_seed_state.key[j]) = (
52
+ ρσ_seed_state.key[j], ρσ_seed_state.key[i])
45
53
  seed()
46
54
 
47
55
 
package/src/lib/re.pyj CHANGED
@@ -473,7 +473,15 @@ _ALIAS_MAP = {
473
473
  }
474
474
  # }}}
475
475
 
476
- _ASCII_CONTROL_CHARS = {'a': 7, 'b': 8, 'f': 12, 'n': 10, 'r': 13, 't': 9, 'v': 11}
476
+ _ASCII_CONTROL_CHARS = {
477
+ 'a': 7,
478
+ 'b': 8,
479
+ 'f': 12,
480
+ 'n': 10,
481
+ 'r': 13,
482
+ 't': 9,
483
+ 'v': 11,
484
+ }
477
485
  _HEX_PAT = /^[a-fA-F0-9]/
478
486
  _NUM_PAT = /^[0-9]/
479
487
  _GROUP_PAT = /<([^>]+)>/
@@ -496,7 +504,8 @@ _re_cache_map = {}
496
504
  _re_cache_items = v'[]'
497
505
 
498
506
  error = SyntaxError # This is the error JS throws for invalid regexps
499
- has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)
507
+ has_prop = Object.prototype.hasOwnProperty.call.bind(
508
+ Object.prototype.hasOwnProperty)
500
509
 
501
510
 
502
511
  def _expand(groups, repl, group_name_map):
@@ -534,7 +543,13 @@ def _expand(groups, repl, group_name_map):
534
543
  if _ASCII_CONTROL_CHARS[q]:
535
544
  return String.fromCharCode(_ASCII_CONTROL_CHARS[q])
536
545
  if '0' <= q <= '9':
537
- ans = read_digits(Number.MAX_VALUE, _NUM_PAT, 10, Number.MAX_VALUE, q)
546
+ ans = read_digits(
547
+ Number.MAX_VALUE,
548
+ _NUM_PAT,
549
+ 10,
550
+ Number.MAX_VALUE,
551
+ q
552
+ )
538
553
  if jstype(ans) is 'number':
539
554
  return groups[ans] or ''
540
555
  return '\\' + ans
@@ -564,7 +579,10 @@ def _expand(groups, repl, group_name_map):
564
579
  if code <= 0xFFFF:
565
580
  return String.fromCharCode(code)
566
581
  code -= 0x10000
567
- return String.fromCharCode(0xD800 + (code >> 10), 0xDC00 + (code & 0x3FF))
582
+ return String.fromCharCode(
583
+ 0xD800 + (code >> 10),
584
+ 0xDC00 + (code & 0x3FF)
585
+ )
568
586
  return '\\U' + code
569
587
  if q is 'N' and peek() is '{':
570
588
  next()
@@ -581,7 +599,10 @@ def _expand(groups, repl, group_name_map):
581
599
  if code <= 0xFFFF:
582
600
  return String.fromCharCode(code)
583
601
  code -= 0x10000
584
- return String.fromCharCode(0xD800 + (code >> 10), 0xDC00 + (code & 0x3FF))
602
+ return String.fromCharCode(
603
+ 0xD800 + (code >> 10),
604
+ 0xDC00 + (code & 0x3FF)
605
+ )
585
606
 
586
607
  return '\\' + q
587
608
 
@@ -624,7 +645,9 @@ def transform_regex(source, flags):
624
645
 
625
646
  if ch is '[':
626
647
  in_class = True
627
- if source[pos] is ']': # in python the empty set is not allowed, instead []] is the same as [\]]
648
+ # in python the empty set is not allowed,
649
+ # instead []] is the same as [\]]
650
+ if source[pos] is ']':
628
651
  pos += 1
629
652
  ch = r'[\]'
630
653
  elif ch is '(':
@@ -637,7 +660,15 @@ def transform_regex(source, flags):
637
660
  pos = close + 1
638
661
  continue
639
662
  if 'aiLmsux'.indexOf(extension) is not -1:
640
- flag_map = {'a': ASCII, 'i': IGNORECASE, 'L': LOCALE, 'm': MULTILINE, 's': DOTALL, 'u': UNICODE, 'x': VERBOSE}
663
+ flag_map = {
664
+ 'a': ASCII,
665
+ 'i': IGNORECASE,
666
+ 'L': LOCALE,
667
+ 'm': MULTILINE,
668
+ 's': DOTALL,
669
+ 'u': UNICODE,
670
+ 'x': VERBOSE,
671
+ }
641
672
  close = source.indexOf(')', pos + 1)
642
673
  if close is -1:
643
674
  raise SyntaxError('Expecting a closing )')
@@ -650,14 +681,19 @@ def transform_regex(source, flags):
650
681
  pos = close + 1
651
682
  continue
652
683
  if extension is '(':
653
- raise SyntaxError('Group existence assertions are not supported in JavaScript')
684
+ raise SyntaxError(
685
+ 'Group existence assertions are not '
686
+ + 'supported in JavaScript'
687
+ )
654
688
  if extension is 'P':
655
689
  pos += 2
656
690
  q = source[pos]
657
691
  if q is '<':
658
692
  close = source.indexOf('>', pos)
659
693
  if close is -1:
660
- raise SyntaxError('Named group not closed, expecting >')
694
+ raise SyntaxError(
695
+ 'Named group not closed, expecting >'
696
+ )
661
697
  name = source[pos + 1:close]
662
698
  if not has_prop(group_map, name):
663
699
  group_map[name] = v'[]'
@@ -666,13 +702,20 @@ def transform_regex(source, flags):
666
702
  elif q is '=':
667
703
  close = source.indexOf(')', pos)
668
704
  if close is -1:
669
- raise SyntaxError('Named group back-reference not closed, expecting a )')
705
+ raise SyntaxError(
706
+ 'Named group back-reference not closed,'
707
+ + ' expecting a )'
708
+ )
670
709
  name = source[pos + 1:close]
671
710
  if not isNaN(parseInt(name, 10)):
672
711
  ans += '\\' + name
673
712
  else:
674
713
  if not has_prop(group_map, name):
675
- raise SyntaxError('Invalid back-reference. The named group: ' + name + ' has not yet been defined.')
714
+ raise SyntaxError(
715
+ 'Invalid back-reference. The named group: '
716
+ + name
717
+ + ' has not yet been defined.'
718
+ )
676
719
  ans += '\\' + group_map[name][-1]
677
720
  pos = close + 1
678
721
  continue
@@ -812,8 +855,14 @@ class MatchObject:
812
855
 
813
856
  class RegexObject:
814
857
  def __init__(self, pattern, flags):
815
- self.pattern = pattern.source if isinstance(pattern, RegExp) else pattern
816
- self.js_pattern, self.flags, self.group_name_map = transform_regex(self.pattern, flags)
858
+ self.pattern = pattern.source if isinstance(
859
+ pattern,
860
+ RegExp
861
+ ) else pattern
862
+ self.js_pattern, self.flags, self.group_name_map = transform_regex(
863
+ self.pattern,
864
+ flags
865
+ )
817
866
 
818
867
  modifiers = ''
819
868
  if self.flags & IGNORECASE: modifiers += 'i'
@@ -838,7 +887,12 @@ class RegexObject:
838
887
  return self._do_search(self._pattern, string, pos, endpos)
839
888
 
840
889
  def match(self, string, pos=0, endpos=None):
841
- return self._do_search(RegExp('^' + self.js_pattern, self._modifiers), string, pos, endpos)
890
+ return self._do_search(
891
+ RegExp('^' + self.js_pattern, self._modifiers),
892
+ string,
893
+ pos,
894
+ endpos
895
+ )
842
896
 
843
897
  def split(self, string, maxsplit=0):
844
898
  self._pattern.lastIndex = 0
@@ -850,7 +904,10 @@ class RegexObject:
850
904
 
851
905
  def finditer(self, string):
852
906
  # We have to copy pat since lastIndex is mutable
853
- pat = RegExp(this._pattern.source, this._modifiers) # noqa: unused-local
907
+ pat = RegExp( # noqa: unused-local
908
+ this._pattern.source,
909
+ this._modifiers
910
+ )
854
911
  ans = v"{'_string':string, '_r':pat, '_self':self}"
855
912
  ans[ρσ_iterator_symbol] = def ():
856
913
  return this
@@ -858,13 +915,15 @@ class RegexObject:
858
915
  m = this._r.exec(this._string)
859
916
  if m is None:
860
917
  return v"{'done':true}"
861
- return v"{'done':false, 'value':new MatchObject(this._self, m, 0, null)}"
918
+ _mo = MatchObject(this._self, m, 0, None) # noqa: unused-local
919
+ return v"{'done':false, 'value':_mo}"
862
920
  return ans
863
921
 
864
922
  def subn(self, repl, string, count=0):
865
923
  expand = _expand
866
924
  if jstype(repl) is 'function':
867
- expand = def (m, repl, gnm): return '' + repl(MatchObject(self, m, 0, None))
925
+ expand = def (m, repl, gnm):
926
+ return '' + repl(MatchObject(self, m, 0, None))
868
927
  this._pattern.lastIndex = 0
869
928
  num = 0
870
929
  matches = v'[]'
@@ -880,7 +939,11 @@ class RegexObject:
880
939
  m = matches[i] # noqa:undef
881
940
  start = m.index
882
941
  end = start + m[0].length
883
- string = string[:start] + expand(m, repl, self.group_name_map) + string[end:]
942
+ string = string[:start] + expand(
943
+ m,
944
+ repl,
945
+ self.group_name_map
946
+ ) + string[end:]
884
947
  return string, matches.length
885
948
 
886
949
  def sub(self, repl, string, count=0):