rapydscript-ns 0.8.3 → 0.9.0
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.
- package/CHANGELOG.md +26 -0
- package/README.md +1351 -141
- package/TODO.md +12 -6
- package/language-service/index.js +184 -26
- package/package.json +1 -1
- package/release/baselib-plain-pretty.js +5895 -1928
- package/release/baselib-plain-ugly.js +140 -3
- package/release/compiler.js +16282 -5408
- package/release/signatures.json +25 -22
- package/src/ast.pyj +94 -1
- package/src/baselib-builtins.pyj +362 -3
- package/src/baselib-bytes.pyj +664 -0
- package/src/baselib-containers.pyj +99 -0
- package/src/baselib-errors.pyj +45 -1
- package/src/baselib-internal.pyj +346 -49
- package/src/baselib-itertools.pyj +17 -4
- package/src/baselib-str.pyj +46 -4
- package/src/lib/abc.pyj +317 -0
- package/src/lib/copy.pyj +120 -0
- package/src/lib/dataclasses.pyj +532 -0
- package/src/lib/enum.pyj +125 -0
- package/src/lib/pythonize.pyj +1 -1
- package/src/lib/re.pyj +35 -1
- package/src/lib/react.pyj +74 -0
- package/src/lib/typing.pyj +577 -0
- package/src/monaco-language-service/builtins.js +19 -4
- package/src/monaco-language-service/diagnostics.js +40 -19
- package/src/output/classes.pyj +161 -25
- package/src/output/codegen.pyj +16 -2
- package/src/output/exceptions.pyj +97 -1
- package/src/output/functions.pyj +87 -5
- package/src/output/jsx.pyj +164 -0
- package/src/output/literals.pyj +28 -2
- package/src/output/loops.pyj +5 -2
- package/src/output/modules.pyj +1 -1
- package/src/output/operators.pyj +108 -36
- package/src/output/statements.pyj +2 -2
- package/src/output/stream.pyj +1 -0
- package/src/parse.pyj +496 -128
- package/src/tokenizer.pyj +38 -4
- package/test/abc.pyj +291 -0
- package/test/arithmetic_nostrict.pyj +88 -0
- package/test/arithmetic_types.pyj +169 -0
- package/test/baselib.pyj +91 -0
- package/test/bytes.pyj +467 -0
- package/test/classes.pyj +1 -0
- package/test/comparison_ops.pyj +173 -0
- package/test/dataclasses.pyj +253 -0
- package/test/enum.pyj +134 -0
- package/test/eval_exec.pyj +56 -0
- package/test/format.pyj +148 -0
- package/test/object.pyj +64 -0
- package/test/python_compat.pyj +17 -15
- package/test/python_features.pyj +89 -21
- package/test/regexp.pyj +29 -1
- package/test/tuples.pyj +96 -0
- package/test/typing.pyj +469 -0
- package/test/unit/index.js +2292 -70
- package/test/unit/language-service.js +674 -4
- package/test/unit/web-repl.js +1106 -0
- package/test/vars_locals_globals.pyj +94 -0
- package/tools/cli.js +11 -0
- package/tools/compile.js +5 -0
- package/tools/embedded_compiler.js +15 -4
- package/tools/lint.js +16 -19
- package/tools/repl.js +1 -1
- package/web-repl/env.js +122 -0
- package/web-repl/main.js +1 -3
- package/web-repl/rapydscript.js +125 -3
- package/PYTHON_DIFFERENCES_REPORT.md +0 -291
- package/PYTHON_FEATURE_COVERAGE.md +0 -200
- package/hack_demo.pyj +0 -112
package/src/lib/re.pyj
CHANGED
|
@@ -22,14 +22,18 @@ _NAME_PAT = /^[a-zA-Z ]/
|
|
|
22
22
|
I = IGNORECASE = 2
|
|
23
23
|
L = LOCALE = 4
|
|
24
24
|
M = MULTILINE = 8
|
|
25
|
-
D = DOTALL = 16
|
|
25
|
+
S = D = DOTALL = 16 # re.S is the canonical Python alias; re.D kept for compat
|
|
26
26
|
U = UNICODE = 32
|
|
27
27
|
X = VERBOSE = 64
|
|
28
28
|
DEBUG = 128
|
|
29
29
|
A = ASCII = 256
|
|
30
|
+
NOFLAG = 0
|
|
30
31
|
|
|
31
32
|
supports_unicode = RegExp.prototype.unicode is not undefined
|
|
32
33
|
|
|
34
|
+
# ES2022 'd' (hasIndices) flag gives exact group start/end offsets
|
|
35
|
+
_supports_indices = v"(function(){try{new RegExp('a','d');return true;}catch(e){return false;}})()"
|
|
36
|
+
|
|
33
37
|
_RE_ESCAPE = /[-\/\\^$*+?.()|[\]{}]/g
|
|
34
38
|
|
|
35
39
|
_re_cache_map = {}
|
|
@@ -240,6 +244,18 @@ class MatchObject:
|
|
|
240
244
|
match = self._groups
|
|
241
245
|
self._start = v'Array(match.length)'
|
|
242
246
|
self._end = v'Array(match.length)'
|
|
247
|
+
# ES2022: use accurate per-group indices when the 'd' flag is present
|
|
248
|
+
if match.indices is not undefined:
|
|
249
|
+
for v'var i = 0; i < match.indices.length; i++':
|
|
250
|
+
pair = match.indices[i] # noqa:undef
|
|
251
|
+
if pair is undefined:
|
|
252
|
+
self._start[i] = -1
|
|
253
|
+
self._end[i] = -1
|
|
254
|
+
else:
|
|
255
|
+
self._start[i] = pair[0]
|
|
256
|
+
self._end[i] = pair[1]
|
|
257
|
+
return
|
|
258
|
+
# Fallback heuristic for environments without 'd' flag
|
|
243
259
|
self._start[0] = self._start_pos
|
|
244
260
|
self._end[0] = self._start_pos + match[0].length
|
|
245
261
|
offset = self._start_pos
|
|
@@ -358,6 +374,8 @@ class RegexObject:
|
|
|
358
374
|
if self.flags & MULTILINE: modifiers += 'm'
|
|
359
375
|
if not (self.flags & ASCII) and supports_unicode:
|
|
360
376
|
modifiers += 'u'
|
|
377
|
+
if _supports_indices:
|
|
378
|
+
modifiers += 'd'
|
|
361
379
|
self._modifiers = modifiers + 'g'
|
|
362
380
|
self._pattern = RegExp(self.js_pattern, self._modifiers)
|
|
363
381
|
|
|
@@ -424,6 +442,19 @@ class RegexObject:
|
|
|
424
442
|
def sub(self, repl, string, count=0):
|
|
425
443
|
return self.subn(repl, string, count)[0]
|
|
426
444
|
|
|
445
|
+
def fullmatch(self, string, pos=0, endpos=None):
|
|
446
|
+
if endpos is not None:
|
|
447
|
+
string = string[:endpos]
|
|
448
|
+
end = string.length
|
|
449
|
+
# Sticky 'y' + no 'm': anchors match to exactly pos..end
|
|
450
|
+
mods = self._modifiers.replace('g', 'y').replace('m', '')
|
|
451
|
+
pat = RegExp(self.js_pattern + '$', mods)
|
|
452
|
+
pat.lastIndex = pos
|
|
453
|
+
m = pat.exec(string)
|
|
454
|
+
if m is None or m.index is not pos or m.index + m[0].length is not end:
|
|
455
|
+
return None
|
|
456
|
+
return MatchObject(self, m, pos, endpos)
|
|
457
|
+
|
|
427
458
|
def _get_from_cache(pattern, flags):
|
|
428
459
|
if isinstance(pattern, RegExp):
|
|
429
460
|
pattern = pattern.source
|
|
@@ -446,6 +477,9 @@ def search(pattern, string, flags=0):
|
|
|
446
477
|
def match(pattern, string, flags=0):
|
|
447
478
|
return _get_from_cache(pattern, flags).match(string)
|
|
448
479
|
|
|
480
|
+
def fullmatch(pattern, string, flags=0):
|
|
481
|
+
return _get_from_cache(pattern, flags).fullmatch(string)
|
|
482
|
+
|
|
449
483
|
def split(pattern, string, maxsplit=0, flags=0):
|
|
450
484
|
return _get_from_cache(pattern, flags).split(string)
|
|
451
485
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD
|
|
3
|
+
# RapydScript bindings for React.
|
|
4
|
+
#
|
|
5
|
+
# Supported: all standard hooks (useState, useEffect, useContext, useReducer,
|
|
6
|
+
# useCallback, useMemo, useRef, useImperativeHandle, useLayoutEffect,
|
|
7
|
+
# useDebugValue, useId, useTransition, useDeferredValue), core classes
|
|
8
|
+
# (Component, PureComponent), special elements (Fragment, StrictMode,
|
|
9
|
+
# Suspense, Profiler), and utilities (createElement, cloneElement,
|
|
10
|
+
# createContext, createRef, forwardRef, isValidElement, memo, lazy).
|
|
11
|
+
#
|
|
12
|
+
# Requires React to be available as a global variable. Load it via a CDN
|
|
13
|
+
# <script> tag, a bundler global shim, or any other mechanism before your
|
|
14
|
+
# compiled script runs.
|
|
15
|
+
#
|
|
16
|
+
# Usage:
|
|
17
|
+
# from __python__ import jsx
|
|
18
|
+
# from react import useState, useEffect, useRef
|
|
19
|
+
#
|
|
20
|
+
# def Counter():
|
|
21
|
+
# count, setCount = useState(0)
|
|
22
|
+
# def handleClick():
|
|
23
|
+
# setCount(count + 1)
|
|
24
|
+
# return <button onClick={handleClick}>{count}</button>
|
|
25
|
+
#
|
|
26
|
+
# For class components extend React.Component directly (no import needed):
|
|
27
|
+
#
|
|
28
|
+
# class MyComponent(React.Component):
|
|
29
|
+
# def render(self):
|
|
30
|
+
# return <div>{self.props.title}</div>
|
|
31
|
+
|
|
32
|
+
# ── Hooks (React 16.8+) ───────────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
useState = React.useState
|
|
35
|
+
useEffect = React.useEffect
|
|
36
|
+
useContext = React.useContext
|
|
37
|
+
useReducer = React.useReducer
|
|
38
|
+
useCallback = React.useCallback
|
|
39
|
+
useMemo = React.useMemo
|
|
40
|
+
useRef = React.useRef
|
|
41
|
+
useImperativeHandle = React.useImperativeHandle
|
|
42
|
+
useLayoutEffect = React.useLayoutEffect
|
|
43
|
+
useDebugValue = React.useDebugValue
|
|
44
|
+
|
|
45
|
+
# ── Hooks (React 18+) ────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
useId = React.useId
|
|
48
|
+
useTransition = React.useTransition
|
|
49
|
+
useDeferredValue = React.useDeferredValue
|
|
50
|
+
useSyncExternalStore = React.useSyncExternalStore
|
|
51
|
+
useInsertionEffect = React.useInsertionEffect
|
|
52
|
+
|
|
53
|
+
# ── Core classes ─────────────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
Component = React.Component
|
|
56
|
+
PureComponent = React.PureComponent
|
|
57
|
+
|
|
58
|
+
# ── Special elements ─────────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
Fragment = React.Fragment
|
|
61
|
+
StrictMode = React.StrictMode
|
|
62
|
+
Suspense = React.Suspense
|
|
63
|
+
Profiler = React.Profiler
|
|
64
|
+
|
|
65
|
+
# ── Utilities ────────────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
createElement = React.createElement
|
|
68
|
+
cloneElement = React.cloneElement
|
|
69
|
+
createContext = React.createContext
|
|
70
|
+
createRef = React.createRef
|
|
71
|
+
forwardRef = React.forwardRef
|
|
72
|
+
isValidElement = React.isValidElement
|
|
73
|
+
memo = React.memo
|
|
74
|
+
lazy = React.lazy
|