feat: Ruby の自然な配列構文サポート(0-indexed)#311
Merged
Merged
Conversation
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feature/ruby-array-syntax/ |
Change the Ruby generator to output natural Ruby array syntax instead
of the list("$name") wrapper. List indices are converted from Scratch's
1-indexed to Ruby's 0-indexed. Literal indices are decremented directly;
expression indices generate "expr - 1".
Refs #310
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comment-based pattern detection for clean round-trips: - operator_subtract with @ruby:array:index comment passes through the .index() result without subtracting 1 - getListIndex detects operator_add(x, 1) with @ruby:array:index_offset comment and uses x directly as the 0-indexed value Refs #310 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement converter handlers to recognize Ruby array method calls ($a.push, $a[0], $a.length, etc.) and convert them to Scratch list blocks with proper 0-indexed to 1-indexed conversion. - Add convertToListBlock helper to convert data_variable to data_listcontents - Add adjustIndex helper for 0→1 index conversion with Primitive support - Add << operator handler as alias for push - Update [], length handlers to support array syntax conversion - Gate conversion on version >= 2 to preserve v1 string behavior - Update existing v2 tests: $a.length → data_lengthoflist, $a[0] → data_itemoflist Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Generator: detect clear + push sequence with @ruby:array:literal comment and emit array literal syntax. Suppress push blocks marked with @ruby:array:literal:element. Converter: handle GlobalVariableWriteNode with ArrayNode value, generating data_deletealloflist + data_addtolist blocks with round-trip comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When $a.index("thing") is converted to blocks in version 2,
wrap data_itemnumoflist in operator_subtract(result, 1) with
@ruby:array:index comment for round-trip support.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 15 round-trip tests covering all array operations (push, <<, delete_at, clear, insert, []=, [], index, length, include?, array literals) for both global and instance variables. Fix helper to properly handle stage/sprite variable separation for $ prefix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The generator now always outputs array syntax ($my_list.push instead of
list("$my_list").push). Update existing roundtrip tests to provide
expectedRuby with the new output format.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ruby version 1 only supports list() syntax; array syntax produces an error. Ruby version 2 only supports array syntax; list() produces an error. Added empty? handler for variables in v2 array syntax. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The include? handler in variables.js was creating data_listcontainsitem blocks with type 'value' instead of 'value_boolean', causing _processCondition to reject them in if-conditions with error "condition is not boolean". Fixes #10 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The empty? and include? handlers in variables.js called convertToListBlock which throws in v1 for data_variable receivers. In v1, empty? should fall through to the operators handler, and include? should work directly on the receiver (pre-existing behavior). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
873f515 to
d479302
Compare
Add i18n support for the 3 error messages introduced in this PR using defineMessages/react-intl pattern. Add Japanese translations to ja.js and ja-Hira.js locale files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 15, 2026
…array-syntax feat: Ruby の自然な配列構文サポート(0-indexed)
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 の自然な配列構文でScratchのリストを操作できるようにする。
list("$a")形式を廃止し、$a[0]、$a.push("x")等の 0-indexed 配列構文に統一。Refs #310
Implementation Steps
list("$a")→@a、1-indexed → 0-indexed)$a = [1, 2, 3]サポートindexメソッドの 0-indexed 変換list()のみ、v2は配列構文のみDefinition of Done
$a = [1, 2, 3]→ コードタブ → 正しいブロック