Fix ModuloBox E0046 error and add null literal support
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
@ -250,6 +250,7 @@ pub enum LiteralValue {
|
||||
Integer(i64),
|
||||
Float(f64), // 浮動小数点数サポート追加
|
||||
Bool(bool),
|
||||
Null, // null値
|
||||
Void,
|
||||
}
|
||||
|
||||
@ -264,6 +265,7 @@ impl LiteralValue {
|
||||
LiteralValue::Integer(i) => Box::new(IntegerBox::new(*i)),
|
||||
LiteralValue::Float(f) => Box::new(FloatBox::new(*f)),
|
||||
LiteralValue::Bool(b) => Box::new(BoolBox::new(*b)),
|
||||
LiteralValue::Null => Box::new(crate::boxes::null_box::NullBox::new()),
|
||||
LiteralValue::Void => Box::new(VoidBox::new()),
|
||||
}
|
||||
}
|
||||
@ -283,6 +285,8 @@ impl LiteralValue {
|
||||
Some(LiteralValue::Float(float_box.value))
|
||||
} else if let Some(bool_box) = box_val.as_any().downcast_ref::<BoolBox>() {
|
||||
Some(LiteralValue::Bool(bool_box.value))
|
||||
} else if box_val.as_any().downcast_ref::<crate::boxes::null_box::NullBox>().is_some() {
|
||||
Some(LiteralValue::Null)
|
||||
} else if box_val.as_any().downcast_ref::<VoidBox>().is_some() {
|
||||
Some(LiteralValue::Void)
|
||||
} else {
|
||||
@ -298,6 +302,7 @@ impl fmt::Display for LiteralValue {
|
||||
LiteralValue::Integer(i) => write!(f, "{}", i),
|
||||
LiteralValue::Float(fl) => write!(f, "{}", fl),
|
||||
LiteralValue::Bool(b) => write!(f, "{}", b),
|
||||
LiteralValue::Null => write!(f, "null"),
|
||||
LiteralValue::Void => write!(f, "void"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,6 +513,14 @@ impl BoxCore for ModuloBox {
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "ModuloBox[{}]", self.box_id())
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl NyashBox for ModuloBox {
|
||||
|
||||
@ -357,6 +357,14 @@ impl NyashParser {
|
||||
})
|
||||
}
|
||||
|
||||
TokenType::NULL => {
|
||||
self.advance();
|
||||
Ok(ASTNode::Literal {
|
||||
value: LiteralValue::Null,
|
||||
span: Span::unknown(),
|
||||
})
|
||||
}
|
||||
|
||||
TokenType::THIS => {
|
||||
self.advance();
|
||||
Ok(ASTNode::This { span: Span::unknown() })
|
||||
|
||||
@ -16,6 +16,7 @@ pub enum TokenType {
|
||||
FLOAT(f64), // 浮動小数点数サポート追加
|
||||
TRUE,
|
||||
FALSE,
|
||||
NULL, // null リテラル
|
||||
|
||||
// キーワード
|
||||
BOX,
|
||||
@ -417,6 +418,7 @@ impl NyashTokenizer {
|
||||
"or" => TokenType::OR,
|
||||
"true" => TokenType::TRUE,
|
||||
"false" => TokenType::FALSE,
|
||||
"null" => TokenType::NULL,
|
||||
_ => TokenType::IDENTIFIER(identifier),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user