From 2efac109ef94f7cd1b25d227485ef97d744661eb Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 5 Jan 2019 16:06:55 -0800 Subject: [PATCH] Node for TupleLiteral --- schala-lang/language/src/ast.rs | 2 +- schala-lang/language/src/parsing.rs | 11 +++++++---- schala-lang/language/src/reduced_ast.rs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index 4286eeb..aa6c322 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -112,7 +112,7 @@ pub enum ExpressionType { BoolLiteral(bool), BinExp(BinOp, Box>, Box>), PrefixExp(PrefixOp, Box>), - TupleLiteral(Vec), + TupleLiteral(Vec>), Value(Rc), NamedStruct { name: Rc, diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index dd4738c..d79f14d 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -672,7 +672,10 @@ impl Parser { match inner.len() { 0 => Ok(Expression(TupleLiteral(vec![]), None)), 1 => Ok(inner.pop().unwrap()), - _ => Ok(Expression(TupleLiteral(inner), None)), + _ => { + let inner: Vec> = inner.into_iter().map(|ex| ex.into()).collect(); + Ok(Expression(TupleLiteral(inner), None)) + } } }; self.restrictions.no_struct_literal = old_struct_value; @@ -1224,12 +1227,12 @@ mod parse_tests { parse_test!("()", AST(vec![exst!(TupleLiteral(vec![]))])); parse_test!("(\"hella\", 34)", AST(vec![exst!( TupleLiteral( - vec![ex!(s r#""hella""#), ex!(s "34")] + vec![ex!(s r#""hella""#).into(), ex!(s "34").into()] ) )])); parse_test!("((1+2), \"slough\")", AST(vec![exst!(TupleLiteral(vec![ - ex!(binexp!("+", NatLiteral(1), NatLiteral(2))), - ex!(StringLiteral(rc!(slough))), + ex!(binexp!("+", NatLiteral(1), NatLiteral(2))).into(), + ex!(StringLiteral(rc!(slough))).into(), ]))])) } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index cececab..ffa327e 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -142,7 +142,7 @@ impl Expression { f: Box::new(f.reduce(symbol_table)), args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(), }, - TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.reduce(symbol_table)).collect()), + TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()), IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table), Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table), NamedStruct { .. } => Expr::UnimplementedSigilValue,