feat(phase12.7): 糖衣構文Phase 12.7-B完了 + 自律型AI開発システム制御機能

🚀 Phase 12.7-B: ChatGPT5糖衣構文(基本実装完了)
- パイプライン演算子(|>)実装
- セーフアクセス(?.)とデフォルト値(??)実装
- sugar gateによる段階的有効化機能
- 糖衣構文テストスイート追加

🤖 自律型AI開発システム改善
- codex-async-notify.sh: タスク制御指示追加
  - "下の箱を積み過ぎないように先に進んでください"
  - "フェーズが終わったと判断したら止まってください"
- プロセス数表示機能の改善(count_running_codex_display)
- 自動停止機能が正常動作(Phase 12.7-C前で停止確認)

📚 ドキュメント更新
- Paper 13: 自律型AI協調開発システムの革新性を文書化
- ANCP可逆マッピング仕様追加
- nyfmt PoC(フォーマッター)計画追加

🧱 箱理論の体現
- 74k行のコードベース(Phase 15で20k行を目指す)
- ANCP適用で最終的に6k行相当を狙う
- 世界最小の実用コンパイラへの道

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-09-05 05:16:21 +09:00
parent c45866073d
commit 19f775c34d
47 changed files with 2171 additions and 163 deletions

View File

@ -22,6 +22,9 @@ mod expressions;
mod statements;
mod declarations;
mod items;
pub mod sugar; // Phase 12.7-B: desugar pass (basic)
pub mod entry_sugar; // helper to parse with sugar level
pub mod sugar_gate; // thread-local gate for sugar parsing (tests/docs)
// mod errors;
use common::ParserUtils;
@ -30,6 +33,9 @@ use crate::tokenizer::{Token, TokenType, TokenizeError};
use crate::ast::{ASTNode, Span};
use thiserror::Error;
#[inline]
fn is_sugar_enabled() -> bool { crate::parser::sugar_gate::is_enabled() }
// ===== 🔥 Debug Macros =====
/// Infinite loop detection macro - must be called in every loop that advances tokens
@ -197,7 +203,7 @@ impl NyashParser {
// まず左辺を式としてパース
let expr = self.parse_expression()?;
// 次のトークンが = なら代入文
// 次のトークンが = または 複合代入演算子 なら代入文
if self.match_token(&TokenType::ASSIGN) {
self.advance(); // consume '='
let value = Box::new(self.parse_expression()?);
@ -217,6 +223,40 @@ impl NyashParser {
Err(ParseError::InvalidStatement { line })
}
}
} else if self.match_token(&TokenType::PLUS_ASSIGN) ||
self.match_token(&TokenType::MINUS_ASSIGN) ||
self.match_token(&TokenType::MUL_ASSIGN) ||
self.match_token(&TokenType::DIV_ASSIGN) {
if !is_sugar_enabled() {
let line = self.current_token().line;
return Err(ParseError::UnexpectedToken {
found: self.current_token().token_type.clone(),
expected: "enable NYASH_SYNTAX_SUGAR_LEVEL=basic|full for '+=' and friends".to_string(),
line,
});
}
// determine operator
let op = match &self.current_token().token_type {
TokenType::PLUS_ASSIGN => crate::ast::BinaryOperator::Add,
TokenType::MINUS_ASSIGN => crate::ast::BinaryOperator::Subtract,
TokenType::MUL_ASSIGN => crate::ast::BinaryOperator::Multiply,
TokenType::DIV_ASSIGN => crate::ast::BinaryOperator::Divide,
_ => unreachable!(),
};
self.advance(); // consume 'op='
let rhs = self.parse_expression()?;
// 左辺が代入可能な形式かチェック
match &expr {
ASTNode::Variable { .. } | ASTNode::FieldAccess { .. } => {
let left_clone = expr.clone();
let value = ASTNode::BinaryOp { operator: op, left: Box::new(left_clone), right: Box::new(rhs), span: Span::unknown() };
Ok(ASTNode::Assignment { target: Box::new(expr), value: Box::new(value), span: Span::unknown() })
}
_ => {
let line = self.current_token().line;
Err(ParseError::InvalidStatement { line })
}
}
} else {
// 代入文でなければ式文として返す
Ok(expr)