fix(ruby-generator): v1 でリスト操作を list() ラッパー記法で出力する (#839)#842
Merged
Conversation
…rray syntax
v1 generated plain array syntax ($name[N], 0-indexed) for all list element
and indexed operations, but the v1 Ruby->Blocks converter rejects array
syntax. Round-tripping a v1 program (e.g. the koshien AI list read
list("$最短経路")[2]) produced $最短経路[1], which fails to re-convert in v1.
Make data-list.js (and data_listcontents) version-aware: v1 emits the
list("$name") wrapper with 1-indexed access; v2 keeps $name[0-indexed].
Covers push/insert/delete_at/replace/item/index/length/include?/clear/empty?.
Aligns with the documented v1 spec (smalruby-language-spec-v1-diff).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
🤖 autopilot status
Linked issue #839. Maintained by autopilot (single writer); do not edit. |
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/topic/autopilot-839/ |
Author
🤖 autopilot 敵対的レビュー完了別の批判的レビュアーとして差分を精査しました。修正が必要な欠陥は見つかりませんでした。 人間レビューへ進めます。 検証した観点(すべて OK)
所見(任意・ブロッカーではない)
|
02b512c to
f51b2e1
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ruby v1 の生成コードが、リスト要素の読み出しや添字操作を 配列記法
$名前[N](0 始まり) で出力していた。v1 の Ruby→Blocks コンバータは配列記法を拒否するため、Ruby タブ ⇄ コードタブのラウンドトリップが壊れていた(Epic #738 の DoD で発覚)。例: v1 koshien AI でリスト要素を読むと
koshien.move_to($最短経路[1])が生成され、再変換時に「配列の書き方はルビーバージョン2でのみ使えます」エラーになる。本 PR でジェネレータをバージョン分岐させ、v1 は
list("$名前")ラッパー記法(1 始まり)、v2 は従来どおり$名前[0 始まり]を出力するようにした。これはdocs/smalruby-language-spec-v1-diff.ja.mdに既に記載されている v1 仕様(list("@items")[1])への準拠でもある。Changes Made
src/lib/ruby-generator/data-list.js:renderList()/getVersionedIndex()ヘルパーを追加し、全リスト操作をバージョン分岐:data_addtolist(push)/data_insertatlist(insert・last・random)/data_deleteoflist(delete_at・last・random)/data_deletealloflist(clear)/data_replaceitemoflist([i]=)/data_itemoflist([i])/data_itemnumoflist(index)/data_lengthoflist(length・empty?)/data_listcontainsitem(include?)getListIndex)。src/lib/ruby-generator/data.js:data_listcontents(裸のリスト参照)も v1 でlist("$名前")を出力。Test Coverage
test/unit/lib/ruby-generator/data.test.js: 既存のリスト系テストを v2(配列記法)に明示固定し、新規 v1list()記法 describe を追加。test/unit/lib/ruby-roundtrip/extension_koshien_v2.test.js: 本 Issue の再現 — v1 koshienkoshien.move_to(list("$最短経路")[2])のラウンドトリップを追加。test/unit/lib/ruby-roundtrip/variables.test.js/book-compat.test.js/while-and-conditions.test.js: バグを記録していた期待値(配列記法・#363TODO 含む)を真のラウンドトリップ(list(...)保持)へ修正。test/unit/helpers/ruby-roundtrip-helper.js: ジェネレータのバージョンをコンバータと既定で揃える(本番と同じく単一バージョン設定。配列記法ジェネレータが偶然バージョン非依存だったために隠れていた v2 テストの取りこぼしを是正)。ローカル:
ruby-generator/+ruby-to-blocks-converter/全ユニット(1764 件)、ruby-roundtrip/全(252 件)green。lint / prettier clean。Acceptance Criteria
list("$名前")[1始まりindex]で生成される$名前[0始まり])のままtest/unit/lib/ruby-roundtrip/等にユニットテスト追加(v1/v2 双方)Related
Closes #839
Epic #738 / #743(Ruby v2 対応)/ #827 / #363(v1 ジェネレータの list() 記法保持 TODO を解消)
🤖 Generated with Claude Code