chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt

This commit is contained in:
Selfhosting Dev
2025-09-17 07:43:07 +09:00
parent fcf8ce1f3c
commit adbb0201a9
385 changed files with 35622 additions and 15004 deletions

View File

@ -1,19 +1,19 @@
/*! 🌐 HTTP Method Implementations
*
*
* HTTP関連Boxのメソッド実行を実装
* SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox
*/
use super::super::*;
use crate::boxes::{SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox};
use crate::boxes::{HTTPRequestBox, HTTPResponseBox, HTTPServerBox, SocketBox};
impl NyashInterpreter {
/// SocketBox methods
pub(in crate::interpreter) fn execute_socket_method(
&mut self,
socket_box: &SocketBox,
method: &str,
arguments: &[ASTNode]
&mut self,
socket_box: &SocketBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"bind" => {
@ -22,7 +22,7 @@ impl NyashInterpreter {
message: format!("bind() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
let result = socket_box.bind(address, port);
@ -34,7 +34,7 @@ impl NyashInterpreter {
message: format!("listen() expects 1 argument, got {}", arguments.len()),
});
}
let backlog = self.execute_expression(&arguments[0])?;
Ok(socket_box.listen(backlog))
}
@ -44,13 +44,16 @@ impl NyashInterpreter {
message: format!("accept() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.accept())
}
"acceptTimeout" | "accept_timeout" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("acceptTimeout(ms) expects 1 argument, got {}", arguments.len()),
message: format!(
"acceptTimeout(ms) expects 1 argument, got {}",
arguments.len()
),
});
}
let ms = self.execute_expression(&arguments[0])?;
@ -62,7 +65,7 @@ impl NyashInterpreter {
message: format!("connect() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
Ok(socket_box.connect(address, port))
@ -73,13 +76,16 @@ impl NyashInterpreter {
message: format!("read() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.read())
}
"recvTimeout" | "recv_timeout" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("recvTimeout(ms) expects 1 argument, got {}", arguments.len()),
message: format!(
"recvTimeout(ms) expects 1 argument, got {}",
arguments.len()
),
});
}
let ms = self.execute_expression(&arguments[0])?;
@ -88,10 +94,13 @@ impl NyashInterpreter {
"readHttpRequest" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("readHttpRequest() expects 0 arguments, got {}", arguments.len()),
message: format!(
"readHttpRequest() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(socket_box.read_http_request())
}
"write" => {
@ -100,7 +109,7 @@ impl NyashInterpreter {
message: format!("write() expects 1 argument, got {}", arguments.len()),
});
}
let data = self.execute_expression(&arguments[0])?;
Ok(socket_box.write(data))
}
@ -110,16 +119,19 @@ impl NyashInterpreter {
message: format!("close() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.close())
}
"isConnected" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("isConnected() expects 0 arguments, got {}", arguments.len()),
message: format!(
"isConnected() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(socket_box.is_connected())
}
"isServer" => {
@ -128,7 +140,7 @@ impl NyashInterpreter {
message: format!("isServer() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.is_server())
}
"toString" => {
@ -137,7 +149,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(socket_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -148,10 +160,10 @@ impl NyashInterpreter {
/// HTTPServerBox methods
pub(in crate::interpreter) fn execute_http_server_method(
&mut self,
server_box: &HTTPServerBox,
method: &str,
arguments: &[ASTNode]
&mut self,
server_box: &HTTPServerBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"bind" => {
@ -160,7 +172,7 @@ impl NyashInterpreter {
message: format!("bind() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
Ok(server_box.bind(address, port))
@ -171,7 +183,7 @@ impl NyashInterpreter {
message: format!("listen() expects 1 argument, got {}", arguments.len()),
});
}
let backlog = self.execute_expression(&arguments[0])?;
Ok(server_box.listen(backlog))
}
@ -181,7 +193,7 @@ impl NyashInterpreter {
message: format!("start() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(server_box.start())
}
"stop" => {
@ -190,7 +202,7 @@ impl NyashInterpreter {
message: format!("stop() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(server_box.stop())
}
"get" => {
@ -199,7 +211,7 @@ impl NyashInterpreter {
message: format!("get() expects 2 arguments, got {}", arguments.len()),
});
}
let path = self.execute_expression(&arguments[0])?;
let handler = self.execute_expression(&arguments[1])?;
Ok(server_box.get(path, handler))
@ -210,7 +222,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(server_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -221,19 +233,22 @@ impl NyashInterpreter {
/// HTTPRequestBox methods
pub(in crate::interpreter) fn execute_http_request_method(
&mut self,
request_box: &HTTPRequestBox,
method: &str,
arguments: &[ASTNode]
&mut self,
request_box: &HTTPRequestBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"getMethod" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("getMethod() expects 0 arguments, got {}", arguments.len()),
message: format!(
"getMethod() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(request_box.get_method())
}
"getPath" => {
@ -242,7 +257,7 @@ impl NyashInterpreter {
message: format!("getPath() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(request_box.get_path())
}
"toString" => {
@ -251,7 +266,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(request_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -262,19 +277,22 @@ impl NyashInterpreter {
/// HTTPResponseBox methods
pub(in crate::interpreter) fn execute_http_response_method(
&mut self,
response_box: &HTTPResponseBox,
method: &str,
arguments: &[ASTNode]
&mut self,
response_box: &HTTPResponseBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"setStatus" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("setStatus() expects 2 arguments, got {}", arguments.len()),
message: format!(
"setStatus() expects 2 arguments, got {}",
arguments.len()
),
});
}
let code = self.execute_expression(&arguments[0])?;
let message = self.execute_expression(&arguments[1])?;
Ok(response_box.set_status(code, message))
@ -282,10 +300,13 @@ impl NyashInterpreter {
"toHttpString" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("toHttpString() expects 0 arguments, got {}", arguments.len()),
message: format!(
"toHttpString() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(response_box.to_http_string())
}
"toString" => {
@ -294,7 +315,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(response_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {