Starting work on guard arms
This commit is contained in:
parent
5ecd298e6a
commit
837a180b09
@ -125,13 +125,25 @@ pub enum Discriminator {
|
|||||||
pub enum IfExpressionBody {
|
pub enum IfExpressionBody {
|
||||||
SimpleConditional(Block, Option<Block>),
|
SimpleConditional(Block, Option<Block>),
|
||||||
SimplePatternMatch(Pattern, Block, Option<Block>),
|
SimplePatternMatch(Pattern, Block, Option<Block>),
|
||||||
GuardList(Vec<Guard>)
|
GuardList(Vec<GuardArm>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Guard {
|
pub struct GuardArm {
|
||||||
pat: Pattern,
|
pub guard: Guard,
|
||||||
body: Block,
|
pub body: Block,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub enum Guard {
|
||||||
|
Pat(Pattern),
|
||||||
|
HalfExpr(HalfExpr)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub struct HalfExpr {
|
||||||
|
pub op: Option<BinOp>,
|
||||||
|
pub expr: ExpressionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
@ -124,7 +124,8 @@ modified_precedence_expression := ???
|
|||||||
conditional := block else_clause
|
conditional := block else_clause
|
||||||
simple_pattern_match := pattern 'then' conditional
|
simple_pattern_match := pattern 'then' conditional
|
||||||
else_clause := ε | 'else' block
|
else_clause := ε | 'else' block
|
||||||
guard_block := '{' (guard, ',')* '}'
|
guard_block := '{' (guard_arm, ',')* '}'
|
||||||
|
guard_arm := guard '->' block
|
||||||
guard := ??
|
guard := ??
|
||||||
|
|
||||||
/* Expression - While */
|
/* Expression - While */
|
||||||
@ -701,10 +702,17 @@ impl Parser {
|
|||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(guard_block(&mut self) -> ParseResult<IfExpressionBody> {
|
parse_method!(guard_block(&mut self) -> ParseResult<IfExpressionBody> {
|
||||||
let guards = delimited!(self, LCurlyBrace, guard, Comma, RCurlyBrace);
|
let guards = delimited!(self, LCurlyBrace, guard_arm, Comma, RCurlyBrace);
|
||||||
Ok(IfExpressionBody::GuardList(guards))
|
Ok(IfExpressionBody::GuardList(guards))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
parse_method!(guard_arm(&mut self) -> ParseResult<GuardArm> {
|
||||||
|
let guard = self.guard()?;
|
||||||
|
expect!(self, Operator(ref c) if **c == "->");
|
||||||
|
let body = self.block()?;
|
||||||
|
Ok(GuardArm { guard, body })
|
||||||
|
});
|
||||||
|
|
||||||
parse_method!(guard(&mut self) -> ParseResult<Guard> {
|
parse_method!(guard(&mut self) -> ParseResult<Guard> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user