Skip to content

Commit 1c446a0

Browse files
enhance: update deps / support aiscript v1.1
1 parent df839f1 commit 1c446a0

File tree

4 files changed

+218
-144
lines changed

4 files changed

+218
-144
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { AISCRIPT_VERSION, Parser, Interpreter, utils, errors, type Ast } from 'aiscript1_1';
2+
import { Runner } from '../runner';
3+
4+
export default class extends Runner {
5+
version = AISCRIPT_VERSION;
6+
7+
parse(code: string) {
8+
const ast = Parser.parse(code);
9+
const metadata = Interpreter.collectMetadata(ast);
10+
return [ast, metadata] as const;
11+
}
12+
13+
private interpreter = new Interpreter({}, {
14+
out: (value) => {
15+
this.print(
16+
value.type === 'num' ? value.value.toString()
17+
: value.type === 'str' ? `"${value.value}"`
18+
: JSON.stringify(utils.valToJs(value), null, 2) ?? '',
19+
);
20+
},
21+
log: (type, params) => {
22+
if (type === 'end' && params.val != null && 'type' in params.val) {
23+
this.print(utils.valToString(params.val, true));
24+
}
25+
},
26+
});
27+
async exec(node: unknown): Promise<void> {
28+
await this.interpreter.exec(node as Ast.Node[]);
29+
}
30+
isAiScriptError(error: unknown): error is errors.AiScriptError {
31+
return error instanceof errors.AiScriptError;
32+
}
33+
getErrorName(error: errors.AiScriptError): string | undefined {
34+
if (error instanceof errors.AiScriptSyntaxError) {
35+
return 'SyntaxError';
36+
}
37+
if (error instanceof errors.AiScriptTypeError) {
38+
return 'TypeError';
39+
}
40+
if (error instanceof errors.AiScriptRuntimeError) {
41+
return 'RuntimeError';
42+
}
43+
if (error instanceof errors.AiScriptIndexOutOfRangeError) {
44+
return 'IndexOutOfRangeError';
45+
}
46+
if (error instanceof errors.AiScriptUserError) {
47+
return 'UserError';
48+
}
49+
return 'AiScriptError';
50+
}
51+
dispose() {
52+
this.interpreter.abort();
53+
}
54+
}

.vitepress/scripts/versions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface VersionModule {
66

77
export const versionModules = new Map<string, () => Promise<VersionModule>>([
88
['dev', () => import('./dev')],
9+
['1.1.0', () => import('./1.1.0')],
910
['1.0.0', () => import('./1.0.0')],
1011
['0.19.0', () => import('./0.19.0')],
1112
['0.18.0', () => import('./0.18.0')],

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
"devDependencies": {
1111
"@syuilo/aiscript": "dev",
1212
"aiscript-vscode": "github:aiscript-dev/aiscript-vscode#v0.1.16",
13-
"aiscript1_0": "npm:@syuilo/aiscript@1.0.0",
1413
"aiscript0_14": "npm:@syuilo/aiscript@0.14.1",
1514
"aiscript0_15": "npm:@syuilo/aiscript@0.15.0",
1615
"aiscript0_16": "npm:@syuilo/aiscript@0.16.0",
1716
"aiscript0_17": "npm:@syuilo/aiscript@0.17.0",
1817
"aiscript0_18": "npm:@syuilo/aiscript@0.18.0",
1918
"aiscript0_19": "npm:@syuilo/aiscript@0.19.0",
19+
"aiscript1_0": "npm:@syuilo/aiscript@1.0.0",
20+
"aiscript1_1": "npm:@syuilo/aiscript@1.1.0",
2021
"lz-string": "^1.5.0",
2122
"markdown-it-mathjax3": "^4.3.2",
2223
"shiki": "^3.9.2",
2324
"vite": "^7.0.6",
24-
"vitepress": "^1.6.3",
25+
"vitepress": "^1.6.4",
2526
"vue": "^3.5.18"
2627
},
2728
"pnpm": {

0 commit comments

Comments
 (0)