sipl-kit 0.4.0__tar.gz → 0.4.1__tar.gz
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.
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/CHANGELOG.md +11 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/PKG-INFO +16 -4
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/README.md +15 -3
- sipl_kit-0.4.1/docs/images/error.png +0 -0
- sipl_kit-0.4.1/docs/images/highlight.png +0 -0
- sipl_kit-0.4.1/docs/images/run.png +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/__init__.py +1 -1
- sipl_kit-0.4.1/vscode-sipl/CHANGELOG.md +11 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/vscode-sipl/README.md +10 -2
- sipl_kit-0.4.1/vscode-sipl/src/cli.js +189 -0
- sipl_kit-0.4.0/vscode-sipl/CHANGELOG.md +0 -5
- sipl_kit-0.4.0/vscode-sipl/src/cli.js +0 -118
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/.gitignore +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/LICENSE +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/docs/architecture.md +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/docs/cli.md +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/docs/language.md +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/docs/schema/cli-output.schema.json +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/divides.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/double_factorial_even.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/errors/infinite_loop.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/errors/missing_else.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/errors/trailing_semicolon.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/errors/undefined_variable.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/fibonacci.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/gcd.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/isqrt.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/parity.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/power.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/examples/prime.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/grammar/README.md +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/pyproject.toml +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/__main__.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/ast.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/cli.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/diagnostics.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/grammar/__init__.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/grammar/sipl.lark +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/interpreter/__init__.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/interpreter/events.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/interpreter/runtime.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/parser.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/printer.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/semantics/__init__.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/src/sipl/semantics/terms.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/conftest.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/01_empty.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/02_no_begin.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/03_empty_block.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/04_trailing_semicolon.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/05_missing_semicolon.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/06_if_without_else.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/07_eq_instead_assign.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/08_bad_char.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/09_condition_is_number.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/10_unclosed_paren.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/11_keyword_as_var.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/12_missing_end.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/13_two_programs.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/14_assign_to_number.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/invalid/15_double_plus.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/01_skip.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/02_assign.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/03_seq.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/04_if.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/05_while.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/06_nested_block.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/07_precedence.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/08_negative.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/09_conditions.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/10_comments.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/11_div_mod.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/12_keyword_prefix_vars.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/13_nested_if_while.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/grammar/valid/14_paren_cond.sipl +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_cli.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_grammar.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_interpreter.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_parser.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_printer.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_semantics.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/tests/test_trace.py +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/vscode-sipl/LICENSE +0 -0
- {sipl_kit-0.4.0 → sipl_kit-0.4.1}/vscode-sipl/src/extension.js +0 -0
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
Format: [Keep a Changelog](https://keepachangelog.com/), versions: [SemVer](https://semver.org/).
|
|
4
4
|
One version number is used for the Python package `sipl-kit` and the VS Code extension `sipl-vscode`.
|
|
5
5
|
|
|
6
|
+
## [0.4.1] - 2026-11-18
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- VS Code extension on Windows: when `python` is the Microsoft Store alias (exit code 9009) the extension
|
|
10
|
+
now tries `py -3`, `python`, `python3` and `sipl` and remembers the one that works.
|
|
11
|
+
If none works, the error explains how to set `sipl.pythonPath`.
|
|
12
|
+
- CI: extension tests run on Node 22 without a glob pattern.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Screenshots of the VS Code extension in both READMEs (REL-04).
|
|
16
|
+
|
|
6
17
|
## [0.4.0] - 2026-11-18
|
|
7
18
|
|
|
8
19
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sipl-kit
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: SIPL (SImple Programming Language) toolkit: grammar, parser, interpreter, trace, semantic terms and CLI
|
|
5
5
|
Project-URL: Homepage, https://github.com/exite-off/sipl-toolkit
|
|
6
6
|
Project-URL: Changelog, https://github.com/exite-off/sipl-toolkit/blob/main/CHANGELOG.md
|
|
@@ -124,15 +124,27 @@ print(derive(program).term) # AS^R(1) · WH(...)
|
|
|
124
124
|
|
|
125
125
|
1. Встановіть пакет: `pip install sipl-kit`.
|
|
126
126
|
2. Завантажте `sipl-vscode-<версія>.vsix` з [Releases](https://github.com/exite-off/sipl-toolkit/releases)
|
|
127
|
-
і встановіть: `code --install-extension sipl-vscode-0.4.
|
|
127
|
+
і встановіть: `code --install-extension sipl-vscode-0.4.1.vsix`.
|
|
128
128
|
3. Відкрийте `.sipl`-файл. Помилки підсвічуються одразу під час набору.
|
|
129
129
|
Кнопки ▶ (Run) і ✓ (Check) у заголовку редактора, Ctrl+F5 запускає програму.
|
|
130
130
|
Команди *SIPL: Trace* і *SIPL: Show Semantic Term* доступні з Command Palette.
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
Розширення саме шукає Python з `sipl-kit`: у Windows пробує `py -3`, `python`, `python3`, `sipl`,
|
|
133
|
+
в інших системах `python3`, `python`, `sipl`. Якщо не знаходить (наприклад, `python` у Windows відкриває
|
|
134
|
+
Microsoft Store), вкажіть повний шлях до інтерпретатора в налаштуванні `sipl.pythonPath`.
|
|
133
135
|
Сумісність: VS Code 1.85+, Windows / Linux / macOS.
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
Підсвітка синтаксису, кнопки Run ▶ і Check ✓:
|
|
138
|
+
|
|
139
|
+

|
|
140
|
+
|
|
141
|
+
Результат *SIPL: Run* для `X=4, Y=4` у панелі Output:
|
|
142
|
+
|
|
143
|
+

|
|
144
|
+
|
|
145
|
+
Синтаксична помилка підкреслюється в редакторі з точним рядком і колонкою:
|
|
146
|
+
|
|
147
|
+

|
|
136
148
|
|
|
137
149
|
## Приклади
|
|
138
150
|
|
|
@@ -101,15 +101,27 @@ print(derive(program).term) # AS^R(1) · WH(...)
|
|
|
101
101
|
|
|
102
102
|
1. Встановіть пакет: `pip install sipl-kit`.
|
|
103
103
|
2. Завантажте `sipl-vscode-<версія>.vsix` з [Releases](https://github.com/exite-off/sipl-toolkit/releases)
|
|
104
|
-
і встановіть: `code --install-extension sipl-vscode-0.4.
|
|
104
|
+
і встановіть: `code --install-extension sipl-vscode-0.4.1.vsix`.
|
|
105
105
|
3. Відкрийте `.sipl`-файл. Помилки підсвічуються одразу під час набору.
|
|
106
106
|
Кнопки ▶ (Run) і ✓ (Check) у заголовку редактора, Ctrl+F5 запускає програму.
|
|
107
107
|
Команди *SIPL: Trace* і *SIPL: Show Semantic Term* доступні з Command Palette.
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
Розширення саме шукає Python з `sipl-kit`: у Windows пробує `py -3`, `python`, `python3`, `sipl`,
|
|
110
|
+
в інших системах `python3`, `python`, `sipl`. Якщо не знаходить (наприклад, `python` у Windows відкриває
|
|
111
|
+
Microsoft Store), вкажіть повний шлях до інтерпретатора в налаштуванні `sipl.pythonPath`.
|
|
110
112
|
Сумісність: VS Code 1.85+, Windows / Linux / macOS.
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
Підсвітка синтаксису, кнопки Run ▶ і Check ✓:
|
|
115
|
+
|
|
116
|
+

|
|
117
|
+
|
|
118
|
+
Результат *SIPL: Run* для `X=4, Y=4` у панелі Output:
|
|
119
|
+
|
|
120
|
+

|
|
121
|
+
|
|
122
|
+
Синтаксична помилка підкреслюється в редакторі з точним рядком і колонкою:
|
|
123
|
+
|
|
124
|
+

|
|
113
125
|
|
|
114
126
|
## Приклади
|
|
115
127
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
- Find Python automatically (`py -3`, `python`, `python3`, `sipl` on Windows), skip the Microsoft Store alias,
|
|
6
|
+
clear error message with the `sipl.pythonPath` hint.
|
|
7
|
+
- Screenshots in README.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
- First release: language registration, TextMate grammar, snippets, Run/Check/Trace/Term commands, live diagnostics.
|
|
@@ -13,19 +13,27 @@ the extension calls `sipl ... --json` and shows the results.
|
|
|
13
13
|
- **SIPL: Trace** prints every execution event (assign, condition, before/after statement)
|
|
14
14
|
- **SIPL: Show Semantic Term** prints the term in course notation with all applied rules
|
|
15
15
|
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
16
22
|
|
|
17
23
|
## Requirements
|
|
18
24
|
|
|
19
25
|
- VS Code 1.85 or newer
|
|
20
26
|
- Python 3.10+ with the toolkit installed: `pip install sipl-kit`
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
The extension looks for Python with `sipl-kit` by itself: `py -3`, `python`, `python3`, `sipl` on Windows,
|
|
29
|
+
`python3`, `python`, `sipl` elsewhere. If none works (for example `python` opens the Microsoft Store on Windows),
|
|
30
|
+
set `sipl.pythonPath` (for example `C:\\Users\\me\\sipl\\.venv\\Scripts\\python.exe`).
|
|
23
31
|
|
|
24
32
|
## Settings
|
|
25
33
|
|
|
26
34
|
| Setting | Default | Meaning |
|
|
27
35
|
|---|---|---|
|
|
28
|
-
| `sipl.pythonPath` |
|
|
36
|
+
| `sipl.pythonPath` | empty: search | interpreter with `sipl-kit` installed |
|
|
29
37
|
| `sipl.cliPath` | empty | path to the `sipl` executable, used instead of `python -m sipl` |
|
|
30
38
|
| `sipl.maxSteps` | 100000 | step limit for Run/Trace |
|
|
31
39
|
| `sipl.checkOnType` | true | live syntax check |
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Thin wrapper around the sipl CLI. No vscode imports here, so it can be tested with plain node.
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
|
|
6
|
+
function defaultPython(platform = process.platform) {
|
|
7
|
+
return platform === "win32" ? "python" : "python3";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// commands to try in order, each is [command, baseArgs]
|
|
11
|
+
function candidates(config, platform = process.platform) {
|
|
12
|
+
const cliPath = (config.cliPath || "").trim();
|
|
13
|
+
if (cliPath) {
|
|
14
|
+
return [[cliPath, []]];
|
|
15
|
+
}
|
|
16
|
+
const python = (config.pythonPath || "").trim();
|
|
17
|
+
if (python) {
|
|
18
|
+
return [[python, ["-m", "sipl"]]];
|
|
19
|
+
}
|
|
20
|
+
if (platform === "win32") {
|
|
21
|
+
// "python" may be the Microsoft Store stub, so the py launcher goes first
|
|
22
|
+
return [["py", ["-3", "-m", "sipl"]], ["python", ["-m", "sipl"]], ["python3", ["-m", "sipl"]], ["sipl", []]];
|
|
23
|
+
}
|
|
24
|
+
return [["python3", ["-m", "sipl"]], ["python", ["-m", "sipl"]], ["sipl", []]];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// returns [command, baseArgs] that will be tried first
|
|
28
|
+
function resolveCommand(config, platform = process.platform) {
|
|
29
|
+
return candidates(config, platform)[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// "X=5, Y=2" -> ["-s", "X=5", "-s", "Y=2"], throws on bad input
|
|
33
|
+
function stateArgs(text) {
|
|
34
|
+
const args = [];
|
|
35
|
+
for (const raw of (text || "").split(/[,;\s]+/)) {
|
|
36
|
+
const part = raw.trim();
|
|
37
|
+
if (!part) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*=-?\d+$/.test(part)) {
|
|
41
|
+
throw new Error(`Bad state item "${part}", expected NAME=INT`);
|
|
42
|
+
}
|
|
43
|
+
args.push("-s", part);
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// CLI span (1-based, end exclusive) -> zero-based range parts
|
|
49
|
+
function spanToRange(span) {
|
|
50
|
+
const line = Math.max((span.line || 1) - 1, 0);
|
|
51
|
+
const col = Math.max((span.column || 1) - 1, 0);
|
|
52
|
+
let endLine = Math.max((span.end_line || span.line || 1) - 1, 0);
|
|
53
|
+
let endCol = Math.max((span.end_column || span.column || 1) - 1, 0);
|
|
54
|
+
if (endLine < line || (endLine === line && endCol <= col)) {
|
|
55
|
+
endLine = line;
|
|
56
|
+
endCol = col + 1;
|
|
57
|
+
}
|
|
58
|
+
return { line, col, endLine, endCol };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function formatState(state) {
|
|
62
|
+
const items = Object.entries(state || {}).map(([k, v]) => `${k} ↦ ${v}`);
|
|
63
|
+
return `[${items.join(", ")}]`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function formatEvent(e) {
|
|
67
|
+
const where = e.span ? `${e.span.line}:${e.span.column}` : "-";
|
|
68
|
+
const head = `#${String(e.step).padEnd(4)} ${where.padEnd(7)} ${e.kind.padEnd(17)}`;
|
|
69
|
+
switch (e.kind) {
|
|
70
|
+
case "assign":
|
|
71
|
+
return `${head} ${e.variable}: ${e.old === null ? "⊥" : e.old} -> ${e.new}`;
|
|
72
|
+
case "condition":
|
|
73
|
+
return `${head} ${e.construct} -> ${e.value}` + (e.iteration !== undefined ? ` (iteration ${e.iteration})` : "");
|
|
74
|
+
case "start":
|
|
75
|
+
case "finish":
|
|
76
|
+
return `${head} ${formatState(e.state)}`;
|
|
77
|
+
case "error":
|
|
78
|
+
return `${head} ${e.error.message}`;
|
|
79
|
+
default:
|
|
80
|
+
return `${head} ${e.node || ""}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// true when the command did not start or is not a working sipl
|
|
85
|
+
function isMissing(res) {
|
|
86
|
+
if (res.error) {
|
|
87
|
+
return res.error.code === "ENOENT";
|
|
88
|
+
}
|
|
89
|
+
return (
|
|
90
|
+
res.code === 9009 ||
|
|
91
|
+
/Python was not found/i.test(res.stderr) ||
|
|
92
|
+
/No module named '?sipl'?/.test(res.stderr) ||
|
|
93
|
+
/is not recognized as an internal or external command/i.test(res.stderr)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function spawnOnce(command, argv, source, options) {
|
|
98
|
+
const spawnFn = options.spawn || spawn;
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
let child;
|
|
101
|
+
try {
|
|
102
|
+
child = spawnFn(command, argv, {
|
|
103
|
+
cwd: options.cwd,
|
|
104
|
+
env: { ...process.env, PYTHONIOENCODING: "utf-8", PYTHONUTF8: "1" },
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
resolve({ error, stdout: "", stderr: "" });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let stdout = "";
|
|
111
|
+
let stderr = "";
|
|
112
|
+
let done = false;
|
|
113
|
+
const finish = (res) => {
|
|
114
|
+
if (!done) {
|
|
115
|
+
done = true;
|
|
116
|
+
resolve(res);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
child.stdout.setEncoding("utf8");
|
|
120
|
+
child.stderr.setEncoding("utf8");
|
|
121
|
+
child.stdout.on("data", (d) => (stdout += d));
|
|
122
|
+
child.stderr.on("data", (d) => (stderr += d));
|
|
123
|
+
child.on("error", (error) => finish({ error, stdout, stderr }));
|
|
124
|
+
child.on("close", (code) => finish({ code, stdout, stderr }));
|
|
125
|
+
child.stdin.on("error", () => {});
|
|
126
|
+
child.stdin.end(source, "utf8");
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function missingMessage(tried, configured, platform) {
|
|
131
|
+
const list = tried.map((c) => `"${c}"`).join(", ");
|
|
132
|
+
if (configured) {
|
|
133
|
+
return `Cannot run sipl with ${list}. Check sipl.pythonPath / sipl.cliPath and that sipl-kit is installed there (pip install sipl-kit).`;
|
|
134
|
+
}
|
|
135
|
+
let msg = `Python with sipl-kit was not found (tried ${list}). Install it with "pip install sipl-kit" ` +
|
|
136
|
+
"and, if Python is not on PATH, set sipl.pythonPath to the full path of python.exe.";
|
|
137
|
+
if (platform === "win32") {
|
|
138
|
+
msg += " A \"Python was not found\" message comes from the Microsoft Store alias: " +
|
|
139
|
+
"turn it off in Settings > Apps > Advanced app settings > App execution aliases.";
|
|
140
|
+
}
|
|
141
|
+
return msg;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// the command that worked last time, so the fallback search runs once
|
|
145
|
+
let cached = null;
|
|
146
|
+
|
|
147
|
+
// runs the CLI with source on stdin, resolves with {code, json, stderr}
|
|
148
|
+
async function runCli(config, args, source, options = {}) {
|
|
149
|
+
const platform = options.platform || process.platform;
|
|
150
|
+
let list = candidates(config, platform);
|
|
151
|
+
const configured = list.length === 1;
|
|
152
|
+
if (!configured && cached && cached.platform === platform) {
|
|
153
|
+
list = [cached.command, ...list.filter((c) => c[0] !== cached.command[0])];
|
|
154
|
+
}
|
|
155
|
+
const tried = [];
|
|
156
|
+
for (const [command, base] of list) {
|
|
157
|
+
tried.push(command);
|
|
158
|
+
const res = await spawnOnce(command, [...base, ...args, "-", "--json"], source, options);
|
|
159
|
+
if (res.error && !isMissing(res)) {
|
|
160
|
+
throw res.error;
|
|
161
|
+
}
|
|
162
|
+
if (isMissing(res)) {
|
|
163
|
+
if (cached && cached.command[0] === command) {
|
|
164
|
+
cached = null;
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let json = null;
|
|
169
|
+
try {
|
|
170
|
+
json = res.stdout.trim() ? JSON.parse(res.stdout) : null;
|
|
171
|
+
} catch (_) {
|
|
172
|
+
json = null;
|
|
173
|
+
}
|
|
174
|
+
if (json === null) {
|
|
175
|
+
throw new Error(`sipl exited with code ${res.code}: ${res.stderr.trim() || "no output"}`);
|
|
176
|
+
}
|
|
177
|
+
if (!configured) {
|
|
178
|
+
cached = { platform, command: [command, base] };
|
|
179
|
+
}
|
|
180
|
+
return { code: res.code, json, stderr: res.stderr };
|
|
181
|
+
}
|
|
182
|
+
throw new Error(missingMessage(tried, configured, platform));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function resetCache() {
|
|
186
|
+
cached = null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = { defaultPython, candidates, resolveCommand, resetCache, stateArgs, spanToRange, formatState, formatEvent, runCli };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// Thin wrapper around the sipl CLI. No vscode imports here, so it can be tested with plain node.
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const { spawn } = require("child_process");
|
|
5
|
-
|
|
6
|
-
function defaultPython(platform = process.platform) {
|
|
7
|
-
return platform === "win32" ? "python" : "python3";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// returns [command, baseArgs] for running the CLI
|
|
11
|
-
function resolveCommand(config, platform = process.platform) {
|
|
12
|
-
const cliPath = (config.cliPath || "").trim();
|
|
13
|
-
if (cliPath) {
|
|
14
|
-
return [cliPath, []];
|
|
15
|
-
}
|
|
16
|
-
const python = (config.pythonPath || "").trim() || defaultPython(platform);
|
|
17
|
-
return [python, ["-m", "sipl"]];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// "X=5, Y=2" -> ["-s", "X=5", "-s", "Y=2"], throws on bad input
|
|
21
|
-
function stateArgs(text) {
|
|
22
|
-
const args = [];
|
|
23
|
-
for (const raw of (text || "").split(/[,;\s]+/)) {
|
|
24
|
-
const part = raw.trim();
|
|
25
|
-
if (!part) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*=-?\d+$/.test(part)) {
|
|
29
|
-
throw new Error(`Bad state item "${part}", expected NAME=INT`);
|
|
30
|
-
}
|
|
31
|
-
args.push("-s", part);
|
|
32
|
-
}
|
|
33
|
-
return args;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// CLI span (1-based, end exclusive) -> zero-based range parts
|
|
37
|
-
function spanToRange(span) {
|
|
38
|
-
const line = Math.max((span.line || 1) - 1, 0);
|
|
39
|
-
const col = Math.max((span.column || 1) - 1, 0);
|
|
40
|
-
let endLine = Math.max((span.end_line || span.line || 1) - 1, 0);
|
|
41
|
-
let endCol = Math.max((span.end_column || span.column || 1) - 1, 0);
|
|
42
|
-
if (endLine < line || (endLine === line && endCol <= col)) {
|
|
43
|
-
endLine = line;
|
|
44
|
-
endCol = col + 1;
|
|
45
|
-
}
|
|
46
|
-
return { line, col, endLine, endCol };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function formatState(state) {
|
|
50
|
-
const items = Object.entries(state || {}).map(([k, v]) => `${k} ↦ ${v}`);
|
|
51
|
-
return `[${items.join(", ")}]`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function formatEvent(e) {
|
|
55
|
-
const where = e.span ? `${e.span.line}:${e.span.column}` : "-";
|
|
56
|
-
const head = `#${String(e.step).padEnd(4)} ${where.padEnd(7)} ${e.kind.padEnd(17)}`;
|
|
57
|
-
switch (e.kind) {
|
|
58
|
-
case "assign":
|
|
59
|
-
return `${head} ${e.variable}: ${e.old === null ? "⊥" : e.old} -> ${e.new}`;
|
|
60
|
-
case "condition":
|
|
61
|
-
return `${head} ${e.construct} -> ${e.value}` + (e.iteration !== undefined ? ` (iteration ${e.iteration})` : "");
|
|
62
|
-
case "start":
|
|
63
|
-
case "finish":
|
|
64
|
-
return `${head} ${formatState(e.state)}`;
|
|
65
|
-
case "error":
|
|
66
|
-
return `${head} ${e.error.message}`;
|
|
67
|
-
default:
|
|
68
|
-
return `${head} ${e.node || ""}`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// runs the CLI with source on stdin, resolves with {code, json, stderr}
|
|
73
|
-
function runCli(config, args, source, options = {}) {
|
|
74
|
-
const [command, base] = resolveCommand(config, options.platform);
|
|
75
|
-
const spawnFn = options.spawn || spawn;
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
let child;
|
|
78
|
-
try {
|
|
79
|
-
child = spawnFn(command, [...base, ...args, "-", "--json"], {
|
|
80
|
-
cwd: options.cwd,
|
|
81
|
-
env: { ...process.env, PYTHONIOENCODING: "utf-8", PYTHONUTF8: "1" },
|
|
82
|
-
});
|
|
83
|
-
} catch (err) {
|
|
84
|
-
reject(err);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
let stdout = "";
|
|
88
|
-
let stderr = "";
|
|
89
|
-
child.stdout.setEncoding("utf8");
|
|
90
|
-
child.stderr.setEncoding("utf8");
|
|
91
|
-
child.stdout.on("data", (d) => (stdout += d));
|
|
92
|
-
child.stderr.on("data", (d) => (stderr += d));
|
|
93
|
-
child.on("error", (err) => {
|
|
94
|
-
if (err.code === "ENOENT") {
|
|
95
|
-
reject(new Error(`Cannot start "${command}". Install sipl-kit (pip install sipl-kit) or set sipl.pythonPath / sipl.cliPath.`));
|
|
96
|
-
} else {
|
|
97
|
-
reject(err);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
child.on("close", (code) => {
|
|
101
|
-
let json = null;
|
|
102
|
-
try {
|
|
103
|
-
json = stdout.trim() ? JSON.parse(stdout) : null;
|
|
104
|
-
} catch (_) {
|
|
105
|
-
json = null;
|
|
106
|
-
}
|
|
107
|
-
if (json === null) {
|
|
108
|
-
const hint = /No module named sipl/.test(stderr) ? " Install it with: pip install sipl-kit" : "";
|
|
109
|
-
reject(new Error(`sipl exited with code ${code}: ${stderr.trim() || "no output"}.${hint}`));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
resolve({ code, json, stderr });
|
|
113
|
-
});
|
|
114
|
-
child.stdin.end(source, "utf8");
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = { defaultPython, resolveCommand, stateArgs, spanToRange, formatState, formatEvent, runCli };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|