-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from aiscript-dev/aiscript-next
AiScript Next
- Loading branch information
Showing
53 changed files
with
6,712 additions
and
4,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# AiScriptパーサーの全体像 | ||
|
||
AiScriptのパーサーは2つの段階を経て構文ツリーに変換される。 | ||
|
||
1. ソースコードをトークン列に分割する | ||
2. トークン列を順番に読み取って構文ツリー(AST)を構築する | ||
|
||
ソースコードをトークン列に分割する処理(トークナイズと呼ばれる)は「Scanner」というモジュールが担当する。 | ||
トークン列から構文ツリーを構築する処理(パース)は、syntaxesディレクトリ以下にあるパース関数が担当する。名前がparseから始まっている関数がパース関数。 | ||
|
||
AiScriptのパーサーではトークナイズはまとめて行われない。 | ||
パース関数が次のトークンを要求すると、下位モジュールであるScannerが次のトークンを1つだけ読み取る。 | ||
|
||
Scannerによって現在の読み取り位置(カーソル位置)が保持される。 | ||
また、Scannerの各種メソッドで現在のトークンが期待されたものと一致するかどうかの確認やトークンの種類の取得などを行える。 | ||
これらの機能を利用することにより、パース関数を簡潔に記述できる。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Scanner 設計資料 | ||
|
||
## 現在のトークンと先読みされたトークン | ||
_tokensの0番には現在のトークンが保持される。また、トークンが先読みされた場合は1番以降にそれらのトークンが保持されていくことになる。 | ||
例えば、次のトークンを1つ先読みした場合は0番に現在のトークンが入り1番に先読みされたトークンが入る。 | ||
|
||
nextメソッドで現在位置が移動すると、それまで0番にあったトークン(現在のトークン)は配列から削除され、1番にあった要素は現在のトークンとなる。 | ||
配列から全てのトークンが無くなった場合はトークンの読み取りが実行される。 | ||
|
||
## CharStream | ||
ScannerはCharStreamを下位モジュールとして利用する。 | ||
CharStreamは入力文字列から一文字ずつ文字を取り出すことができる。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# TokenStreams | ||
各種パース関数はITokenStreamインターフェースを実装したクラスインスタンスを引数にとる。 | ||
|
||
実装クラス | ||
- Scanner | ||
- TokenStream | ||
|
||
## TokenStream | ||
読み取り済みのトークン列を入力にとるストリーム。 | ||
テンプレート構文の式部分ではトークン列の読み取りだけを先に行い、式の内容の解析はパース時に遅延して行われる。 | ||
この時の読み取り済みのトークン列はTokenStremとしてパース関数に渡される。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.