Starting work on guard arms
This commit is contained in:
parent
5ecd298e6a
commit
837a180b09
@ -125,13 +125,25 @@ pub enum Discriminator {
|
||||
pub enum IfExpressionBody {
|
||||
SimpleConditional(Block, Option<Block>),
|
||||
SimplePatternMatch(Pattern, Block, Option<Block>),
|
||||
GuardList(Vec<Guard>)
|
||||
GuardList(Vec<GuardArm>)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Guard {
|
||||
pat: Pattern,
|
||||
body: Block,
|
||||
pub struct GuardArm {
|
||||
pub guard: Guard,
|
||||
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)]
|
||||
|
@ -124,7 +124,8 @@ modified_precedence_expression := ???
|
||||
conditional := block else_clause
|
||||
simple_pattern_match := pattern 'then' conditional
|
||||
else_clause := ε | 'else' block
|
||||
guard_block := '{' (guard, ',')* '}'
|
||||
guard_block := '{' (guard_arm, ',')* '}'
|
||||
guard_arm := guard '->' block
|
||||
guard := ??
|
||||
|
||||
/* Expression - While */
|
||||
@ -701,10 +702,17 @@ impl Parser {
|
||||
});
|
||||
|
||||
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))
|
||||
});
|
||||
|
||||
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> {
|
||||
unimplemented!()
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user