diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 2a58fed..5051a1d 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -142,6 +142,7 @@ pub enum Expression { FloatLiteral(f64), BoolLiteral(bool), StringLiteral(String), + TupleLiteral(Vec), Fix { initial: Box, prefixes: Vec, diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index dc508e2..c6ee1b8 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -87,12 +87,15 @@ macro_inner_v = { | (!("(" | ")") ~ ANY) } +tuple = { "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" } + primary = { integer | float | boolean | string_lit | static_path + | tuple } postfix = { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 778faa2..a5fda42 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -309,7 +309,7 @@ impl From> for Expression { 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()), _ => unimplemented!("{rule:#?}"), } } diff --git a/src/codegen.rs b/src/codegen.rs index 7463650..a288066 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -113,7 +113,15 @@ impl GetRust for Expression { Expression::FloatLiteral(n) => n.to_string(), Expression::BoolLiteral(b) => b.to_string(), Expression::StringLiteral(s) => format!("\"{}\".to_string()", s), - + Expression::TupleLiteral(t) => { + format!( + "({})", + t.iter() + .map(Expression::get_rust) + .collect::>() + .join(", ") + ) + } Expression::Fix { initial, prefixes, diff --git a/test/src/main.mist b/test/src/main.mist index aa71749..6ae3431 100644 --- a/test/src/main.mist +++ b/test/src/main.mist @@ -1,3 +1,3 @@ void main() { - println!("Hello, World!"); + (i32, i32) = (10, 20); } \ No newline at end of file