Small refactors

This commit is contained in:
2026-05-04 20:44:56 +02:00
parent 341000b98e
commit a6411624d3
3 changed files with 6 additions and 18 deletions
+4 -16
View File
@@ -293,22 +293,10 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
}
Rule::primary => Expression::from(inner.next().unwrap()),
Rule::static_path => Expression::Path(StaticPath::from(pair)),
Rule::integer => {
let value = pair.as_str().parse::<i64>().unwrap();
Expression::IntLiteral(value)
}
Rule::float => {
let value = pair.as_str().parse::<f64>().unwrap();
Expression::FloatLiteral(value)
}
Rule::boolean => {
let value = pair.as_str().parse::<bool>().unwrap();
Expression::BoolLiteral(value)
}
Rule::string_lit => {
let inner_str = pair.into_inner().next().unwrap().as_str();
Expression::StringLiteral(inner_str.to_string())
}
Rule::integer => Expression::IntLiteral(pair.as_str().parse::<i64>().unwrap()),
Rule::float => Expression::FloatLiteral(pair.as_str().parse::<f64>().unwrap()),
Rule::boolean => Expression::BoolLiteral(pair.as_str().parse::<bool>().unwrap()),
Rule::string_lit => Expression::StringLiteral(inner.as_str().to_string()),
Rule::tuple => Expression::TupleLiteral(inner.map(Expression::from).collect()),
_ => unimplemented!("{rule:#?}"),
}
+1 -1
View File
@@ -112,7 +112,7 @@ impl GetRust for Expression {
Expression::IntLiteral(n) => n.to_string(),
Expression::FloatLiteral(n) => n.to_string(),
Expression::BoolLiteral(b) => b.to_string(),
Expression::StringLiteral(s) => format!("\"{}\".to_string()", s),
Expression::StringLiteral(s) => format!("\"{s}\""),
Expression::TupleLiteral(t) => {
format!(
"({})",
+1 -1
View File
@@ -1,3 +1,3 @@
void main() {
(i32, i32) = (10, 20);
(i32, i32, str*) my_tuple = (10, 20, "hello, world");
}