More work on pattern-matching
This commit is contained in:
parent
5b5689accf
commit
da59fae0d3
@ -157,7 +157,7 @@ pub enum Pattern {
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum PatternLiteral {
|
||||
NumPattern(ExpressionType),
|
||||
NumPattern(ExpressionType), //TODO fix
|
||||
StringPattern(Rc<String>),
|
||||
BoolPattern(bool),
|
||||
VarPattern(Rc<String>)
|
||||
|
@ -57,8 +57,8 @@ pub enum Expr {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Alternative {
|
||||
tag: usize,
|
||||
bound_vars: (),
|
||||
tag: Option<usize>,
|
||||
bound_vars: Vec<Rc<String>>,
|
||||
item: Vec<Stmt>,
|
||||
}
|
||||
|
||||
@ -158,20 +158,34 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
||||
None => vec![],
|
||||
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
||||
};
|
||||
Expr::Match { //TODO this still doesn't work right
|
||||
cond,
|
||||
alternatives: vec![
|
||||
|
||||
/*
|
||||
let alternatives = match pat {
|
||||
Pattern::TupleStruct(name, subpatterns) => {
|
||||
let symbol = symbol_table.values.get(name).unwrap();
|
||||
|
||||
unimplemented!()
|
||||
},
|
||||
_ => panic!()
|
||||
};
|
||||
*/
|
||||
|
||||
let alternatives = vec![
|
||||
Alternative {
|
||||
tag: 0,
|
||||
bound_vars: (),
|
||||
tag: Some(0),
|
||||
bound_vars: vec![],
|
||||
item: then_clause,
|
||||
},
|
||||
Alternative {
|
||||
tag: 1,
|
||||
bound_vars: (),
|
||||
tag: None,
|
||||
bound_vars: vec![],
|
||||
item: else_clause,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
Expr::Match {
|
||||
cond,
|
||||
alternatives,
|
||||
}
|
||||
},
|
||||
IfExpressionBody::GuardList(ref _guard_arms) => panic!(),
|
||||
|
@ -11,6 +11,8 @@ pub struct SymbolTable {
|
||||
pub values: HashMap<Rc<String>, Symbol> //TODO this will eventually have real type information
|
||||
}
|
||||
|
||||
//TODO add various types of lookups here, maybe multiple hash tables internally? also make values
|
||||
//non-public
|
||||
impl SymbolTable {
|
||||
pub fn new() -> SymbolTable {
|
||||
SymbolTable { values: HashMap::new() }
|
||||
|
Loading…
Reference in New Issue
Block a user