feat(constructor): implement birth() syntax and pack transparency system
## 🌟 birth() Constructor Implementation - Add BIRTH token to tokenizer (src/tokenizer.rs:37,403) - Implement birth() parser support (src/parser/mod.rs) - Add birth() interpreter support with priority system - Priority: birth > pack > init > Box名 ## 🚨 Fix Documentation Inconsistencies - Fix delegation-system.md: pack → birth unified - Fix box-design/README.md: add pack-specific section - Fix LANGUAGE_GUIDE.md: birth unified, pack builtin-only - Fix CLAUDE.md: birth philosophy, pack system separation ## 📋 pack Transparency System Design - Create phase_8_8_pack_transparency_system.md specification - Establish correct pack definition: builtin Box inheritance only - Design user-transparent system: from BuiltinBox() → internal pack - Comprehensive test cases and implementation requirements ## 🧪 Testing - Add test_birth_simple.nyash: birth() functionality verification - Document constructor name decision process - Prepare for Copilot implementation with clear specifications 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -451,6 +451,66 @@ impl NyashParser {
|
||||
span: Span::unknown(),
|
||||
};
|
||||
|
||||
// パラメータの数でコンストラクタを区別
|
||||
let constructor_key = format!("{}/{}", field_or_method, params.len());
|
||||
constructors.insert(constructor_key, constructor);
|
||||
}
|
||||
}
|
||||
|
||||
// birthトークンをメソッド名として特別処理
|
||||
else if self.match_token(&TokenType::BIRTH) && self.peek_token() == &TokenType::LPAREN {
|
||||
let field_or_method = "birth".to_string();
|
||||
self.advance(); // consume 'birth'
|
||||
|
||||
// コンストラクタとして処理
|
||||
if self.match_token(&TokenType::LPAREN) {
|
||||
// birthは常にコンストラクタ
|
||||
if is_override {
|
||||
return Err(ParseError::UnexpectedToken {
|
||||
expected: "method definition, not constructor after override keyword".to_string(),
|
||||
found: TokenType::BIRTH,
|
||||
line: self.current_token().line,
|
||||
});
|
||||
}
|
||||
// コンストラクタの処理
|
||||
self.advance(); // consume '('
|
||||
|
||||
let mut params = Vec::new();
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "constructor parameter parsing");
|
||||
|
||||
if let TokenType::IDENTIFIER(param) = &self.current_token().token_type {
|
||||
params.push(param.clone());
|
||||
self.advance();
|
||||
}
|
||||
|
||||
if self.match_token(&TokenType::COMMA) {
|
||||
self.advance();
|
||||
}
|
||||
}
|
||||
|
||||
self.consume(TokenType::RPAREN)?;
|
||||
self.consume(TokenType::LBRACE)?;
|
||||
|
||||
let mut body = Vec::new();
|
||||
while !self.match_token(&TokenType::RBRACE) && !self.is_at_end() {
|
||||
self.skip_newlines();
|
||||
if !self.match_token(&TokenType::RBRACE) {
|
||||
body.push(self.parse_statement()?);
|
||||
}
|
||||
}
|
||||
|
||||
self.consume(TokenType::RBRACE)?;
|
||||
|
||||
let constructor = ASTNode::FunctionDeclaration {
|
||||
name: field_or_method.clone(),
|
||||
params: params.clone(),
|
||||
body,
|
||||
is_static: false,
|
||||
is_override: false,
|
||||
span: Span::unknown(),
|
||||
};
|
||||
|
||||
// パラメータの数でコンストラクタを区別
|
||||
let constructor_key = format!("{}/{}", field_or_method, params.len());
|
||||
constructors.insert(constructor_key, constructor);
|
||||
@ -461,8 +521,8 @@ impl NyashParser {
|
||||
|
||||
// メソッド定義またはコンストラクタか?
|
||||
if self.match_token(&TokenType::LPAREN) {
|
||||
// Box名と同じまたは"init"または"pack"の場合はコンストラクタ
|
||||
if field_or_method == name || field_or_method == "init" || field_or_method == "pack" {
|
||||
// Box名と同じまたは"init"または"pack"または"birth"の場合はコンストラクタ
|
||||
if field_or_method == name || field_or_method == "init" || field_or_method == "pack" || field_or_method == "birth" {
|
||||
// コンストラクタはoverrideできない
|
||||
if is_override {
|
||||
return Err(ParseError::UnexpectedToken {
|
||||
|
||||
Reference in New Issue
Block a user