chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
This commit is contained in:
@ -2,17 +2,17 @@
|
||||
* Function declaration parsing
|
||||
*/
|
||||
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::tokenizer::TokenType;
|
||||
use crate::ast::{ASTNode, Span};
|
||||
use crate::must_advance;
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::tokenizer::TokenType;
|
||||
|
||||
impl NyashParser {
|
||||
/// function宣言をパース: function name(params) { body }
|
||||
pub fn parse_function_declaration(&mut self) -> Result<ASTNode, ParseError> {
|
||||
self.consume(TokenType::FUNCTION)?;
|
||||
|
||||
|
||||
// 関数名を取得
|
||||
let name = if let TokenType::IDENTIFIER(name) = &self.current_token().token_type {
|
||||
let name = name.clone();
|
||||
@ -26,18 +26,18 @@ impl NyashParser {
|
||||
line,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// パラメータリストをパース
|
||||
self.consume(TokenType::LPAREN)?;
|
||||
let mut params = Vec::new();
|
||||
|
||||
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "function declaration 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();
|
||||
}
|
||||
@ -50,13 +50,13 @@ impl NyashParser {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.consume(TokenType::RPAREN)?;
|
||||
|
||||
|
||||
// 関数本体をパース
|
||||
self.consume(TokenType::LBRACE)?;
|
||||
self.skip_newlines();
|
||||
|
||||
|
||||
let mut body = Vec::new();
|
||||
while !self.match_token(&TokenType::RBRACE) && !self.is_at_end() {
|
||||
self.skip_newlines();
|
||||
@ -64,16 +64,16 @@ impl NyashParser {
|
||||
body.push(self.parse_statement()?);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.consume(TokenType::RBRACE)?;
|
||||
|
||||
|
||||
Ok(ASTNode::FunctionDeclaration {
|
||||
name,
|
||||
params,
|
||||
body,
|
||||
is_static: false, // 通常の関数は静的でない
|
||||
is_static: false, // 通常の関数は静的でない
|
||||
is_override: false, // デフォルトは非オーバーライド
|
||||
span: Span::unknown(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,16 +2,16 @@
|
||||
* Global variable parsing
|
||||
*/
|
||||
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::tokenizer::TokenType;
|
||||
use crate::ast::{ASTNode, Span};
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::tokenizer::TokenType;
|
||||
|
||||
impl NyashParser {
|
||||
/// グローバル変数をパース: global name = value
|
||||
pub fn parse_global_var(&mut self) -> Result<ASTNode, ParseError> {
|
||||
self.consume(TokenType::GLOBAL)?;
|
||||
|
||||
|
||||
let name = if let TokenType::IDENTIFIER(name) = &self.current_token().token_type {
|
||||
let name = name.clone();
|
||||
self.advance();
|
||||
@ -24,10 +24,14 @@ impl NyashParser {
|
||||
line,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
self.consume(TokenType::ASSIGN)?;
|
||||
let value = Box::new(self.parse_expression()?);
|
||||
|
||||
Ok(ASTNode::GlobalVar { name, value, span: Span::unknown() })
|
||||
|
||||
Ok(ASTNode::GlobalVar {
|
||||
name,
|
||||
value,
|
||||
span: Span::unknown(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
/*!
|
||||
* Parser Items Module
|
||||
*
|
||||
*
|
||||
* Top-level item declarations:
|
||||
* - Global variables
|
||||
* - Function declarations
|
||||
* - Static declarations (functions and boxes)
|
||||
*/
|
||||
|
||||
pub mod global_vars;
|
||||
pub mod functions;
|
||||
pub mod global_vars;
|
||||
pub mod static_items;
|
||||
|
||||
// Re-export for convenience
|
||||
|
||||
@ -3,17 +3,17 @@
|
||||
* Handles both static functions and static boxes
|
||||
*/
|
||||
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::tokenizer::TokenType;
|
||||
use crate::ast::{ASTNode, Span};
|
||||
use crate::must_advance;
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::tokenizer::TokenType;
|
||||
|
||||
impl NyashParser {
|
||||
/// 静的宣言をパース - 🔥 static function / static box 記法
|
||||
pub fn parse_static_declaration(&mut self) -> Result<ASTNode, ParseError> {
|
||||
self.consume(TokenType::STATIC)?;
|
||||
|
||||
|
||||
// 次のトークンで分岐: function か box か
|
||||
match &self.current_token().token_type {
|
||||
TokenType::FUNCTION => self.parse_static_function(),
|
||||
@ -28,20 +28,20 @@ impl NyashParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 静的関数宣言をパース - static function Name() { ... }
|
||||
fn parse_static_function(&mut self) -> Result<ASTNode, ParseError> {
|
||||
self.consume(TokenType::FUNCTION)?;
|
||||
|
||||
|
||||
// 関数名を取得(Box名.関数名の形式をサポート)
|
||||
let name = if let TokenType::IDENTIFIER(first_part) = &self.current_token().token_type {
|
||||
let mut full_name = first_part.clone();
|
||||
self.advance();
|
||||
|
||||
|
||||
// ドット記法をチェック(例:Math.min)
|
||||
if self.match_token(&TokenType::DOT) {
|
||||
self.advance(); // DOTを消費
|
||||
|
||||
|
||||
if let TokenType::IDENTIFIER(method_name) = &self.current_token().token_type {
|
||||
full_name = format!("{}.{}", full_name, method_name);
|
||||
self.advance();
|
||||
@ -54,7 +54,7 @@ impl NyashParser {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
full_name
|
||||
} else {
|
||||
let line = self.current_token().line;
|
||||
@ -64,18 +64,18 @@ impl NyashParser {
|
||||
line,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// パラメータリストをパース
|
||||
self.consume(TokenType::LPAREN)?;
|
||||
let mut params = Vec::new();
|
||||
|
||||
|
||||
while !self.match_token(&TokenType::RPAREN) && !self.is_at_end() {
|
||||
must_advance!(self, _unused, "static function 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();
|
||||
}
|
||||
@ -88,13 +88,13 @@ impl NyashParser {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.consume(TokenType::RPAREN)?;
|
||||
|
||||
|
||||
// 関数本体をパース
|
||||
self.consume(TokenType::LBRACE)?;
|
||||
self.skip_newlines();
|
||||
|
||||
|
||||
let mut body = Vec::new();
|
||||
while !self.match_token(&TokenType::RBRACE) && !self.is_at_end() {
|
||||
self.skip_newlines();
|
||||
@ -102,16 +102,16 @@ impl NyashParser {
|
||||
body.push(self.parse_statement()?);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.consume(TokenType::RBRACE)?;
|
||||
|
||||
|
||||
Ok(ASTNode::FunctionDeclaration {
|
||||
name,
|
||||
params,
|
||||
body,
|
||||
is_static: true, // 🔥 静的関数フラグを設定
|
||||
is_static: true, // 🔥 静的関数フラグを設定
|
||||
is_override: false, // デフォルトは非オーバーライド
|
||||
span: Span::unknown(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user