Tuple literals
This commit is contained in:
@@ -142,6 +142,7 @@ pub enum Expression {
|
|||||||
FloatLiteral(f64),
|
FloatLiteral(f64),
|
||||||
BoolLiteral(bool),
|
BoolLiteral(bool),
|
||||||
StringLiteral(String),
|
StringLiteral(String),
|
||||||
|
TupleLiteral(Vec<Expression>),
|
||||||
Fix {
|
Fix {
|
||||||
initial: Box<Expression>,
|
initial: Box<Expression>,
|
||||||
prefixes: Vec<Prefix>,
|
prefixes: Vec<Prefix>,
|
||||||
|
|||||||
@@ -87,12 +87,15 @@ macro_inner_v = {
|
|||||||
| (!("(" | ")") ~ ANY)
|
| (!("(" | ")") ~ ANY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tuple = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" }
|
||||||
|
|
||||||
primary = {
|
primary = {
|
||||||
integer
|
integer
|
||||||
| float
|
| float
|
||||||
| boolean
|
| boolean
|
||||||
| string_lit
|
| string_lit
|
||||||
| static_path
|
| static_path
|
||||||
|
| tuple
|
||||||
}
|
}
|
||||||
|
|
||||||
postfix = {
|
postfix = {
|
||||||
|
|||||||
+1
-1
@@ -309,7 +309,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
|||||||
let inner_str = pair.into_inner().next().unwrap().as_str();
|
let inner_str = pair.into_inner().next().unwrap().as_str();
|
||||||
Expression::StringLiteral(inner_str.to_string())
|
Expression::StringLiteral(inner_str.to_string())
|
||||||
}
|
}
|
||||||
|
Rule::tuple => Expression::TupleLiteral(inner.map(Expression::from).collect()),
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -113,7 +113,15 @@ impl GetRust for Expression {
|
|||||||
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!("\"{}\".to_string()", s),
|
||||||
|
Expression::TupleLiteral(t) => {
|
||||||
|
format!(
|
||||||
|
"({})",
|
||||||
|
t.iter()
|
||||||
|
.map(Expression::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
Expression::Fix {
|
Expression::Fix {
|
||||||
initial,
|
initial,
|
||||||
prefixes,
|
prefixes,
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
void main() {
|
void main() {
|
||||||
println!("Hello, World!");
|
(i32, i32) = (10, 20);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user