Skip to content

feat: convert bare literals to temp variable assignments (#524 Phase1-3)#533

Merged
takaokouji merged 5 commits into
developfrom
feat/tryruby-bare-literals
Apr 18, 2026
Merged

feat: convert bare literals to temp variable assignments (#524 Phase1-3)#533
takaokouji merged 5 commits into
developfrom
feat/tryruby-bare-literals

Conversation

@takaokouji
Copy link
Copy Markdown

Summary

裸のリテラル("Jimmy", 42, [1,2,3])を一時変数代入に変換してエラーを回避。@ruby:literal:type コメントマーカーでラウンドトリップを実現。

  • 文字列: "Jimmy"_lit_1_ = "Jimmy" → ジェネレーターで "Jimmy" に復元
  • 整数: 42_lit_1_ = 4242 に復元
  • 配列: [1,2,3] → リストブロック → 配列リテラルのラウンドトリップは TODO

Test Coverage

  • コンバーター: 文字列/整数/浮動小数点/空配列/配列/シンボル(エラー維持) 6テスト
  • ラウンドトリップ: 文字列/整数 2テスト(配列は TODO)

Refs #524 (Phase 1 #3)

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>
@github-actions
Copy link
Copy Markdown

takaokouji and others added 4 commits April 18, 2026 17:59
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>
@takaokouji takaokouji merged commit 7c59dd6 into develop Apr 18, 2026
9 checks passed
@takaokouji takaokouji deleted the feat/tryruby-bare-literals branch April 18, 2026 09:49
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant