🚀 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:
@ -9,6 +9,38 @@ use crate::tokenizer::TokenType;
|
||||
use crate::ast::{ASTNode, BinaryOperator, LiteralValue, UnaryOperator, Span};
|
||||
use super::{NyashParser, ParseError};
|
||||
|
||||
// ===== 🔥 Debug Macros (copied from parent module) =====
|
||||
|
||||
/// Infinite loop detection macro - must be called in every loop that advances tokens
|
||||
/// Prevents parser from hanging due to token consumption bugs
|
||||
/// Uses parser's debug_fuel field for centralized fuel management
|
||||
macro_rules! must_advance {
|
||||
($parser:expr, $fuel:expr, $location:literal) => {
|
||||
// デバッグ燃料がSomeの場合のみ制限チェック
|
||||
if let Some(ref mut limit) = $parser.debug_fuel {
|
||||
if *limit == 0 {
|
||||
eprintln!("🚨 PARSER INFINITE LOOP DETECTED at {}", $location);
|
||||
eprintln!("🔍 Current token: {:?} at line {}", $parser.current_token().token_type, $parser.current_token().line);
|
||||
eprintln!("🔍 Parser position: {}/{}", $parser.current, $parser.tokens.len());
|
||||
return Err(ParseError::InfiniteLoop {
|
||||
location: $location.to_string(),
|
||||
token: $parser.current_token().token_type.clone(),
|
||||
line: $parser.current_token().line,
|
||||
});
|
||||
}
|
||||
*limit -= 1;
|
||||
}
|
||||
// None の場合は無制限なのでチェックしない
|
||||
};
|
||||
}
|
||||
|
||||
/// Initialize debug fuel for loop monitoring
|
||||
macro_rules! debug_fuel {
|
||||
() => {
|
||||
100_000 // Default: 100k iterations should be enough for any reasonable program
|
||||
};
|
||||
}
|
||||
|
||||
impl NyashParser {
|
||||
/// 式をパース (演算子優先順位あり)
|
||||
pub(super) fn parse_expression(&mut self) -> Result<ASTNode, ParseError> {
|
||||
@ -214,6 +246,8 @@ impl NyashParser {
|
||||
let mut arg_count = 0;
|
||||
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "method call argument parsing");
|
||||
|
||||
arguments.push(self.parse_expression()?);
|
||||
arg_count += 1;
|
||||
|
||||
@ -254,6 +288,8 @@ impl NyashParser {
|
||||
let mut arguments = Vec::new();
|
||||
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "function call argument parsing");
|
||||
|
||||
arguments.push(self.parse_expression()?);
|
||||
if self.match_token(&TokenType::COMMA) {
|
||||
self.advance();
|
||||
@ -372,6 +408,8 @@ impl NyashParser {
|
||||
let mut arguments = Vec::new();
|
||||
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "new expression argument parsing");
|
||||
|
||||
arguments.push(self.parse_expression()?);
|
||||
if self.match_token(&TokenType::COMMA) {
|
||||
self.advance();
|
||||
|
||||
Reference in New Issue
Block a user