rapydscript-ns 0.9.2 → 0.9.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.
- package/CHANGELOG.md +28 -0
- package/PYTHON_GAPS.md +352 -0
- package/README.md +176 -32
- package/TODO.md +1 -128
- package/bin/rapydscript +70 -70
- package/language-service/index.js +242 -11
- package/memory/project_string_impl.md +43 -0
- package/package.json +1 -1
- package/release/baselib-plain-pretty.js +248 -38
- package/release/baselib-plain-ugly.js +8 -8
- package/release/compiler.js +778 -277
- package/release/signatures.json +30 -30
- package/src/ast.pyj +10 -1
- package/src/baselib-builtins.pyj +56 -2
- package/src/baselib-containers.pyj +25 -1
- package/src/baselib-errors.pyj +7 -3
- package/src/baselib-internal.pyj +51 -6
- package/src/baselib-str.pyj +18 -5
- package/src/lib/asyncio.pyj +534 -0
- package/src/lib/base64.pyj +399 -0
- package/src/lib/bisect.pyj +73 -0
- package/src/lib/collections.pyj +228 -4
- package/src/lib/csv.pyj +494 -0
- package/src/lib/heapq.pyj +98 -0
- package/src/lib/html.pyj +382 -0
- package/src/lib/http/__init__.pyj +98 -0
- package/src/lib/http/client.pyj +304 -0
- package/src/lib/http/cookies.pyj +236 -0
- package/src/lib/logging.pyj +672 -0
- package/src/lib/pprint.pyj +455 -0
- package/src/lib/pythonize.pyj +20 -20
- package/src/lib/statistics.pyj +0 -0
- package/src/lib/string.pyj +357 -0
- package/src/lib/textwrap.pyj +329 -0
- package/src/lib/urllib/__init__.pyj +14 -0
- package/src/lib/urllib/error.pyj +66 -0
- package/src/lib/urllib/parse.pyj +475 -0
- package/src/lib/urllib/request.pyj +86 -0
- package/src/monaco-language-service/analyzer.js +5 -2
- package/src/monaco-language-service/completions.js +26 -0
- package/src/monaco-language-service/diagnostics.js +203 -4
- package/src/monaco-language-service/scope.js +1 -0
- package/src/output/codegen.pyj +4 -1
- package/src/output/functions.pyj +152 -6
- package/src/output/loops.pyj +17 -2
- package/src/output/modules.pyj +1 -1
- package/src/output/operators.pyj +15 -0
- package/src/output/stream.pyj +0 -1
- package/src/parse.pyj +108 -24
- package/src/tokenizer.pyj +19 -3
- package/test/async_generators.pyj +144 -0
- package/test/asyncio.pyj +307 -0
- package/test/base64.pyj +202 -0
- package/test/baselib.pyj +23 -0
- package/test/bisect.pyj +178 -0
- package/test/chainmap.pyj +185 -0
- package/test/csv.pyj +405 -0
- package/test/float_special.pyj +64 -0
- package/test/heapq.pyj +174 -0
- package/test/html.pyj +212 -0
- package/test/http.pyj +259 -0
- package/test/imports.pyj +79 -72
- package/test/logging.pyj +356 -0
- package/test/long.pyj +130 -0
- package/test/parenthesized_with.pyj +141 -0
- package/test/pprint.pyj +232 -0
- package/test/python_compat.pyj +3 -5
- package/test/python_modulo.pyj +76 -0
- package/test/python_modulo_off.pyj +21 -0
- package/test/statistics.pyj +224 -0
- package/test/str.pyj +14 -0
- package/test/string.pyj +245 -0
- package/test/textwrap.pyj +172 -0
- package/test/type_display.pyj +48 -0
- package/test/type_enforcement.pyj +164 -0
- package/test/unit/index.js +94 -6
- package/test/unit/language-service-completions.js +121 -0
- package/test/unit/language-service-scope.js +32 -0
- package/test/unit/language-service.js +190 -5
- package/test/unit/run-language-service.js +17 -3
- package/test/unit/web-repl.js +2401 -13
- package/test/urllib.pyj +193 -0
- package/tools/compile.js +1 -1
- package/tools/embedded_compiler.js +7 -7
- package/tools/export.js +4 -2
- package/web-repl/main.js +1 -1
- package/web-repl/rapydscript.js +7 -5
- package/test/omit_function_metadata.pyj +0 -20
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: string.pyj Implementation
|
|
3
|
+
description: string module (character constants, Template, Formatter) — pitfalls and design decisions
|
|
4
|
+
type: project
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## string.pyj Implementation (added 2026-05-02)
|
|
8
|
+
- `src/lib/string.pyj` — character constants, `Template`, `Formatter`
|
|
9
|
+
- `test/string.pyj` — unit tests; `test/unit/web-repl.js` — 3 bundle tests (bundle_string_*)
|
|
10
|
+
- Language service: `'string'` added to `STDLIB_MODULES` in `src/monaco-language-service/diagnostics.js`
|
|
11
|
+
|
|
12
|
+
## Character Constants
|
|
13
|
+
- Built via simple Python assignments; `chr(39)` = `'`, `chr(92)` = `\`, `chr(96)` = `` ` `` avoid escaping issues in string literals
|
|
14
|
+
- `whitespace = ' \t\n\r' + chr(11) + chr(12)` — chr(11)=VT, chr(12)=FF
|
|
15
|
+
|
|
16
|
+
## Template
|
|
17
|
+
- `substitute(mapping=None)` / `safe_substitute(mapping=None)` — accepts plain dict or ρσ_dict
|
|
18
|
+
- `_tmpl_to_plain(mapping)` converts ρσ_dict (via `.jsmap`) to a plain JS object
|
|
19
|
+
- `_tmpl_re` regex: `/\$(?:(\$)|\{([_a-zA-Z][_a-zA-Z0-9]*)\}|([_a-zA-Z][_a-zA-Z0-9]*)|([^]?))/g`
|
|
20
|
+
- Uses `[^]?` (zero-or-one of any char) to match trailing lone `$` so substitute raises ValueError
|
|
21
|
+
- `ρσ_str(val)` used for substituted values (gives 'None' for null, matching Python behavior)
|
|
22
|
+
|
|
23
|
+
## Formatter
|
|
24
|
+
- `format(format_string, *args)` — positional args ONLY (no **kwargs in RapydScript)
|
|
25
|
+
- Named fields: use `vformat(fmt, [], {'key': val})` directly
|
|
26
|
+
- `vformat` delegates to `_fmt_vformat(fmt_str, args, kwargs, self)` JS helper
|
|
27
|
+
- `_fmt_get_kwarg(kwargs, key)` handles both plain objects and ρσ_dict (.jsmap)
|
|
28
|
+
- `format_field` calls `format(value, format_spec)` (= `ρσ_format`) for specs; `str(value)` when empty
|
|
29
|
+
- Subclassing works: override `format_field`, `convert_field`, `get_value`, `get_field`
|
|
30
|
+
|
|
31
|
+
## Critical v-block Pitfall Discovered
|
|
32
|
+
**v-blocks are TRULY VERBATIM — Python does NOT process escape sequences.**
|
|
33
|
+
- `\n` in v-block → `\n` in JS output (which in a JS string = newline char)
|
|
34
|
+
- `\\n` in v-block → `\\n` in JS output (which in a JS string = backslash+n)
|
|
35
|
+
- For regex literals in v-blocks: write exactly the JS you want — `\$` → `\$` in JS regex (literal $)
|
|
36
|
+
- NEVER double backslashes in v-block regex literals (unlike what an older MEMORY note implies)
|
|
37
|
+
- The MEMORY note about doubling (`\\n`/`\\t`) applies when you WANT literal `\n` text in JS, not actual newlines
|
|
38
|
+
|
|
39
|
+
## String.prototype .upper() in Tests
|
|
40
|
+
- `String.prototype.upper` (and other Python str methods) is NOT added in the test runner context unless `from pythonize import strings` is used
|
|
41
|
+
- Subclass tests that operate on string return values must use `.toUpperCase()` (native JS) not `.upper()` (Python) unless pythonize is imported
|
|
42
|
+
|
|
43
|
+
**Why:** How to apply: When testing Formatter/string subclasses in .pyj test files that don't import pythonize, use `v'result.toUpperCase()'` not `result.upper()`.
|
package/package.json
CHANGED