Tuples
This commit is contained in:
parent
e2703121d8
commit
1f6e6d9b31
@ -20,6 +20,7 @@ pub enum Stmt {
|
|||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
Unit,
|
Unit,
|
||||||
Lit(Lit),
|
Lit(Lit),
|
||||||
|
Tuple(Vec<Expr>),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
Val(Rc<String>),
|
Val(Rc<String>),
|
||||||
Call {
|
Call {
|
||||||
@ -88,7 +89,8 @@ impl Expression {
|
|||||||
f: Box::new(f.reduce()),
|
f: Box::new(f.reduce()),
|
||||||
args: arguments.iter().map(|arg| arg.reduce()).collect(),
|
args: arguments.iter().map(|arg| arg.reduce()).collect(),
|
||||||
},
|
},
|
||||||
e => Expr::UnimplementedSigilValue,
|
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.reduce()).collect()),
|
||||||
|
_ => Expr::UnimplementedSigilValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,18 @@ impl Expr {
|
|||||||
UserDefined { name: None, .. } => format!("<function>"),
|
UserDefined { name: None, .. } => format!("<function>"),
|
||||||
UserDefined { name: Some(name), .. } => format!("<function {}>", name),
|
UserDefined { name: Some(name), .. } => format!("<function {}>", name),
|
||||||
},
|
},
|
||||||
|
Expr::Tuple(exprs) => {
|
||||||
|
let mut buf = String::new();
|
||||||
|
write!(buf, "(").unwrap();
|
||||||
|
for term in exprs.iter().map(|e| Some(e)).intersperse(None) {
|
||||||
|
match term {
|
||||||
|
Some(e) => write!(buf, "{}", e.to_repl()).unwrap(),
|
||||||
|
None => write!(buf, ", ").unwrap(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
write!(buf, ")").unwrap();
|
||||||
|
buf
|
||||||
|
},
|
||||||
_ => format!("{:?}", self),
|
_ => format!("{:?}", self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,6 +355,7 @@ impl<'a> State<'a> {
|
|||||||
},
|
},
|
||||||
Val(v) => self.value(v),
|
Val(v) => self.value(v),
|
||||||
func @ Func(_) => Ok(func),
|
func @ Func(_) => Ok(func),
|
||||||
|
Tuple(exprs) => Ok(Tuple(exprs.into_iter().map(|expr| self.expression(expr)).collect::<Result<Vec<Expr>,_>>()?)),
|
||||||
Assign { box val, box expr } => {
|
Assign { box val, box expr } => {
|
||||||
let name = match val {
|
let name = match val {
|
||||||
Expr::Val(name) => name,
|
Expr::Val(name) => name,
|
||||||
|
Loading…
Reference in New Issue
Block a user