kairos-lang 1.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Kairos — schedule definition language
2
+ Copyright 2026 azathothx
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # Kairos リファレンス実装(プロトタイプ)
2
+
3
+ > **English readers**: this is the reference implementation of [Kairos](https://kairos-lang.org/), a schedule
4
+ > definition language. The language docs are canonical in Japanese with a full English mirror —
5
+ > [English spec](https://kairos-lang.org/en/spec/) · [recipes](https://kairos-lang.org/en/recipes/) ·
6
+ > [playground](https://kairos-lang.org/en/playground/). CLI: `npx kairos-lang next -n 3 payday.kairos`
7
+ > (evaluator messages are Japanese; `--json` output is language-neutral). Apache-2.0.
8
+
9
+ スケジュール定義言語 **Kairos**([`../spec/`](../spec/))のリファレンス実装の試作。
10
+ 目的は仕様の実行可能性の検証——**EBNF §5.6 がそのままパーサに、代表例 §7 と 40-examples の実データが
11
+ そのままテストに**なるかを確かめ、仕様の穴を実行で炙り出すこと(結果=綻び F43〜F50。
12
+ [`../design/40-examples/90-findings.md`](../design/40-examples/90-findings.md))。
13
+
14
+ ## 使い方
15
+
16
+ ```bash
17
+ npm install # devDependencies(typescript / vitest)のみ
18
+ npm test # spec §7 全代表例・NAOJ 暦要項実データ・静的エラー・reference/ と stdlib/ の doctest
19
+ npm run typecheck
20
+
21
+ # CLI(Node 24+。TS をネイティブ実行。サブコマンド省略時は list)
22
+ node src/cli.ts list examples/payday.kairos --from 2026-01-01 --to 2027-01-01
23
+ node src/cli.ts list examples/jp-holidays.kairos --from 2026-01-01 --to 2027-01-01
24
+ node src/cli.ts list examples/rokuyo.kairos --from 2026-01-01 --to 2027-01-01 # 旧暦・六曜(大安など)
25
+ node src/cli.ts next -n 3 examples/payday.kairos # 今日から次の 3 発火
26
+ node src/cli.ts next --json examples/payday.kairos # 機械可読(下記 CliReport)
27
+ ```
28
+
29
+ ### CLI サブコマンド
30
+
31
+ - **`list [--from] [--to] [--tz] [--json] <file>`** — 範囲 `[from, to)` の全発火・区間註釈・
32
+ 被覆サマリ。既定は実行 tz の今日から 1 年。
33
+ - **`next [-n 件数] [--from] [--horizon 年数] [--tz] [--json] <file>`** — `from`(既定=今日)以降の
34
+ 次の N 発火(既定 1)。探索窓を 1 年から倍々に広げ(上限 `--horizon` 年・既定 10)、見つかったら
35
+ **[from, 最終発火日の翌日) で確定再評価**——区間註釈・残走路が答えの範囲と整合する。
36
+ 本体式 1 つのファイル向け(複数は明示エラー。`list` を使う)。
37
+ - **`--json`** — `CliReport`(`command`/`version`/`tz`/`from`/`to`/`results`〔`dates`・`points`=
38
+ epoch ms・`annotations`=`fromMs`/`toMs` 込み〕/`coverage`/`warnings`)を書き出す。人間表示と
39
+ 同じ器から直列化するため両表示は乖離しない。`points`/`fromMs` は「判定は外部」(ADR-37)の
40
+ 交差計算を呼び手が epoch ms のまま行うための器。
41
+ - **`--supply <file.json>`** — `external`(ADR-46)の解決値を**静的束**で渡す。形は
42
+ `{キー: {dates|instants, covering, asof [, labels]}}`——キーは**束縛名**または
43
+ `"premise.束縛名"`(修飾が優先)。`dates` は `"YYYY-MM-DD"` の配列・`instants` は epoch ms の
44
+ 数値配列(`CliReport` の `points` と同じ規約)。CLI は JSON の**形**だけを検査し、覆域の包含・
45
+ 昇順・実在日などの**供給契約はそのまま評価器の検査**(ADR-46 の 12 種)に掛かる——被覆サマリの
46
+ `asof`/残走路も供給値から出る。`--supply` 無しで `external` を解決しようとすると供給エラー
47
+ (ADR-46 の既定)。
48
+ - **`--lang en`** — 人間表示の**枠組みだけ**英語化(見出し・被覆サマリ・残走路・USAGE・警告ラベル)。
49
+ 評価器メッセージ(エラー・註釈文)は**日本語が正**のまま・`--json` は言語中立——線引きは
50
+ 英語版 Playground(`/en/playground/`)と同一。
51
+ - **終了コード**: 0=成功・1=エラー・2=`next` が地平線内に要求件数未達(部分結果は出力し、
52
+ stderr に不足の内訳)。`--version` は実装版を出して 0 終了。
53
+ - `external` の解決子は持たない(解決時は供給エラー=ADR-46 の既定どおり)。警告は常に stderr。
54
+
55
+ ライブラリとして:
56
+
57
+ ```ts
58
+ import { run } from './src/index.ts';
59
+ const r = run(source, { from: '2026-01-01', to: '2027-01-01' });
60
+ r.results[0].dates; // ['2026-01-23', …]
61
+ ```
62
+
63
+ ## 設計(仕様との対応)
64
+
65
+ | 層 | ファイル | 対応する仕様 |
66
+ |---|---|---|
67
+ | 字句 | `src/lexer.ts` | §5.5・ADR-28(日付・幅リテラル、市民時/経過時間の混合エラー、Unicode 識別子) |
68
+ | 構文 | `src/parser.ts` | §5.6 EBNF(前文・束縛・gen-expr・値式の優先順位・テーブルリテラル) |
69
+ | 評価 | `src/eval.ts` | §3(窓生成語・機構 A・遅延解決)・§4(core 段・射影)・I1〜I8 の一部を実行時検査 |
70
+ | 標準 premise | `stdlib/*.kairos`(gregorian・fiscal・isoweek を依存順にロード) | 各 stdlib ページ §1 の完全定義を **Kairos ソースのまま**評価器に食わせる(Kyureki はデータ入り premise のため同梱しない=[`../stdlib/kyureki.md`](../stdlib/kyureki.md)) |
71
+
72
+ 方針: **評価器は core 演算子だけを実装**し、`Gregorian`・糖衣・祝日カスケードはすべて Kairos ソースとして
73
+ 評価する(言語組み込みの魔法にしない=「透明な標準ライブラリ」ADR-25 の検証)。
74
+
75
+ 検証済みの言語機構: 二層構造・前文(三形+後置畳み込み `axis:`)・機構 A(`Fiscal` の `quarter` 自動追従)・
76
+ `with` 上書きと `rephase` 展開の一致・糖衣の遅延解決(`nextWeekday` の前方 roll・WKST 非依存)・
77
+ week 窓の `wkst:` 遅延解決・cycle(曜日・年干支)・テーブルリテラル(`covering:`/`labels:`・昇順検査)・
78
+ 束縛名射影(`sekki(s) == 立春`)・射影 `ordinalIn`/`epochOrdinal`・`snapTo`・結合子カスケード・
79
+ 選択子の窓相対(I4 エラー含む)・`segmentBy`(隙間ポリシー必須)・ストライド(`from:` 必須=ADR-31)・
80
+ 文字列リテラル(`tz: "Asia/Tokyo"`=ADR-32)・grid の `anchor:`(ADR-31)・
81
+ **カレンダー実体と bizDay 標準導出**(`calendar: TSE`・軸位置の `on: TSE`・正体判定=ADR-35。doctest の
82
+ 標準前提も実体経由)・**member 解決規則**(定義側優先の上書き重ね=ADR-35 判断 8)・**整列の検査**
83
+ (`&`/`\`/`filter(on:)`/`roll(on:)`/`shift(unit: 点列軸)` の同一 G 要求・`snapTo` の再整列=ADR-36)・
84
+ **範囲外出自と covering: の活性化**(ADR-37。値随伴の区間註釈=輸送表 §4.10・包含の静的検査・
85
+ 開端/区間リスト covering・束縛後置の被覆主張+必要条件検査・実効被覆域の分類器・
86
+ `RunResult.annotations`/`coverage`(残走路)・segmentBy の覆域端発火・地平線 4 サイトの三分岐降格・
87
+ defCache キーへの asof/source 追加)・**窓所属の述語 `coincides` と stride の入力相対**
88
+ (ADR-38。証人規則の三分岐・tz 静的検査・窓語 S / cycle w の静的エラー・filter 輸送の逆像拡幅
89
+ =F75・stride の n 域検査と from: 規約・**窓リーダーの覆域検査=F82**〔覆域外に張られた窓の読みは
90
+ coincides/ordinalIn/epochOrdinal/ラベル射影とも範囲外——合成マーカー帯の黙った 24 時間帯化の封止〕)・**窓列への並行ラベル列**(ADR-39。segmentBy の `labels:`・
91
+ 束縛名射影・覆域基準の同長性検査=F62 の器・clip/drop/label: 同居/規則マーカー/合成マーカーの
92
+ 静的エラー群・未知 named-arg を黙って捨てない検査)・**多 TZ**(IANA tz を Intl ベース・依存ゼロで
93
+ サポート——premise 相対 TZ〔ADR-33 の射影パラメータモデル〕・DST の 23/25h 市民日〔ADR-11/12 の
94
+ 幅規約の実行検証〕・隙間/重複リテラルの明示エラー・tz 相対の紀元・covering 端の premise tz 解決・
95
+ 整列タグの tz 名と実幾何の一致・`tz:` 宣言必須の執行=ADR-35/37)・**日付ラベル保存の再錨
96
+ `rebase` と免除系の tz 名検査**(ADR-40。day 整列検査・存在しない日付の明示エラー・
97
+ 最初の瞬間への着地・恒等最適化・註釈の floor/ceil 輸送・within/選択子/ordinalIn/cycle・値射影の
98
+ 市民グリッド tz 名検査〔snapTo は除外〕——F69 の解=TSE×NYSE 共通営業日が書ける)・
99
+ **営業時間の供給規約と標準導出**(ADR-41。`sessionOpens`/`sessionCloses` の対宣言〔with 継承込み〕・整合性検査
100
+ 〔結合実効被覆域∩実体化範囲の局所交互・端の切り欠き・同時刻対は両点保持=文脈順序〕・実体相対の
101
+ `bizOpen`/`bizClose`/`isOpen`〔開場日固定=F85・証人規則の三分岐・実体キーのメモ化〕——
102
+ クロス tz の isOpen が tz 検査に掛からず読める=F89)・**時刻付き anchor/from: の壁時計ラベル読み**
103
+ (ADR-31 改訂 2=F87 の修正。切替日 anchor の grid が anchor 自身を通り、同じ壁時計の 2 本が
104
+ 同一 G になる・shift の経過保存は回帰テストで固定=F83 (a))・**窓インスタンス参照**
105
+ (ADR-42。適用の引数型 dispatch〔点→束縛名射影・値→逆像〕を WindowsV/StreamV+wins の二表現に
106
+ 対で実装・要素点列=定義が窓に束ねた入力点列の窓所属〔F93〕・「窓列→要素点列」の輸送行
107
+ 〔F94。filter と共通経路 `filterByPredicate` を共有=第 5 の窓リーダーサイト〕・逆像は窓単位の
108
+ ラベル評価〔ADR-34 の構造保証から外延等価・naive filter の 1/5〜1/25〕・静的検査群 (a)〜(g)
109
+ 〔自己参照ガードの値引数拡張=ADR-34 改訂・labels: リテラルの域外検査を含む〕・修飾適用形
110
+ `Gregorian.year(2020)`・stdlib の標準ラベル〔Gregorian year/month・Fiscal.year の同時付与=F96〕
111
+ ——`marineDay \ year(2020)` 級の F9 正準例が立つ)・**リテラルと値束縛の締め**(ADR-43。
112
+ 非実在日付の字句エラー〔2026-02-30 級のロールオーバー封止〕・固定オフセット tz の厳格一意形
113
+ 〔"±HH:MM" のみ・Intl 前段の字句検査〕・時点の裸の値束縛=F97 の挙動固定)・**文の区切りと
114
+ 複数行継続**(ADR-44。括弧内自由改行・行頭/行末の段・結合子継続・空行跨ぎ可)・
115
+ **空テーブルリテラル**(ADR-45=F98。`[] covering:` 限定の昇格・covering 必須/labels: [] のみの
116
+ 誘導エラー・整列の第三状態**空虚適合**〔全整列に適合・結合は相手を継承・rebase は恒等〕・
117
+ 空 nonWorking 実体の boot=bizDay 縮退の観測可能性・**F99 修正**=roll 空軸の依存像の過小近似
118
+ 〔dependImageAnn の early return 削除・有限/開端 covering の観測差の回復〕——掃引 23 テスト)・
119
+ **外部供給宣言 `external`**(ADR-46=socket の確定。解決子フック `RunOptions.resolve`〔同期〕・
120
+ `SupplyError`=解決失敗の機械可読部分類・契約検査 12 種〔covering/asof 必須・kind 幾何・包含・
121
+ 昇順・同長/値域/無宣言到着・実在日の再執行・有限整数〕・スナップショット socketCache〔定義側
122
+ premise 単位・一評価一解決・要求駆動〕・位置/tz/source の静的検査・予約語・wire=dates 字面/
123
+ instants ms・doctest `# resolve:` ディレクティブ——external.test.ts 35 本+観測等価スイート。
124
+ **プロトタイプ注記**: 評価器は run ごと生成のため解決値 asof のメモ化キー参加は構成で適合——
125
+ 常駐評価器に転用する場合は defCache キーへ解決値 asof を含めること〔ADR-46 判断 6〕)・
126
+ **窓列への周期ラベル**(ADR-47。`labels: cycle リスト anchor:`——同長性検査なし・位相の宣言のみ)・
127
+ **split の親受理拡張**(ADR-48。実効パーティション規則・境界整合検査・総和検査のエラー昇格)・
128
+ **先頭/末尾 N 選択**(ADR-49/52。`take(n, from:)`・`takeLast(n, until:)`——窓付き入力の誘導エラー・
129
+ 輸送の縮小/鏡像・実装地平線ガード 2 面)・**hour 窓と ordinalIn 整合検査**(ADR-50)・
130
+ **単独時刻リテラルと標準糖衣 at**(ADR-51。`Thh:mm`・strideBy 時刻分岐=epoch 錨・at の名指し
131
+ 検査 2 本〔窓付き入力・引数限定〕)・**束縛右辺の名前解決境界とメモ化の正しさ**(ADR-53+追記
132
+ 1〜3。呼び出し側ラムダ変数の遮断〔4 経路〕・tz 名検査の記録+ヒット時再実行〔fromPredicate+
133
+ baseAlign・再実行の外側フレーム再記録〕)。
134
+
135
+ ## プロトタイプの制約(仕様との既知の乖離)
136
+
137
+ - **有界実体化**: 時間ストリームは [1970-01-01, to+400日) で実体化する。I7(遅延・無限・オンライン)は
138
+ 近似。1970 以前は評価できない。
139
+ - **TZ は IANA tz を実装**(`src/tz.ts`——Intl.DateTimeFormat の探査+二分法でオフセット遷移点列を
140
+ 一度だけ構築・依存ゼロ)。市民日は「その日付になる最初の瞬間」からの半開区間(ADR-33 判断 4)で、
141
+ DST 切替日は 23/25 時間(1d=市民日 ≠ 86400s=ADR-11/12 の幅規約を実行検証)。前文 `tz:` メンバーは
142
+ 評価され、day グリッド・リテラルの錨打ち・紀元(1970-01-01T00:00 の逆像)・covering の端が
143
+ **premise 相対**になる(ADR-33 の射影パラメータモデル)。DST の隙間・重複に落ちる時刻リテラルは
144
+ 明示エラー(解決規約は将来の opt-in)。整列タグ(ADR-36)の tz 名は実幾何と一致する
145
+ (`tz:` 未宣言の premise は実行既定 tz へフォールバック——タグと幾何は常に同じ tz)。
146
+ 残る近似: うるう秒はスコープ外(ADR-33=乖離ではない)・遷移タイムラインの構築範囲は
147
+ [1969, 2101)・tzdb 版はプロセスの ICU 版に固定(ADR-33 判断 10 の版差リスクは仕様どおり)・
148
+ 時刻付き anchor の civil grid 境界は「各市民日で anchor の壁時計時刻(ラベル読み)を最初に読む
149
+ 瞬間」(隙間は隙間明けの最初の瞬間・重複は最初の出現=ADR-31 改訂 2。市民日の開始点を anchor に
150
+ すると日整列=off 0——真夜中遷移 tz の 01:00 開始も日整列と読む)。
151
+ - **未実装**: `Modified` ロール(上位窓引数。roll の依存像も Following/Preceding の 2 規約のみ)・
152
+ `everyInstant` の一般合成(`strideBy(w, from:)` のみ)。
153
+ - **整列(ADR-36)は評価時のタグ伝播**=「束縛解決後静的検査」の近似。細かい原子 grid(秒級
154
+ `grid 1s`)は有界実体化のため実用不能——ADR-36 判断 8 の修理形の検証は 1h 級まで。
155
+ 定量(F80): `hour |> first` は hour 窓の全実体化(約 49 万窓)で例 1 本 12〜22 秒、
156
+ `everyInstant |> strideBy(1h, from:)` は from: 以降のみで 1 秒級(from: がグリッド上なら同じ
157
+ 点列)——doctest の hour 級の例は後者で書く。**本体層の束縛も defCache でメモ化される**
158
+ (2026-08-03。premise 公開語と同じ評価文脈キー=root premise 名+wkst/tz/… の member 列。
159
+ 旧実装は素通しで、値述語から参照されるストリーム束縛〈segmentBy の帯等〉が点ごとに右辺
160
+ 再評価=O(N²) になっていた——実測 37 秒 → 1.5 秒・回帰テストは警告の重複で観測)。
161
+ 窓インスタンス参照 `W(v)`(ADR-42)は W の解決 1 回+窓単位のラベル評価なので値述語形より
162
+ 桁で軽い(実測で naive filter の 1/5〜1/25)。
163
+ - **`label:` 付与式は実装済み**(ADR-34): ラムダは窓の先頭点・射影時の遅延評価・自己参照は明示エラー・
164
+ cycle への label: は明示エラー。字句の時刻検査(`23:59:60` 拒否=ADR-33)も実装。
165
+ 自己参照ガード(labelStack)はラムダの同一性に依存する——本体層束縛もメモ化される現行実装では
166
+ 解決がクロージャ同一性を保存するためガードが効く(旧実装は解決ごとの新クロージャですり抜けて
167
+ 無限再帰し得た既知の穴=本体層メモ化と束ねて 2026-08-03 に解消・回帰テストあり)。
168
+ - **有界実体化の端の扱い**: `span phase:>0` の頭・`split` の末尾には**切れ端窓**を張り、I5(全域
169
+ パーティション)を実体化範囲内で保つ(これが無いと `ordinalIn(month, year, d)` が「枠窓の外」を誤報)。
170
+ 切れ端窓の `label:` は**切れ端の先頭点**で評価されるため、本来の窓と別のラベルが付き得る——
171
+ 窓インスタンス参照 `W(v)` ではこのずれが**「別の年への漏れ」に増幅**される(例: `Fiscal` の頭の
172
+ 切れ端 [1970-01-01, 1970-04-01) は FY1969 の尾だが先頭点の暦年 1970 が付き、`year(1970)` に混入)。
173
+ 実体化端(紀元 1970 直後・to+400 日際)を跨ぐインスタンス参照は評価範囲を内側に取って避けること
174
+ (ADR-42 帰結の注記)。
175
+ 計算範囲(to+約 400 日)越えの `snapTo`/`roll` 終端/`shift` は**クリップ+機械可読警告
176
+ `horizon-clip:`** に降格済み(ADR-37 判断 8 の三分岐——「評価範囲はデータ被覆域に重ねて取る」の
177
+ 運用制約は解消)。roll/shift の地平線判定は「軸の終端が評価 to 以遠まで実体化されているか」の近似。
178
+ - **範囲外出自(ADR-37)の近似**: 註釈は評価時の値随伴伝播(整列タグと同型)。`stride` の位相汚染は
179
+ 「from: 以降で交差する註釈区間の尾部を +∞ へ拡張」の保守近似(stride は入力相対=ADR-38 で確定)。
180
+ `snapTo` の註釈の像は端点を属する窓の先頭へ床処理(覆域の端を窓粒度で解決する操作形)。
181
+ 被覆主張の必要条件検査は「成分 covering の和 ∪ 複合註釈の補集合」で判定(規則ベース成分は補集合側で
182
+ 通る)。**`covering:`/日付テーブルを持つ premise の `tz:` 宣言必須**(ADR-35 判断 1/ADR-37 判断 1)は
183
+ **宣言時に執行**する(base 連鎖の宣言でも可=member 解決規則で内側固定。覆域の端は premise tz の
184
+ 市民日で解決)。並行リスト添字(F62)の分類は依存が覆域を持たないため常に硬エラー側。
185
+ - 実装で出た綻び F43〜F50 は仕様側で解消済み(例の修正=F45〜F48・ADR-31/32=F43/F44/F49/F50)。
186
+ ただし `epoch:` の**既定以外の値**(別紀元の暦法)は未対応(宣言すると静的エラーで知らせる)。
187
+
188
+ ## テスト
189
+
190
+ (28 ファイル・638 本〔doctest 込み〕。下記の個別解説に加え、後発の
191
+ `test/empty-table.test.ts`〔ADR-45〕・`test/external.test.ts`〔ADR-46・35 本〕・
192
+ `test/cycle-labels.test.ts`〔ADR-47〕・`test/split-parent.test.ts`〔ADR-48〕・
193
+ `test/take.test.ts`/`test/takelast.test.ts`〔ADR-49/52〕・`test/hour-window.test.ts`〔ADR-50〕・
194
+ `test/at-time-of-day.test.ts`〔ADR-51〕・`test/memoization.test.ts`〔ADR-53=遮断・順序独立・
195
+ 間接参照 witness 3 経路・診断全文固定〕・`test/table-postfix.test.ts`〔束縛後置 covering〕がある。)
196
+
197
+
198
+ - `test/examples.test.ts` — spec §7 の全代表例。糖衣形と core 展開形の一致、JS Date による独立オラクル照合
199
+ (月末 3 営業日前・第 2 営業日の次の金曜・給料日)、祝日カスケード(2026 年の振替 5/6・国民の休日 9/22 の
200
+ 導出)、会計暦、年干支、week/WKST、入れ子窓。
201
+ - `test/projections.test.ts` — 射影一族と天文暦。期待値は NAOJ 令和8年暦要項
202
+ (`../design/40-examples/95-reference-data.md`): 立春 2/4・八十八夜 5/2・二百十日 9/1・旧正月 2/17。
203
+ - `test/static-errors.test.ts` — 統治の静的エラー(幅の混合・core 語再定義・I4・I5・昇順・labels: 同長)。
204
+ - `test/stdlib-premises.test.ts` — 同梱 stdlib premise(Fiscal・ISOWeek)の回帰。ISO 週暦は JS 実装の
205
+ isocalendar を独立オラクルに全数照合(label: 不要の等価変形の検証)。切れ端窓(I5)・div の floor
206
+ (F63)の回帰を含む。
207
+ - `test/label.test.ts` — `label:` 付与式(ADR-34)。年度ラベル(span)・旧暦月名(segmentBy・文字列
208
+ リスト添字)・split/grid のラベル・自己参照/cycle/非ラムダの明示エラー・字句の時刻検査。
209
+ - `test/calendar-entity.test.ts` — カレンダー実体(ADR-35)と整列(ADR-36)。標準導出のオラクル照合・
210
+ `on: TSE` の等価・`axis: TSE` 畳み込み・正体判定/予約/逆向き判定の静的エラー・`&`/`\`/`filter(on:)`/
211
+ `roll(on:)` の整列エラーと `snapTo` 整合・混合和・窓語 shift の免除・strideBy のグリッド一致。
212
+ - `test/annotations.test.ts` — 範囲外出自と covering: の活性化(ADR-37)。包含の静的検査・開端/区間
213
+ リスト covering・クリップ枠・結合子の相殺なし和と bizDay 退化の観測・shift の平行移動像・roll の
214
+ 依存像と三分岐(範囲外/地平線/完結の尽き)・選択子の窓拡幅・stride の位相汚染・segmentBy の覆域端
215
+ (最終窓の確定)・filter/epochOrdinal の「落として註釈」と覆域内硬エラーの非対称・被覆主張と必要条件
216
+ 検査・被覆サマリ(残走路・完結主張)・defCache×asof。
217
+ - `test/coincides.test.ts` — 窓所属の述語と stride の入力相対(ADR-38)。真偽の確定・証人規則の
218
+ 三分岐(覆域端跨ぎ窓の証人・退化 S の非証人・覆域完全の偽)・filter 輸送の逆像拡幅(F75)・
219
+ tz 不一致/窓語 S/cycle w の静的エラー・閏月検出(閏六月 2025-07-25)・毎営業日 9 時の正準形と
220
+ 前段差の一致・stride の n 域と from: 規約・窓リーダーの覆域検査(F82=合成マーカー帯の
221
+ 覆域外読みは落として註釈——06-business-hours の敵対的検証で発見した回帰)。
222
+ - `test/window-labels.test.ts` — 窓列への並行ラベル列(ADR-39)。束縛名射影と旧イディオムの一致・
223
+ 空窓のラベル読み(欠ティティ)・紀元跨ぎの窓列序数・覆域外射影の分類・同長エラー(短/長)・
224
+ clip/drop/label: 同居/規則マーカー/合成マーカーの静的エラー・被覆主張による合成マーカーの通し・
225
+ 未知 named-arg(core 段・gen 語・糖衣)。
226
+ - `test/timezone.test.ts` — 多 TZ(ADR-33/35/36/37 の幾何側)。DST 切替日の 23/25h 市民日・
227
+ strideBy の市民時幅/経過時間幅の分岐・切替日を跨ぐ roll/shift・隙間/重複リテラルの明示エラー・
228
+ 真夜中スキップ tz(チリ)の市民日開始・premise 相対 day グリッドと紀元・covering 端の premise tz
229
+ 解決・整列 tz 不一致(実幾何)・クロス tz snapTo=chronos の重なり(F69 の前提の固定)・
230
+ Kyureki 型の内側固定・2027 春節の JST/CST 割れ・tz: 必須の執行・時刻付き anchor/from: の壁時計
231
+ ラベル読み(ADR-31 改訂 2=F87: 切替日 anchor・隙間/重複の目盛り・同一 G)・shift の経過保存の
232
+ 固定回帰(F83 (a): 単射着地・往復恒等・Santiago の日開始着地)。
233
+ - `test/business-hours.test.ts` — 営業時間の供給規約と標準導出(ADR-41)。ADR の TSE 二部制の例
234
+ そのままで isOpen の真偽(半開境界・昼休み・半日休・祝日)・bizOpen/bizClose(開場日固定・
235
+ 半日休の引け)・実体相対のクロス tz 読み(F89)・同時刻対=連続営業と和の右端・深夜セッション
236
+ (F85)・交互性違反のデータ相対エラー・対宣言/予約名/未宣言の静的エラー・with 継承込みの対判定・
237
+ covering 外の「落ちて註釈」・営業時間内の毎正時(06 §6.3 と同じ期待値——正準は isOpen 一語)。
238
+ - `test/rebase.test.ts` — 日付ラベル保存の再錨(ADR-40)。共通営業日の正準例(東京×NY・手計算固定)・
239
+ snapTo との対比(系統的 1 日ずれ)・恒等/往復恒等・DST 切替日と真夜中スキップ日(チリ)への
240
+ 再錨・存在しない日付(Pacific/Apia 2011-12-30)・入力整列違反 3 態・to: の統治・註釈輸送・
241
+ 免除系の tz 名検査(within/ordinalIn/値射影/選択子+rebase 後は通る側・snapTo の除外)。
242
+ - `test/instance-reference.test.ts` — 窓インスタンス参照(ADR-42)。F9 の正準例 3 種
243
+ (`marineDay \ year(2020)`・`month(5) & year(2026)`・segmentBy 由来の `kyuMonth("五月")`)・
244
+ 定義的等式との外延一致・点引数射影の不変・修飾適用形 `Gregorian.year(2020)`(Fiscal 下で暦年・
245
+ 結合子被演算子・射影面)・全マッチの和(`lunarMonth25(6)` が閏六月を含む)・空窓/ゼロマッチ=空・
246
+ 輸送行の回帰(マーカー覆域の先で「落ちて註釈」=F94)・静的検査群 (a)〜(g) 全種・値式位置の
247
+ 型エラー・F96 回帰(rephase のラベル保存=Fiscal.year 同時付与と等価)。
248
+ - `test/lexical-limits.test.ts` — リテラルの締め(ADR-43)。非実在日付の字句エラー(閏年規則込み)・
249
+ 固定オフセット tz の厳格一意形・時点の裸の値束縛(F97)の挙動固定。
250
+ - `test/continuation.test.ts` — 文の区切りと複数行継続(ADR-44)。行頭/行末の結合子継続・premise
251
+ ブロック内の複数行右辺・「文頭の結合子は引き続き構文エラー」の退行なし。
252
+ - `test/cli.test.ts` — CLI サブコマンド。list/next・`--json` の CliReport(無損失直列化・points の
253
+ 市民日開始一致)・旧形式互換の黄金出力・next の倍々探索窓と確定再評価・被覆の切れ目をまたぐ答えへの
254
+ 註釈併走・終了コード契約(0/1/2)・`--lang en`(枠組み英語化・註釈は日本語のまま・USAGE の言語
255
+ 選択・不正値拒否)をサブプロセス実走で検査。
256
+ - `test/doc-consistency.test.ts` — 文書の整合性(機械検査)。ADR 範囲表記 vs 実ファイル数・改名済み
257
+ 旧名の残存・仮称印・stdlib の .kairos↔解説 md の label: 同期。
258
+ - `test/doctest.test.ts` — [`../reference/`](../reference/) と [`../stdlib/`](../stdlib/) の実行例
259
+ (` ```kairos ` フェンスの `# eval:`/`#=>` 規約)を全件実行して照合。ドキュメントの例が仕様・実装と
260
+ ずれたらここで割れる。
package/dist/ast.d.ts ADDED
@@ -0,0 +1,142 @@
1
+ import type { DateVal, WidthVal } from './lexer.ts';
2
+ export type Expr = {
3
+ t: 'name';
4
+ name: string;
5
+ } | {
6
+ t: 'qualified';
7
+ ns: string;
8
+ name: string;
9
+ } | {
10
+ t: 'num';
11
+ v: number;
12
+ } | {
13
+ t: 'date';
14
+ v: DateVal;
15
+ } | {
16
+ t: 'time';
17
+ tod: number;
18
+ } | {
19
+ t: 'width';
20
+ v: WidthVal;
21
+ } | {
22
+ t: 'str';
23
+ v: string;
24
+ } | {
25
+ t: 'list';
26
+ elems: ListElem[];
27
+ covering?: CoveringRange[];
28
+ labels?: Expr;
29
+ } | {
30
+ t: 'cycleLabels';
31
+ list: Expr;
32
+ anchor: Expr;
33
+ } | {
34
+ t: 'lambda';
35
+ params: string[];
36
+ body: Expr;
37
+ } | {
38
+ t: 'call';
39
+ callee: Expr;
40
+ args: Arg[];
41
+ } | {
42
+ t: 'index';
43
+ target: Expr;
44
+ index: Expr;
45
+ } | {
46
+ t: 'pipe';
47
+ head: Expr;
48
+ stages: Stage[];
49
+ } | {
50
+ t: 'combine';
51
+ op: '|' | '&' | '\\';
52
+ l: Expr;
53
+ r: Expr;
54
+ } | {
55
+ t: 'bin';
56
+ op: string;
57
+ l: Expr;
58
+ r: Expr;
59
+ } | {
60
+ t: 'not';
61
+ e: Expr;
62
+ } | {
63
+ t: 'neg';
64
+ e: Expr;
65
+ } | {
66
+ t: 'ternary';
67
+ c: Expr;
68
+ a: Expr;
69
+ b: Expr;
70
+ } | {
71
+ t: 'gen';
72
+ operand: Expr;
73
+ word: 'grid' | 'span' | 'split' | 'cycle';
74
+ arg: Expr;
75
+ named: NamedArgs;
76
+ };
77
+ export type ListElem = Expr | {
78
+ t: 'range';
79
+ a: Expr;
80
+ b: Expr;
81
+ };
82
+ /** covering-range(ADR-37 判断 9): 端の省略=開端(完結主張)。".." 単独=全域完結 */
83
+ export type CoveringRange = {
84
+ a: Expr | null;
85
+ b: Expr | null;
86
+ };
87
+ export interface Stage {
88
+ name: string;
89
+ ns?: string;
90
+ args: Arg[];
91
+ }
92
+ export type Arg = {
93
+ name?: string;
94
+ value: Expr;
95
+ };
96
+ export type NamedArgs = Record<string, Expr>;
97
+ export type Statement = {
98
+ t: 'premiseDef';
99
+ name: string;
100
+ block?: PremiseBlock;
101
+ expr?: PremiseExpr;
102
+ } | {
103
+ t: 'preamble';
104
+ form: 'light' | 'inline';
105
+ name?: string;
106
+ members: Member[];
107
+ block?: Statement[];
108
+ } | {
109
+ t: 'binding';
110
+ name: string;
111
+ params: Param[];
112
+ rhs: Expr;
113
+ covering?: CoveringRange[];
114
+ } | {
115
+ t: 'streamExpr';
116
+ expr: Expr;
117
+ };
118
+ export interface PremiseExpr {
119
+ base: string;
120
+ withBlock?: PremiseBlock;
121
+ stages: Stage[];
122
+ }
123
+ export interface PremiseBlock {
124
+ members: Member[];
125
+ bindings: {
126
+ name: string;
127
+ params: Param[];
128
+ rhs: Expr;
129
+ covering?: CoveringRange[];
130
+ }[];
131
+ }
132
+ export interface Member {
133
+ key: string;
134
+ value: string | Expr;
135
+ }
136
+ export type Param = {
137
+ name: string;
138
+ key?: string;
139
+ };
140
+ export interface Program {
141
+ statements: Statement[];
142
+ }
package/dist/ast.js ADDED
@@ -0,0 +1 @@
1
+ export {};