Node for TupleLiteral

This commit is contained in:
greg 2019-01-05 16:06:55 -08:00
parent 215e2bbb0d
commit 2efac109ef
3 changed files with 9 additions and 6 deletions

View File

@ -112,7 +112,7 @@ pub enum ExpressionType {
BoolLiteral(bool), BoolLiteral(bool),
BinExp(BinOp, Box<Node<Expression>>, Box<Node<Expression>>), BinExp(BinOp, Box<Node<Expression>>, Box<Node<Expression>>),
PrefixExp(PrefixOp, Box<Node<Expression>>), PrefixExp(PrefixOp, Box<Node<Expression>>),
TupleLiteral(Vec<Expression>), TupleLiteral(Vec<Node<Expression>>),
Value(Rc<String>), Value(Rc<String>),
NamedStruct { NamedStruct {
name: Rc<String>, name: Rc<String>,

View File

@ -672,7 +672,10 @@ impl Parser {
match inner.len() { match inner.len() {
0 => Ok(Expression(TupleLiteral(vec![]), None)), 0 => Ok(Expression(TupleLiteral(vec![]), None)),
1 => Ok(inner.pop().unwrap()), 1 => Ok(inner.pop().unwrap()),
_ => Ok(Expression(TupleLiteral(inner), None)), _ => {
let inner: Vec<Node<Expression>> = inner.into_iter().map(|ex| ex.into()).collect();
Ok(Expression(TupleLiteral(inner), None))
}
} }
}; };
self.restrictions.no_struct_literal = old_struct_value; self.restrictions.no_struct_literal = old_struct_value;
@ -1224,12 +1227,12 @@ mod parse_tests {
parse_test!("()", AST(vec![exst!(TupleLiteral(vec![]))])); parse_test!("()", AST(vec![exst!(TupleLiteral(vec![]))]));
parse_test!("(\"hella\", 34)", AST(vec![exst!( parse_test!("(\"hella\", 34)", AST(vec![exst!(
TupleLiteral( 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![ parse_test!("((1+2), \"slough\")", AST(vec![exst!(TupleLiteral(vec![
ex!(binexp!("+", NatLiteral(1), NatLiteral(2))), ex!(binexp!("+", NatLiteral(1), NatLiteral(2))).into(),
ex!(StringLiteral(rc!(slough))), ex!(StringLiteral(rc!(slough))).into(),
]))])) ]))]))
} }

View File

@ -142,7 +142,7 @@ impl Expression {
f: Box::new(f.reduce(symbol_table)), f: Box::new(f.reduce(symbol_table)),
args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(), 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), IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table),
Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table), Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table),
NamedStruct { .. } => Expr::UnimplementedSigilValue, NamedStruct { .. } => Expr::UnimplementedSigilValue,