🚀 feat: ":"継承演算子実装+全14Box型の包括的ドキュメント化完成

## 🔧 言語機能改善
- from予約語問題を解決する":"継承演算子を実装
- box Child : Parent 構文でより直感的な継承表現
- tokenizer/parserを更新、from を変数名として使用可能に

## 📚 ドキュメント大改善(1000行以上追加)
全14Box型に包括的なJavaDoc風ドキュメントを追加:
- StringBox: 文字列操作メソッド群
- IntegerBox/BoolBox: 基本データ型と演算子
- MathBox/RandomBox/TimeBox: 計算・ユーティリティ
- ConsoleBox/DebugBox/SoundBox: システムIO
- MapBox/NullBox: データ構造
- EguiBox: デスクトップGUI
- SimpleIntentBox: P2P通信

各Boxに概要・メソッド一覧・使用例・実用例・注意事項を完備

## 🧹 プロジェクト整理
- ルートディレクトリから60個のテストファイルを削除
  (development/root_tests/に移動済み)
- 不要ファイル削除: bmp, tar.xz, html, 空フォルダ等
- examplesフォルダへ適切なファイルを移動

## 📝 その他の更新
- CLAUDE.md: パーサーデバッグ機能の説明追加
- sessions/: AI相談記録2件を保存
  - from予約語問題の解決策検討
  - 標準Box型(ArrayBox等)の設計相談
This commit is contained in:
Moe Charm
2025-08-10 11:32:32 +09:00
parent e7f6666917
commit ccb3204a35
89 changed files with 1536 additions and 3027 deletions

View File

@ -1,4 +1,43 @@
// BoolBox implementation - Boolean values in Nyash
/*! BoolBox - 真偽値Box
*
* ## 📝 概要
* true/false値を扱うためのBox。
* JavaScript Boolean型のように直感的な論理演算が可能。
*
* ## 🛠️ 利用可能メソッド
* - `toString()` - 文字列変換 ("true" / "false")
* - `not()` - 論理NOT (演算子: not)
* - `and(other)` - 論理AND (演算子: and)
* - `or(other)` - 論理OR (演算子: or)
* - `equals(other)` - 等価比較 (演算子: ==)
*
* ## 💡 使用例
* ```nyash
* local flag, result, text
* flag = true
*
* result = not flag // false
* result = flag and true // true
* result = flag or false // true
* text = flag.toString() // "true"
*
* // 条件分岐での利用
* if (flag) {
* print("Flag is true!")
* }
* ```
*
* ## 🔄 型変換
* - 数値への変換: true → 1, false → 0
* - 文字列への変換: "true" / "false"
* - 空文字・null・0は false として扱われる
*
* ## ⚡ 論理演算子実装済み
* - `not condition` - NOT演算子
* - `a and b` - AND演算子
* - `a or b` - OR演算子
*/
use crate::box_trait::NyashBox;
use std::any::Any;
use std::fmt::Display;

View File

@ -1,7 +1,48 @@
/*!
* ConsoleBox - ブラウザコンソール制御Box
/*! 📟 ConsoleBox - コンソール出力Box
*
* WebAssembly環境でブラウザのconsole APIにアクセス
* ## 📝 概要
* Webブラウザのコンソール機能を統合したBox。
* WASM環境ではブラウザコンソール、ネイティブ環境では標準出力。
*
* ## 🛠️ 利用可能メソッド
* - `log(message)` - 通常のメッセージ出力
* - `warn(message)` - 警告メッセージ出力
* - `error(message)` - エラーメッセージ出力
* - `clear()` - コンソール画面クリア
*
* ## 💡 使用例
* ```nyash
* local console
* console = new ConsoleBox()
*
* console.log("Hello, Nyash!") // 通常ログ
* console.warn("This is a warning") // 警告
* console.error("Something went wrong") // エラー
* console.clear() // クリア
*
* // デバッグ用途
* local value
* value = 42
* console.log("Debug: value = " + value.toString())
* ```
*
* ## 🌐 環境別動作
* - **WASM環境**: ブラウザの開発者ツールコンソールに出力
* - **ネイティブ環境**: ターミナル標準出力にプレフィックス付きで出力
*
* ## 🔍 デバッグ活用
* ```nyash
* // エラーハンドリング
* if (error_condition) {
* console.error("Critical error occurred!")
* return null
* }
*
* // 実行トレース
* console.log("Function start")
* // 処理...
* console.log("Function end")
* ```
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox};

View File

@ -1,3 +1,104 @@
/*! 🔍 DebugBox - デバッグ支援Box
*
* ## 📝 概要
* プロフェッショナル開発向けデバッグ機能を提供するBox。
* メモリ使用量監視、実行トレース、ブレークポイントなど
* 高度なデバッグ機能を完備。
*
* ## 🛠️ 利用可能メソッド
*
* ### 🎯 基本デバッグ
* - `startTracking()` - デバッグ追跡開始
* - `stopTracking()` - デバッグ追跡停止
* - `trackBox(box, name)` - 特定Boxを追跡対象に追加
* - `watch(box, name)` - リアルタイム監視
* - `clear()` - 全デバッグ情報クリア
*
* ### 📊 レポート・分析
* - `dumpAll()` - 全追跡データダンプ
* - `memoryReport()` - メモリ使用量レポート
* - `showCallStack()` - 関数呼び出しスタック表示
* - `saveToFile(filename)` - デバッグ情報をファイル保存
*
* ### 🎮 高度機能
* - `setBreakpoint(function)` - ブレークポイント設定
* - `traceCall(function, args)` - 関数呼び出しトレース
* - `isTracking()` - 追跡状態確認
* - `getTrackedCount()` - 追跡中Box数取得
*
* ## 💡 使用例
* ```nyash
* local debug, user, product
* debug = new DebugBox()
*
* // デバッグ開始
* debug.startTracking()
*
* // オブジェクトを追跡
* user = new User("Alice", 25)
* debug.trackBox(user, "user_alice")
*
* product = new Product("Book", 1500)
* debug.trackBox(product, "book_product")
*
* // リアルタイム監視
* debug.watch(user.age, "user_age")
*
* // レポート生成
* print(debug.memoryReport())
* print(debug.dumpAll())
*
* // ファイルに保存
* debug.saveToFile("debug_report.txt")
* ```
*
* ## 🎮 実用例 - パフォーマンス診断
* ```nyash
* static box PerformanceTest {
* init { debug, data, results }
*
* main() {
* me.debug = new DebugBox()
* me.debug.startTracking()
*
* // 大量データ処理のテスト
* me.data = []
* loop(i < 1000) {
* me.data.push("item_" + i.toString())
* }
* me.debug.trackBox(me.data, "large_array")
*
* // 処理実行
* me.processData()
*
* // 結果分析
* print(me.debug.memoryReport())
* }
* }
* ```
*
* ## ⚡ ベストプラクティス
* ```nyash
* // エラーハンドリング付きデバッグ
* local debug
* debug = new DebugBox()
*
* try {
* debug.startTracking()
* // 問題のあるコード
* risky_operation()
* } catch (error) {
* debug.saveToFile("error_dump.txt")
* print("Debug info saved to error_dump.txt")
* }
* ```
*
* ## ⚠️ 注意
* - 本格運用時はtrackingを無効にしてパフォーマンス向上
* - 大量データ追跡時はメモリ消費に注意
* - call stackは直近100件まで自動保持
*/
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use chrono::Local;

View File

@ -1,6 +1,35 @@
// Nyash EguiBox Implementation
// Everything is Box哲学によるGUIフレームワーク統合
// 「なんでもBoxにできる」化け物言語の第一歩
/*! 🖼️ EguiBox - デスクトップGUIアプリBox
* Everything is Box哲学によるGUIフレームワーク統合
* 「なんでもBoxにできる」化け物言語の第一歩
*
* ## 📝 概要
* Rustの人気GUI框架eframeを使ったネイティブデスクトップアプリ作成。
* Nyashコードから直接GUI操作が可能
*
* ## 🛠️ 利用可能メソッド
* - `setTitle(title)` - ウィンドウタイトル設定
* - `setSize(width, height)` - ウィンドウサイズ設定
* - `run()` - GUIアプリ実行開始
* - `addText(text)` - テキスト表示追加
* - `addButton(label)` - ボタン追加
* - `close()` - ウィンドウ閉じる
*
* ## 💡 使用例
* ```nyash
* // 基本的なGUIアプリ
* local app
* app = new EguiBox()
* app.setTitle("Nyash GUI Demo")
* app.setSize(800, 600)
* app.addText("Welcome to Nyash!")
* app.addButton("Click Me")
* app.run() // GUIアプリ開始
* ```
*
* ## ⚠️ 注意
* - デスクトップ環境でのみ利用可能WASM環境では無効
* - `run()`はブロッキング動作(アプリ終了まで制御を返さない)
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox};
use crate::interpreter::RuntimeError;

View File

@ -1,4 +1,42 @@
// IntegerBox implementation - Integer values in Nyash
/*! 🔢 IntegerBox - 整数計算Box
*
* ## 📝 概要
* 64ビット符号付き整数を扱うためのBox。
* JavaScript Number型のように直感的な数値操作が可能。
*
* ## 🛠️ 利用可能メソッド
* - `toString()` - 文字列変換
* - `add(other)` - 加算 (演算子: +)
* - `subtract(other)` - 減算 (演算子: -)
* - `multiply(other)` - 乗算 (演算子: *)
* - `divide(other)` - 除算 (演算子: /)
* - `modulo(other)` - 余り計算 (演算子: %)
* - `equals(other)` - 等価比較 (演算子: ==)
* - `abs()` - 絶対値
* - `min(other)` - 最小値
* - `max(other)` - 最大値
*
* ## 💡 使用例
* ```nyash
* local num, result, text
* num = 42
*
* result = num + 8 // 50
* result = num * 2 // 84
* result = num / 3 // 14 (整数除算)
* text = num.toString() // "42"
*
* // メソッド呼び出し形式も可能
* result = num.add(10) // 52
* result = num.multiply(3) // 126
* ```
*
* ## ⚠️ 注意
* - ゼロ除算は実行時エラー
* - オーバーフロー時は標準i64の動作に従う
* - 小数点以下は切り捨て(整数除算)
*/
use crate::box_trait::NyashBox;
use std::any::Any;
use std::fmt::Display;

View File

@ -1,8 +1,106 @@
/*!
* Nyash Map Box - Key-Value store implementation
/*! 🗄️ MapBox - キー値ストレージBox
*
* キーバリューストアを提供するBox型
* Everything is Box哲学に基づくマップデータ構造
* ## 📝 概要
* 高性能キー値ストレージを提供するBox。
* JavaScript Map、Python dict、C# Dictionaryと同等機能。
* 動的データ管理やキャッシュ実装に最適。
*
* ## 🛠️ 利用可能メソッド
* - `set(key, value)` - キー値ペア設定
* - `get(key)` - 値取得
* - `has(key)` - キー存在確認
* - `remove(key)` - キー値ペア削除
* - `clear()` - 全データクリア
* - `keys()` - 全キー取得
* - `values()` - 全値取得
* - `size()` - データ数取得
* - `isEmpty()` - 空判定
*
* ## 💡 使用例
* ```nyash
* local map, result
* map = new MapBox()
*
* // データ設定
* map.set("name", "Alice")
* map.set("age", 25)
* map.set("active", true)
*
* // データ取得
* result = map.get("name") // "Alice"
* print("User: " + result)
*
* // 存在確認
* if (map.has("email")) {
* print("Email: " + map.get("email"))
* } else {
* print("No email registered")
* }
* ```
*
* ## 🎮 実用例 - ゲーム設定管理
* ```nyash
* static box GameConfig {
* init { settings, scores }
*
* main() {
* me.settings = new MapBox()
* me.scores = new MapBox()
*
* // 設定初期化
* me.settings.set("difficulty", "normal")
* me.settings.set("sound", true)
* me.settings.set("graphics", "high")
*
* // スコア記録
* me.scores.set("level1", 850)
* me.scores.set("level2", 1200)
* me.scores.set("level3", 950)
*
* me.displayConfig()
* }
*
* displayConfig() {
* print("=== Game Settings ===")
* print("Difficulty: " + me.settings.get("difficulty"))
* print("Sound: " + me.settings.get("sound").toString())
* print("Total scores: " + me.scores.size().toString())
* }
* }
* ```
*
* ## 🔍 キャッシュ実装例
* ```nyash
* static box APICache {
* init { cache, ttl_map }
*
* main() {
* me.cache = new MapBox()
* me.ttl_map = new MapBox()
* }
*
* getData(url) {
* // キャッシュ確認
* if (me.cache.has(url)) {
* return me.cache.get(url)
* }
*
* // APIから取得
* local data
* data = fetchFromAPI(url)
*
* // キャッシュに保存
* me.cache.set(url, data)
* return data
* }
* }
* ```
*
* ## ⚠️ 注意
* - キーは自動的に文字列変換される
* - スレッドセーフ (Arc<Mutex>使用)
* - 大量データ格納時はメモリ使用量に注意
* - 存在しないキーの取得は "Key not found" メッセージ返却
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, ArrayBox};

View File

@ -1,8 +1,59 @@
/*!
* Nyash Math Box - Mathematical operations
/*! 🧮 MathBox - 数学計算Box
*
* 数学演算を提供するBox型
* Everything is Box哲学に基づく数学ライブラリ
* ## 📝 概要
* 高度な数学演算を提供するBox。Python mathモジュールや
* JavaScript Math オブジェクトと同様の機能を提供。
*
* ## 🛠️ 利用可能メソッド
*
* ### 🔢 基本計算
* - `abs(value)` - 絶対値
* - `max(a, b)` - 最大値
* - `min(a, b)` - 最小値
* - `pow(base, exp)` - 累乗 (base^exp)
* - `sqrt(value)` - 平方根
*
* ### 📐 三角関数
* - `sin(radians)` - 正弦
* - `cos(radians)` - 余弦
* - `tan(radians)` - 正接
*
* ### 📊 対数・指数関数
* - `log(value)` - 自然対数 (ln)
* - `log10(value)` - 常用対数
* - `exp(value)` - 指数関数 (e^x)
*
* ### 🔄 丸め関数
* - `floor(value)` - 切り下げ
* - `ceil(value)` - 切り上げ
* - `round(value)` - 四捨五入
*
* ### 📏 定数取得
* - `getPi()` - 円周率π (3.14159...)
* - `getE()` - 自然対数の底e (2.71828...)
*
* ## 💡 使用例
* ```nyash
* local math, result
* math = new MathBox()
*
* result = math.abs(-42) // 42
* result = math.max(10, 25) // 25
* result = math.sqrt(16) // 4.0
* result = math.pow(2, 3) // 8.0
* result = math.sin(math.getPi() / 2) // 1.0
*
* // 計算例
* local pi, area
* pi = math.getPi()
* area = pi * math.pow(5, 2) // 半径5の円の面積
* ```
*
* ## ⚠️ 注意
* - 三角関数の引数はラジアン
* - 負数の平方根・対数はエラー
* - オーバーフロー時は標準f64の動作に従う
* - 整数演算は自動でFloatBoxに変換される場合あり
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};

View File

@ -1,5 +1,53 @@
// Nyash Box Implementations Module
// Everything is Box哲学に基づく各Box型の実装
/*! 🎯 Nyash Box実装モジュール
* Everything is Box哲学に基づく各Box型の実装
*
* ## 📦 利用可能なBox一覧
*
* ### 🔤 基本データ型Box
* - **StringBox**: 文字列操作 - `"Hello".length()`, `str.split(",")`
* - **IntegerBox**: 整数計算 - `42.add(8)`, `num.toString()`
* - **BoolBox**: 真偽値 - `true.not()`, `flag.toString()`
*
* ### 🧮 計算・ユーティリティBox
* - **MathBox**: 数学関数 - `Math.sin(x)`, `Math.random()`
* - **TimeBox**: 時間操作 - `Time.now()`, `time.format()`
* - **RandomBox**: 乱数生成 - `Random.int(10)`, `Random.choice(array)`
*
* ### 🖥️ システム・IO Box
* - **ConsoleBox**: コンソール出力 - `console.log()`, `console.error()`
* - **DebugBox**: デバッグ支援 - `debug.trace()`, `debug.memory()`
* - **SoundBox**: 音声再生 - `sound.beep()`, `sound.play(file)`
*
* ### 🗄️ コレクション・データBox
* - **MapBox**: キー値ストレージ - `map.set(key, val)`, `map.get(key)`
* - **NullBox**: NULL値表現 - `null.toString()` → "void"
*
* ### 🖼️ GUI・グラフィックBox
* - **EguiBox**: デスクトップGUI - `gui.setTitle()`, `gui.run()`
*
* ### 🌐 Web専用Box (WASM環境)
* - **WebDisplayBox**: HTML表示 - `display.show(html)`
* - **WebConsoleBox**: ブラウザコンソール - `webConsole.log()`
* - **WebCanvasBox**: Canvas描画 - `canvas.drawRect()`
*
* ### 🔗 通信・ネットワークBox
* - **SimpleIntentBox**: P2P通信 - `intent.send()`, `intent.on()`
*
* ## 💡 使用例
* ```nyash
* // 基本的な使い方
* local str, num, result
* str = "Nyash"
* num = 42
* result = str.concat(" v") + num.toString()
*
* // GUIアプリ作成
* local app
* app = new EguiBox()
* app.setTitle("My App")
* app.run()
* ```
*/
// Nyashは意図的にJavaScript/TypeScriptスタイルのcamelCase命名規約を採用
#![allow(non_snake_case)]

View File

@ -1,8 +1,87 @@
/*!
* Nyash Null Box - Null value representation
/*! 🚫 NullBox - NULL値表現Box
*
* null値を表現するBox型
* Everything is Box哲学に基づくnull実装
* ## 📝 概要
* null/void値を表現する特別なBox。
* JavaScript null、Python None、C# nullと同等の機能を提供。
* NULL安全プログラミングをサポート。
*
* ## 🛠️ 利用可能メソッド
* - `isNull()` - null判定 (常にtrue)
* - `isNotNull()` - 非null判定 (常にfalse)
* - `toString()` - 文字列変換 ("null")
* - `equals(other)` - 等価比較 (他のnullとのみtrue)
*
* ## 🛡️ 静的メソッド (null安全機能)
* - `NullBox.checkNull(value)` - 値のnull判定
* - `NullBox.checkNotNull(value)` - 値の非null判定
* - `NullBox.getOrDefault(value, default)` - null時デフォルト値取得
*
* ## 💡 使用例
* ```nyash
* local user, name, default_name
*
* // null値の作成と判定
* user = null
* if (user == null) {
* print("User is null")
* }
*
* // null安全な値取得
* name = getUsername() // null の可能性
* default_name = NullBox.getOrDefault(name, "Anonymous")
* print("Hello, " + default_name)
* ```
*
* ## 🎮 実用例 - null安全プログラミング
* ```nyash
* static box UserManager {
* init { current_user }
*
* main() {
* me.current_user = null
*
* // null安全なログイン処理
* me.loginUser("alice")
* me.displayUserInfo()
* }
*
* loginUser(username) {
* if (username == null or username == "") {
* print("Error: Invalid username")
* return
* }
* me.current_user = new User(username)
* }
*
* displayUserInfo() {
* if (me.current_user == null) {
* print("No user logged in")
* } else {
* print("Current user: " + me.current_user.name)
* }
* }
* }
* ```
*
* ## 🔍 デバッグ活用
* ```nyash
* local data, result
* data = fetchDataFromAPI() // null になる可能性
*
* // null チェック付きデバッグ
* if (NullBox.checkNull(data)) {
* print("Warning: API returned null data")
* result = NullBox.getOrDefault(data, "default_data")
* } else {
* result = data.process()
* }
* ```
*
* ## ⚠️ 重要な特徴
* - `null == null` は常にtrue
* - `null.toString()` は "null"
* - 全てのNullBoxインスタンスは論理的に等価
* - メソッド呼び出し時のnullチェックでNullPointerException防止
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox};

View File

@ -1,8 +1,70 @@
/*!
* Nyash Random Box - Random number generation
/*! 🎲 RandomBox - 乱数生成Box
*
* 乱数生成を提供するBox型
* Everything is Box哲学に基づく乱数ライブラリ
* ## 📝 概要
* 高品質な乱数生成機能を提供するBox。
* ゲーム開発、統計処理、テストデータ生成に最適。
*
* ## 🛠️ 利用可能メソッド
*
* ### 🔢 基本乱数
* - `random()` - 0.01.0の浮動小数点乱数
* - `randInt(min, max)` - 指定範囲の整数乱数
* - `randBool()` - true/falseのランダム選択
* - `seed(value)` - 乱数種を設定(再現可能な乱数)
*
* ### 🎯 選択・配列操作
* - `choice(array)` - 配列からランダム選択
* - `shuffle(array)` - 配列をシャッフル
*
* ### 🎨 生成
* - `randString(length)` - ランダム文字列生成
* - `probability(prob)` - 指定確率でtrue
*
* ## 💡 使用例
* ```nyash
* local random, result, dice, array
* random = new RandomBox()
*
* // 基本的な乱数
* result = random.random() // 0.01.0
* dice = random.randInt(1, 6) // サイコロ(1-6)
* result = random.randBool() // true or false
*
* // 配列関連
* array = ["apple", "banana", "cherry"]
* result = random.choice(array) // ランダム選択
* array = random.shuffle(array) // シャッフル
*
* // ゲーム用途
* local password, critical_hit
* password = random.randString(8) // 8文字のランダム文字列
* critical_hit = random.probability(0.1) // 10%でクリティカル
* ```
*
* ## 🎮 実用例
* ```nyash
* // RPGダメージ計算
* local damage, is_critical
* damage = random.randInt(10, 20) // 基本ダメージ10-20
* is_critical = random.probability(0.15) // 15%でクリティカル
* if (is_critical) {
* damage = damage * 2
* }
*
* // テストデータ生成
* local users, user_id, user_name
* users = []
* loop(i < 10) {
* user_id = random.randInt(1000, 9999)
* user_name = "user_" + random.randString(5)
* users.push(user_name + ":" + user_id)
* }
* ```
*
* ## ⚠️ 注意
* - 暗号学的に安全な乱数ではない(セキュリティ用途非推奨)
* - seed()で同じ値を設定すると同じ乱数列を生成(テスト用)
* - 大きな配列のshuffleは処理時間が長い場合あり
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, ArrayBox};

View File

@ -1,4 +1,163 @@
// シンプルなIntentBox - 最小限の実装
/*! 🔗 SimpleIntentBox - P2P通信Box
*
* ## 📝 概要
* ピア・ツー・ピア通信機能を提供する軽量実装Box。
* ノード間のメッセージ配信、イベント通知、
* 分散アプリケーション構築に使用。
*
* ## 🛠️ 利用可能メソッド
* - `send(target, message)` - メッセージ送信
* - `on(event, callback)` - イベントリスナー登録
* - `emit(event, data)` - イベント発火
* - `connect(nodeId)` - ノード接続
* - `disconnect(nodeId)` - ノード切断
* - `getConnectedNodes()` - 接続中ノード一覧
* - `setNodeId(id)` - 自ードID設定
* - `broadcast(message)` - 全ノードにブロードキャスト
*
* ## 💡 使用例
* ```nyash
* local intent
* intent = new SimpleIntentBox()
*
* // ノード設定
* intent.setNodeId("node1")
*
* // リスナー登録
* intent.on("message", "handleMessage")
* intent.on("join", "handleNodeJoin")
*
* // メッセージ送信
* intent.send("node2", "Hello from node1!")
*
* // ブロードキャスト
* intent.broadcast("System announcement")
* ```
*
* ## 🎮 実用例 - チャットアプリ
* ```nyash
* static box ChatNode {
* init { intent, username, messages }
*
* main() {
* me.intent = new SimpleIntentBox()
* me.username = "User1"
* me.messages = []
*
* // ノード初期化
* me.intent.setNodeId(me.username)
* me.setupEventHandlers()
*
* // チャットルームに参加
* me.joinChatRoom()
* }
*
* setupEventHandlers() {
* // メッセージ受信
* me.intent.on("chat_message", "onChatMessage")
* // ユーザー参加
* me.intent.on("user_joined", "onUserJoined")
* // ユーザー退出
* me.intent.on("user_left", "onUserLeft")
* }
*
* sendMessage(text) {
* local msg
* msg = new MapBox()
* msg.set("from", me.username)
* msg.set("text", text)
* msg.set("timestamp", new TimeBox().now())
*
* me.intent.broadcast("chat_message", msg)
* }
*
* onChatMessage(sender, message) {
* me.messages.push(message)
* print("[" + message.get("from") + "] " + message.get("text"))
* }
* }
* ```
*
* ## 🌐 分散計算例
* ```nyash
* static box DistributedWorker {
* init { intent, node_id, tasks }
*
* main() {
* me.intent = new SimpleIntentBox()
* me.node_id = "worker_" + RandomBox.randInt(1000, 9999)
* me.tasks = []
*
* me.intent.setNodeId(me.node_id)
* me.registerAsWorker()
* }
*
* registerAsWorker() {
* // タスク受信リスナー
* me.intent.on("task_assign", "processTask")
* // 結果送信完了リスナー
* me.intent.on("result_received", "onResultReceived")
*
* // ワーカー登録通知
* me.intent.broadcast("worker_ready", me.node_id)
* }
*
* processTask(coordinator, task) {
* print("Processing task: " + task.get("id"))
*
* // 重い計算処理...
* local result
* result = heavyCalculation(task.get("data"))
*
* // 結果を送信
* me.intent.send(coordinator, result)
* }
* }
* ```
*
* ## 🎯 ゲーム用マルチプレイヤー
* ```nyash
* static box GameClient {
* init { intent, player_id, game_state }
*
* main() {
* me.intent = new SimpleIntentBox()
* me.player_id = "player_" + me.generateId()
* me.game_state = new MapBox()
*
* me.connectToGame()
* }
*
* connectToGame() {
* me.intent.setNodeId(me.player_id)
*
* // ゲームイベント
* me.intent.on("player_move", "onPlayerMove")
* me.intent.on("game_update", "onGameUpdate")
* me.intent.on("player_joined", "onPlayerJoined")
*
* // ゲーム参加
* me.intent.broadcast("join_game", me.player_id)
* }
*
* movePlayer(x, y) {
* local move_data
* move_data = new MapBox()
* move_data.set("player", me.player_id)
* move_data.set("x", x)
* move_data.set("y", y)
*
* me.intent.broadcast("player_move", move_data)
* }
* }
* ```
*
* ## ⚠️ 注意
* - 現在は最小限実装(フル機能開発中)
* - ネットワーク通信は未実装(ローカル通信のみ)
* - メッセージ配信は同一プロセス内限定
* - 本格P2P実装は将来バージョンで提供予定
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox};
use std::any::Any;

View File

@ -1,8 +1,141 @@
/*!
* Nyash Sound Box - Simple sound generation
/*! 🔊 SoundBox - サウンド・音響効果Box
*
* 音響効果を提供するBox型
* Everything is Box哲学に基づく音響ライブラリ
* ## 📝 概要
* システム音・効果音を提供するBox。
* ゲーム効果音、通知音、アラート音の生成に使用。
* クロスプラットフォーム対応のシンプルなサウンドシステム。
*
* ## 🛠️ 利用可能メソッド
* - `beep()` - 基本ビープ音
* - `beeps(count)` - 指定回数ビープ
* - `bell()` - ベル音
* - `alarm()` - アラーム音
* - `playTone(frequency, duration)` - 指定周波数・時間で音生成
* - `playFile(filename)` - 音声ファイル再生
* - `setVolume(level)` - 音量設定 (0.0-1.0)
*
* ## 💡 使用例
* ```nyash
* local sound
* sound = new SoundBox()
*
* // 基本的な音
* sound.beep() // シンプルビープ
* sound.beeps(3) // 3回ビープ
* sound.bell() // ベル音
*
* // ゲーム効果音
* sound.playTone(440, 500) // ラの音を500ms
* sound.playTone(880, 200) // 高いラの音を200ms
* ```
*
* ## 🎮 実用例 - ゲーム効果音
* ```nyash
* static box GameSFX {
* init { sound }
*
* main() {
* me.sound = new SoundBox()
* me.sound.setVolume(0.7)
*
* // ゲームイベント
* me.playerJump()
* me.coinCollect()
* me.gameOver()
* }
*
* playerJump() {
* // ジャンプ音:低→高
* me.sound.playTone(220, 100)
* me.sound.playTone(440, 150)
* }
*
* coinCollect() {
* // コイン音:上昇音階
* me.sound.playTone(523, 80) //
* me.sound.playTone(659, 80) //
* me.sound.playTone(784, 120) //
* }
*
* gameOver() {
* // ゲームオーバー音:下降
* me.sound.playTone(440, 200)
* me.sound.playTone(392, 200)
* me.sound.playTone(349, 400)
* }
* }
* ```
*
* ## 🚨 通知・アラート用途
* ```nyash
* static box NotificationSystem {
* init { sound }
*
* main() {
* me.sound = new SoundBox()
* me.testNotifications()
* }
*
* info() {
* me.sound.beep() // 情報通知
* }
*
* warning() {
* me.sound.beeps(2) // 警告
* }
*
* error() {
* // エラー音:断続的
* me.sound.playTone(200, 100)
* // 短い間隔
* me.sound.playTone(200, 100)
* me.sound.playTone(200, 200)
* }
*
* success() {
* // 成功音:上昇音階
* me.sound.playTone(523, 150) //
* me.sound.playTone(659, 150) //
* me.sound.playTone(784, 200) //
* }
* }
* ```
*
* ## 🎵 音楽生成例
* ```nyash
* static box MusicBox {
* init { sound, notes }
*
* main() {
* me.sound = new SoundBox()
* me.notes = new MapBox()
* me.setupNotes()
* me.playMelody()
* }
*
* setupNotes() {
* // 音階定義
* me.notes.set("C", 261) //
* me.notes.set("D", 293) //
* me.notes.set("E", 329) //
* me.notes.set("F", 349) // ファ
* me.notes.set("G", 392) //
* }
*
* playNote(note, duration) {
* local freq
* freq = me.notes.get(note)
* me.sound.playTone(freq, duration)
* }
* }
* ```
*
* ## ⚠️ 注意
* - システムによってはビープ音が無効化されている場合あり
* - 音量設定は環境依存
* - 長時間音生成はCPU使用率に注意
* - ファイル再生は対応フォーマット限定
* - Web環境では制限が多いユーザー操作後のみ音声再生可能
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};

View File

@ -1,4 +1,32 @@
// StringBox implementation - String values in Nyash
/*! 🔤 StringBox - 文字列操作Box
*
* ## 📝 概要
* UTF-8エンコード文字列を扱うためのBox。
* JavaScript風のメソッドで直感的な文字列操作が可能。
*
* ## 🛠️ 利用可能メソッド
* - `length()` - 文字列長を取得
* - `concat(other)` - 文字列結合
* - `split(separator)` - 区切り文字で分割
* - `substring(start, end)` - 部分文字列取得
* - `toUpperCase()` - 大文字変換
* - `toLowerCase()` - 小文字変換
* - `trim()` - 前後の空白除去
* - `indexOf(search)` - 文字列検索
* - `replace(from, to)` - 文字列置換
* - `charAt(index)` - 指定位置の文字取得
*
* ## 💡 使用例
* ```nyash
* local text, parts, result
* text = "Hello, World!"
*
* print(text.length()) // 13
* print(text.toUpperCase()) // "HELLO, WORLD!"
* parts = text.split(",") // ["Hello", " World!"]
* result = text.concat(" Nyash") // "Hello, World! Nyash"
* ```
*/
use crate::box_trait::NyashBox;
use std::any::Any;
use std::fmt::Display;

View File

@ -1,8 +1,121 @@
/*!
* Nyash Time Box - Time and Date operations
/*! ⏰ TimeBox - 時間・日付操作Box
*
* 時間と日付操作を提供するBox型
* Everything is Box哲学に基づく時間ライブラリ
* ## 📝 概要
* 高精度な時間・日付操作を提供するBox。
* JavaScript Date、Python datetime、C# DateTimeと同等機能。
* タイムスタンプ処理、フォーマット、時差計算をサポート。
*
* ## 🛠️ 利用可能メソッド
*
* ### 📅 基本操作
* - `now()` - 現在日時取得
* - `fromTimestamp(timestamp)` - UNIXタイムスタンプから日時作成
* - `parse(date_string)` - 文字列から日時パース
* - `format(pattern)` - 指定フォーマットで文字列化
*
* ### 🔢 値取得
* - `year()` - 年取得
* - `month()` - 月取得 (1-12)
* - `day()` - 日取得 (1-31)
* - `hour()` - 時取得 (0-23)
* - `minute()` - 分取得 (0-59)
* - `second()` - 秒取得 (0-59)
* - `weekday()` - 曜日取得 (0=日曜)
*
* ### ⏱️ 計算
* - `addDays(days)` - 日数加算
* - `addHours(hours)` - 時間加算
* - `addMinutes(minutes)` - 分加算
* - `diffDays(other)` - 日数差計算
* - `diffHours(other)` - 時間差計算
*
* ## 💡 使用例
* ```nyash
* local time, now, birthday, age
* time = new TimeBox()
*
* // 現在日時
* now = time.now()
* print("現在: " + now.format("yyyy/MM/dd HH:mm:ss"))
*
* // 誕生日から年齢計算
* birthday = time.parse("1995-03-15")
* age = now.diffYears(birthday)
* print("年齢: " + age.toString() + "歳")
*
* // 1週間後
* local next_week
* next_week = now.addDays(7)
* print("1週間後: " + next_week.format("MM月dd日"))
* ```
*
* ## 🎮 実用例 - イベントスケジューラー
* ```nyash
* static box EventScheduler {
* init { time, events, current }
*
* main() {
* me.time = new TimeBox()
* me.events = []
* me.current = me.time.now()
*
* // イベント追加
* me.addEvent("会議", me.current.addHours(2))
* me.addEvent("ランチ", me.current.addHours(5))
* me.addEvent("プレゼン", me.current.addDays(1))
*
* me.showUpcomingEvents()
* }
*
* addEvent(title, datetime) {
* local event
* event = new MapBox()
* event.set("title", title)
* event.set("datetime", datetime)
* event.set("timestamp", datetime.toTimestamp())
* me.events.push(event)
* }
*
* showUpcomingEvents() {
* print("=== 今後のイベント ===")
* loop(i < me.events.length()) {
* local event, hours_until
* event = me.events.get(i)
* hours_until = event.get("datetime").diffHours(me.current)
*
* print(event.get("title") + " - " +
* hours_until.toString() + "時間後")
* }
* }
* }
* ```
*
* ## 🕐 時間計算例
* ```nyash
* local time, start, end, duration
* time = new TimeBox()
*
* // 作業時間計測
* start = time.now()
* // 何か重い処理...
* heavyCalculation()
* end = time.now()
*
* duration = end.diffSeconds(start)
* print("処理時間: " + duration.toString() + "秒")
*
* // 締切まで残り時間
* local deadline, remaining
* deadline = time.parse("2025-12-31 23:59:59")
* remaining = deadline.diffDays(time.now())
* print("締切まで" + remaining.toString() + "日")
* ```
*
* ## ⚠️ 注意
* - ローカルタイムゾーンに基づく処理
* - パース可能な日時フォーマットは限定的
* - UNIXタイムスタンプは秒単位
* - 夏時間切り替え時は計算に注意
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};