Skip to content

Commit df839f1

Browse files
enhance: aiscript v1.0.0 に対応
1 parent 398d7db commit df839f1

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
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_0';
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.0.0', () => import('./1.0.0')],
910
['0.19.0', () => import('./0.19.0')],
1011
['0.18.0', () => import('./0.18.0')],
1112
['0.17.0', () => import('./0.17.0')],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
},
99
"packageManager": "pnpm@9.14.3",
1010
"devDependencies": {
11-
"@syuilo/aiscript": "1.0.0-dev.20250804",
11+
"@syuilo/aiscript": "dev",
1212
"aiscript-vscode": "github:aiscript-dev/aiscript-vscode#v0.1.16",
13+
"aiscript1_0": "npm:@syuilo/aiscript@1.0.0",
1314
"aiscript0_14": "npm:@syuilo/aiscript@0.14.1",
1415
"aiscript0_15": "npm:@syuilo/aiscript@0.15.0",
1516
"aiscript0_16": "npm:@syuilo/aiscript@0.16.0",

pnpm-lock.yaml

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)