Still more refactoring work
This commit is contained in:
parent
811c52c8d3
commit
3bca82a8c8
@ -190,7 +190,7 @@ pub enum ExpressionKind {
|
|||||||
},
|
},
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: Option<Box<Expression>>,
|
discriminator: Option<Box<Expression>>,
|
||||||
body: IfExpressionBody,
|
body: Box<IfExpressionBody>,
|
||||||
},
|
},
|
||||||
WhileExpression {
|
WhileExpression {
|
||||||
condition: Option<Box<Expression>>,
|
condition: Option<Box<Expression>>,
|
||||||
@ -242,8 +242,8 @@ pub struct ConditionArm {
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Condition {
|
pub enum Condition {
|
||||||
Pattern(Pattern),
|
Pattern(Pattern),
|
||||||
TruncatedOp(BinOp, Box<Expression>),
|
TruncatedOp(BinOp, Expression),
|
||||||
Expression(Box<Expression>),
|
Expression(Expression),
|
||||||
Else,
|
Else,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,7 +818,7 @@ impl Parser {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let body = if_expr_body()?;
|
let body = Box::new(self.if_expr_body()?);
|
||||||
Ok(Expression::new(self.id_store.fresh(), ExpressionKind::IfExpression { discriminator, body }))
|
Ok(Expression::new(self.id_store.fresh(), ExpressionKind::IfExpression { discriminator, body }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,10 +881,10 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn cond_arm(&mut self) -> ParseResult<GuardArm> {
|
fn cond_arm(&mut self) -> ParseResult<ConditionArm> {
|
||||||
let (condition, guard) = if let Keyword(Kw::Else) = self.token_handler.peek_kind() {
|
let (condition, guard) = if let Keyword(Kw::Else) = self.token_handler.peek_kind() {
|
||||||
self.token_handler.next();
|
self.token_handler.next();
|
||||||
(Condition:Else, None)
|
(Condition::Else, None)
|
||||||
} else {
|
} else {
|
||||||
let condition = self.condition()?;
|
let condition = self.condition()?;
|
||||||
let guard = self.guard()?;
|
let guard = self.guard()?;
|
||||||
@ -902,9 +902,9 @@ impl Parser {
|
|||||||
self.token_handler.next();
|
self.token_handler.next();
|
||||||
Condition::Pattern(self.pattern()?)
|
Condition::Pattern(self.pattern()?)
|
||||||
},
|
},
|
||||||
Operator(ref op) if !PrefixOp::is_prefix(&*op) => {
|
tok if BinOp::from_sigil_token(&tok).is_some() => {
|
||||||
let op = self.token_handler.next();
|
let op = BinOp::from_sigil_token(&self.token_handler.next().kind).unwrap();
|
||||||
let expr = Box::new(self.expression()?);
|
let expr = self.expression()?;
|
||||||
Condition::TruncatedOp(op, expr)
|
Condition::TruncatedOp(op, expr)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -120,30 +120,6 @@ impl<'a> ScopeResolver<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IfExpression { ref body, ref discriminator } => {
|
|
||||||
match &**discriminator {
|
|
||||||
Discriminator::Simple(expr) | Discriminator::BinOp(expr, _) => self.expr(expr)?
|
|
||||||
};
|
|
||||||
|
|
||||||
match &**body {
|
|
||||||
IfExpressionBody::SimplePatternMatch(ref pat, ref alt1, ref alt2) => {
|
|
||||||
self.pattern(pat)?;
|
|
||||||
self.block(alt1)?;
|
|
||||||
if let Some(alt) = alt2 {
|
|
||||||
self.block(alt)?;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
IfExpressionBody::GuardList(guardarms) => {
|
|
||||||
for arm in guardarms.iter() {
|
|
||||||
if let Guard::Pat(ref pat) = arm.guard {
|
|
||||||
self.pattern(pat)?;
|
|
||||||
}
|
|
||||||
self.block(&arm.body)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => ()
|
_ => ()
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -318,7 +318,7 @@ impl<'a> TypeContext<'a> {
|
|||||||
StringLiteral(_) => ty!(StringT),
|
StringLiteral(_) => ty!(StringT),
|
||||||
PrefixExp(op, expr) => self.prefix(op, expr)?,
|
PrefixExp(op, expr) => self.prefix(op, expr)?,
|
||||||
BinExp(op, lhs, rhs) => self.binexp(op, lhs, rhs)?,
|
BinExp(op, lhs, rhs) => self.binexp(op, lhs, rhs)?,
|
||||||
IfExpression { discriminator, body } => self.if_expr(discriminator, body)?,
|
IfExpression { discriminator, body } => self.if_expr(&*discriminator, &**body)?,
|
||||||
Value(val) => self.handle_value(val)?,
|
Value(val) => self.handle_value(val)?,
|
||||||
Call { box ref f, arguments } => self.call(f, arguments)?,
|
Call { box ref f, arguments } => self.call(f, arguments)?,
|
||||||
Lambda { params, type_anno, body } => self.lambda(params, type_anno, body)?,
|
Lambda { params, type_anno, body } => self.lambda(params, type_anno, body)?,
|
||||||
@ -348,10 +348,10 @@ impl<'a> TypeContext<'a> {
|
|||||||
self.handle_apply(tf, vec![t_lhs, t_rhs])
|
self.handle_apply(tf, vec![t_lhs, t_rhs])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn if_expr(&mut self, discriminator: &Discriminator, body: &IfExpressionBody) -> InferResult<Type> {
|
fn if_expr(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> InferResult<Type> {
|
||||||
use self::Discriminator::*; use self::IfExpressionBody::*;
|
use self::IfExpressionBody::*;
|
||||||
match (discriminator, body) {
|
match (discriminator, body) {
|
||||||
(Simple(expr), SimpleConditional(then_clause, else_clause)) => self.handle_simple_if(expr, then_clause, else_clause),
|
(Some(expr), SimpleConditional{ then_case, else_case }) => self.handle_simple_if(expr, then_case, else_case),
|
||||||
_ => TypeError::new(format!("Complex conditionals not supported"))
|
_ => TypeError::new(format!("Complex conditionals not supported"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user