Files
hakorune/CLAUDE.md
Moe Charm 50fc4ca1ce 🎁 feat: pack構文革命完全達成 - Box哲学の具現化
【実装内容】
- packキーワード追加: TokenType::PACK, "pack" mapping
- パーサー対応: init同様の特別扱い + from Parent.pack()
- インタープリター対応: pack > init > Box名順優先選択
- デリゲーション統合: from Parent.pack()で親packを呼び出し
- テスト完備: test_pack_syntax.nyash包括テスト

【革命的効果】
- Box哲学具現化: 「箱に詰める」でコードを書くたび哲学体験
- 他言語差別化: new/init超越のNyash独自アイデンティティ
- 直感的UX: Gemini・ChatGPT両先生一致推薦の最適命名
- メンタルモデル統一: 全Boxで1つのpack動詞に収束
- 拡張基盤: try_pack, from_*パターンへの発展準備完了

🎉 Everything is Box - Now Everything is Packed\!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 09:40:24 +09:00

8.9 KiB
Raw Blame History

Nyash開発ガイド for Claude

Nyashプログラミング言語開発に必要な情報をまとめたクイックリファレンス。

🚀 クイックスタート

🐧 Linux/WSL版

# ビルドと実行
cargo build --release
./target/release/nyash program.nyash

🪟 Windows版 (NEW!)

# クロスコンパイルでWindows実行ファイル生成
cargo install cargo-xwin
cargo xwin build --target x86_64-pc-windows-msvc --release

# 生成された実行ファイル (916KB)
target/x86_64-pc-windows-msvc/release/nyash.exe

🌐 WebAssembly版

# ブラウザープレイグラウンド
cd projects/nyash-wasm
./build.sh
# nyash_playground.html をブラウザーで開く

📚 ドキュメント構造

🎯 よく使う情報

📊 最新開発状況

📖 詳細リファレンス

🎮 実用例・アプリ

  • 実用例 - サンプルコード・パターン集
  • 実装済みアプリ: サイコロRPG・統計計算・LISPインタープリター

重要な設計原則

🏗️ Everything is Box

  • すべての値がBoxStringBox, IntegerBox, BoolBox等
  • ユーザー定義Box: box ClassName { init { field1, field2 } }

🌟 完全明示デリゲーション2025-08-11革命

// デリゲーション構文
box Child from Parent {  // from構文でデリゲーション
    init(args) {  // コンストラクタは「init」に統一
        from Parent.init(args)  // 親の初期化
    }
    
    override method() {  // 明示的オーバーライド必須
        from Parent.method()  // 親メソッド呼び出し
    }
}

🔄 統一ループ構文

// ✅ 唯一の正しい形式
loop(condition) { }

// ❌ 削除済み構文
while condition { }  // 使用不可
loop() { }          // 使用不可

🎁 pack構文 - Box哲学の具現化2025-08-11実装

// 🎁 「箱に詰める」直感的コンストラクタ
box User {
    init { name, email }
    
    pack(userName, userEmail) {  // ← Box哲学を体現
        me.name = userName
        me.email = userEmail
    }
}

// 🔄 デリゲーションでのpack
box AdminUser from User {
    init { permissions }
    
    pack(adminName, adminEmail, perms) {
        from User.pack(adminName, adminEmail)  // 親のpackを呼び出し
        me.permissions = perms
    }
}

// ✅ 優先順位: pack > init > Box名形式
local user = new User("Alice", "alice@example.com")  // packが使われる

🎯 正統派Nyashスタイル2025-08-09実装

// 🚀 Static Box Main パターン - エントリーポイントの統一スタイル
static box Main {
    init { console, result }  // フィールド宣言
    
    main() {
        // ここから始まる!他の言語と同じエントリーポイント
        me.console = new ConsoleBox()
        me.console.log("🎉 Everything is Box!")
        
        // local変数も使用可能
        local temp
        temp = 42
        me.result = temp
        
        return "Revolution completed!"
    }
}

📝 変数宣言厳密化システム2025-08-09実装

// 🔥 すべての変数は明示宣言必須!(メモリ安全性・非同期安全性保証)

// ✅ static box内のフィールド
static box Calculator {
    init { result, memory }  // 明示宣言
    
    calculate() {
        me.result = 42  // ✅ フィールドアクセス
        
        local temp     // ✅ local変数宣言
        temp = me.result * 2
    }
}

// ✅ static関数内の所有権移転
static function Factory.create() {
    outbox product  // 呼び出し側に所有権移転
    product = new Item()
    return product
}

// ❌ 未宣言変数への代入はエラー
x = 42  // Runtime Error: 未宣言変数 + 修正提案

実装済み演算子Production Ready

// 論理演算子(完全実装)
not condition    // NOT演算子
a and b         // AND演算子  
a or b          // OR演算子

// 算術演算子
a / b           // 除算(ゼロ除算エラー対応済み)
a + b, a - b, a * b  // 加算・減算・乗算

⚠️ 重要な注意点

// ✅ 正しい書き方
init { field1, field2 }  // カンマ必須CPU暴走防止

// ❌ 間違い
init { field1 field2 }   // カンマなし→CPU暴走

🎨 GUI開発NEW!

EguiBox - GUIアプリケーション開発

// EguiBoxでGUIアプリ作成
local app
app = new EguiBox()
app.setTitle("Nyash GUI App") 
app.setSize(800, 600)

// 注意: 現在メインスレッド制約により
// app.run() は特別な実行コンテキストが必要

実装状況: 基本実装完了、GUI実行コンテキスト対応中

🔧 開発サポート

🤖 AI相談

# Gemini CLIで相談
gemini -p "Nyashの実装で困っています..."

🧪 テスト実行

# 基本機能テスト
cargo test

# 演算子統合テスト
./target/debug/nyash test_comprehensive_operators.nyash

# 実用アプリテスト
./target/debug/nyash app_dice_rpg.nyash

🐛 デバッグ

パーサー無限ループ対策NEW! 2025-08-09

# 🔥 デバッグ燃料でパーサー制御
./target/release/nyash --debug-fuel 1000 program.nyash      # 1000回制限
./target/release/nyash --debug-fuel unlimited program.nyash  # 無制限
./target/release/nyash program.nyash                        # デフォルト10万回

# パーサー無限ループが検出されると自動停止+詳細情報表示
🚨 PARSER INFINITE LOOP DETECTED at method call argument parsing
🔍 Current token: IDENTIFIER("from") at line 17
🔍 Parser position: 45/128

対応状況: must_advance!マクロでパーサー制御完全実装済み
効果: 予約語"from"など問題のあるトークンも安全にエラー検出

アプリケーション デバッグ

// DebugBox活用
DEBUG = new DebugBox()
DEBUG.startTracking()
DEBUG.trackBox(myObject, "説明")
print(DEBUG.memoryReport())

📚 ドキュメント再編成戦略

🎯 現在の課題

  • CLAUDE.md肥大化 (500行) - 必要情報の検索困難
  • 情報分散 - 実装状況がCLAUDE.md/current_task/docsに分散
  • 参照関係不明確 - ファイル間の相互リンク不足

🚀 新構造プラン

docs/
├── quick-reference/          # よく使う情報(簡潔)
│   ├── syntax-cheatsheet.md     # 構文早見表
│   ├── operators-summary.md     # 演算子一覧
│   └── development-commands.md  # 開発コマンド集
├── status/                   # 最新開発状況
│   ├── current-implementation.md  # 実装状況詳細
│   ├── recent-achievements.md     # 最新成果
│   └── known-issues.md            # 既知の問題
├── reference/                # 完全リファレンス(現存活用)
└── examples/                 # 実用例(現存拡充)

実装優先順位

  1. Phase 1: CLAUDE.md簡潔化500行→150行ハブ
  2. Phase 2: 基本構造作成・情報移行
  3. Phase 3: 相互リンク整備・拡充

🎉 期待効果

  • 検索性: 必要情報への高速アクセス
  • メンテナンス性: 責任分離・局所的更新
  • 拡張性: 新機能追加が容易

📋 詳細: DOCUMENTATION_REORGANIZATION_STRATEGY.md


最終更新: 2025年8月11日 - 🎁 pack構文革命完全達成!

  • Everything is Packed: Gemini・ChatGPT両先生一致推薦のpackコンストラクタ採用
  • Box哲学具現化: 「箱に詰める」直感的メタファーでコードを書くたび哲学体験
  • 完全実装: pack()from Parent.pack()pack>init>Box名順優先選択
  • 革命的UX: 他言語のnew/initを超越、Nyash独自アイデンティティ確立
  • デリゲーション完成: box Child from Parent+pack+override+from統合完了