Skip to content

Commit

Permalink
enhance: ファイル実行の調整 (#748)
Browse files Browse the repository at this point in the history
* execute file

* docs

* ignore main.ais

* fix doc

* changelog
  • Loading branch information
marihachi authored Aug 4, 2024
1 parent e4f6de8 commit 6fafa1e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/src/parser/parser.js
/src/parser/parser.mjs
npm-debug.log
test.is
main.ais
pnpm-lock.yaml
tsdoc-metadata.json
38 changes: 38 additions & 0 deletions docs/execution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 実行方法
## 1. Playgroundから実行
自分でホストする場合は、以下のコマンドを実行し表示されたリンクをブラウザで開きます。
```
cd playground
npm run build
npm run serve
```

PlaygroundはGitHubでもホストされています:\
https://aiscript-dev.github.io/aiscript/

## 2. スクリプトファイルから実行
ファイルの内容を解析して実行します。

プロジェクトルートに`main.ais`を作成し、以下の内容を記述しファイルに保存します。
```
<: "Hello world!"
```

以下のコマンドを実行します。
```
$ npm run start
```

## 3. スクリプトファイルを解析する (パーサーのデバッグ向け)
ファイルの内容を解析してASTを表示することができます。
主にパーサーのデバッグ向けで、インタプリタの実装状況に関わらずASTの内容を表示することができます。

プロジェクトルートに`main.ais`を作成し、以下の内容を記述しファイルに保存します。
```
<: "Hello world!"
```

以下のコマンドを実行します。
```
$ npm run parse
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
},
"scripts": {
"start": "node ./run",
"parse": "node ./parse",
"start": "node ./scripts/start.mjs",
"parse": "node ./scripts/parse.mjs",
"ts": "npm run ts-esm && npm run ts-dts",
"ts-esm": "tsc --outDir built/esm",
"ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true",
Expand Down
2 changes: 1 addition & 1 deletion parse.js → scripts/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import fs from 'fs';
import { Parser } from '@syuilo/aiscript';
import { inspect } from 'util';

const script = fs.readFileSync('./test.is', 'utf8');
const script = fs.readFileSync('./main.ais', 'utf8');
const ast = Parser.parse(script);
console.log(inspect(ast, { depth: 10 }));
2 changes: 1 addition & 1 deletion run.js → scripts/start.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const interpreter = new Interpreter({}, {
}
});

const script = fs.readFileSync('./test.is', 'utf8');
const script = fs.readFileSync('./main.ais', 'utf8');
try {
const ast = Parser.parse(script);
await interpreter.exec(ast);
Expand Down
2 changes: 2 additions & 0 deletions unreleased/script-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- AiScriptのスクリプトファイルを表す拡張子が`.is`から`.ais`に変更されました。
- ファイル実行機能により読み取られるファイルの名前が`test.is`から`main.ais`へ変更されました。

0 comments on commit 6fafa1e

Please sign in to comment.