1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use ast::*;
pub fn expr_to_pat(expr: &Expr) -> Pat {
match *expr {
Expr::Dummy => Pat::Dummy,
Expr::Operator(ref s) => Pat::Dummy,
Expr::Ref(ref id) => Pat::Ref(id.clone()),
Expr::Parens(ref inner) => Pat::Span(inner.iter().map(|x| expr_to_pat(x)).collect::<Vec<_>>()),
Expr::Span(ref inner) => Pat::Span(inner.iter().map(|x| expr_to_pat(x)).collect::<Vec<_>>()),
Expr::Vector(ref inner) => Pat::Brackets(inner.iter().map(|x| expr_to_pat(x)).collect::<Vec<_>>()),
Expr::Record(ref inner) => Pat::Dummy,
Expr::Number(num) => Pat::Num(num),
Expr::Str(ref s) => Pat::Str(s.clone()),
Expr::Char(ref s) => Pat::Char(s.clone()),
Expr::Lambda |
Expr::Error |
_ => {
panic!("Invalid expr to pat conversion: {:?}", expr);
}
}
}