feat: convert bare literals to temp variable assignments (#524 Phase1-3)#533
Merged
Conversation
Bare string/number/array literals (e.g. "Jimmy", 42, [1,2,3]) are now auto-assigned to temp variables (_lit_1_, _lit_2_) instead of causing converter errors. A @ruby:literal:type comment marker enables the generator to output just the literal on roundtrip. String: "Jimmy" → data_setvariableto(_lit_1_, "Jimmy") [@ruby:literal:string] Integer: 42 → data_setvariableto(_lit_1_, 42) [@ruby:literal:integer] Float: 3.14 → data_setvariableto(_lit_1_, 3.14) [@ruby:literal:float] Array: [1,2,3] → data_deletealloflist + data_addtolist [@ruby:literal:array] Symbol (:foo) still errors as before (needs .to_s). Note: Array literal roundtrip needs further work (TODO). Refs #524 (Phase 1 #3) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feat/tryruby-bare-literals/ |
Re-run _linkBlocks after converting bare literals to temp variable
assignments so they connect to the next block via next pointer.
Before: bare literal and say blocks were separate top-level blocks
After: bare literal block connects to say block (same chain)
Add roundtrip test for "hello" followed by say("hello").
Refs #524
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… chains Replace naive _linkBlocks re-run with targeted linking: - Converted literal blocks link to each other (array items) - Converted literal links to the next existing block only if it was directly preceded by a converted literal (convertedPrev flag) - Existing block chains are never modified Update index.test.js: bare literals (1, "Hello!") no longer error; add separate test for accepted bare literals. Refs #524 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert bare Primitive literals to temp variable assignments in
_processStatement (core.js), not just at the top level. This
enables code like:
when_flag_clicked do
"hello"
say("hello", 2)
end
Add roundtrip test for bare literal inside when_flag_clicked.
Refs #524
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bare integers and strings are now auto-converted to temp variables instead of erroring. Update test expectations accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 18, 2026
…bare-literals feat: convert bare literals to temp variable assignments (#524 Phase1-3)
9 tasks
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
裸のリテラル(
"Jimmy",42,[1,2,3])を一時変数代入に変換してエラーを回避。@ruby:literal:typeコメントマーカーでラウンドトリップを実現。"Jimmy"→_lit_1_ = "Jimmy"→ ジェネレーターで"Jimmy"に復元42→_lit_1_ = 42→42に復元[1,2,3]→ リストブロック → 配列リテラルのラウンドトリップは TODOTest Coverage
Refs #524 (Phase 1 #3)