Small refactors
This commit is contained in:
+4
-16
@@ -293,22 +293,10 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
|||||||
}
|
}
|
||||||
Rule::primary => Expression::from(inner.next().unwrap()),
|
Rule::primary => Expression::from(inner.next().unwrap()),
|
||||||
Rule::static_path => Expression::Path(StaticPath::from(pair)),
|
Rule::static_path => Expression::Path(StaticPath::from(pair)),
|
||||||
Rule::integer => {
|
Rule::integer => Expression::IntLiteral(pair.as_str().parse::<i64>().unwrap()),
|
||||||
let value = pair.as_str().parse::<i64>().unwrap();
|
Rule::float => Expression::FloatLiteral(pair.as_str().parse::<f64>().unwrap()),
|
||||||
Expression::IntLiteral(value)
|
Rule::boolean => Expression::BoolLiteral(pair.as_str().parse::<bool>().unwrap()),
|
||||||
}
|
Rule::string_lit => Expression::StringLiteral(inner.as_str().to_string()),
|
||||||
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::tuple => Expression::TupleLiteral(inner.map(Expression::from).collect()),
|
Rule::tuple => Expression::TupleLiteral(inner.map(Expression::from).collect()),
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -112,7 +112,7 @@ impl GetRust for Expression {
|
|||||||
Expression::IntLiteral(n) => n.to_string(),
|
Expression::IntLiteral(n) => n.to_string(),
|
||||||
Expression::FloatLiteral(n) => n.to_string(),
|
Expression::FloatLiteral(n) => n.to_string(),
|
||||||
Expression::BoolLiteral(b) => b.to_string(),
|
Expression::BoolLiteral(b) => b.to_string(),
|
||||||
Expression::StringLiteral(s) => format!("\"{}\".to_string()", s),
|
Expression::StringLiteral(s) => format!("\"{s}\""),
|
||||||
Expression::TupleLiteral(t) => {
|
Expression::TupleLiteral(t) => {
|
||||||
format!(
|
format!(
|
||||||
"({})",
|
"({})",
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
void main() {
|
void main() {
|
||||||
(i32, i32) = (10, 20);
|
(i32, i32, str*) my_tuple = (10, 20, "hello, world");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user