Make standalone
an enum
This commit is contained in:
parent
4212835d99
commit
95960b7d54
1 changed files with 25 additions and 13 deletions
|
@ -161,15 +161,24 @@ impl AttemptLocalParseRecovery {
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
struct IncDecRecovery {
|
struct IncDecRecovery {
|
||||||
/// Is this increment/decrement its own statement?
|
/// Is this increment/decrement its own statement?
|
||||||
///
|
standalone: IsStandalone,
|
||||||
/// This is `None` when we are unsure.
|
|
||||||
standalone: Option<bool>,
|
|
||||||
/// Is this an increment or decrement?
|
/// Is this an increment or decrement?
|
||||||
op: IncOrDec,
|
op: IncOrDec,
|
||||||
/// Is this pre- or postfix?
|
/// Is this pre- or postfix?
|
||||||
fixity: UnaryFixity,
|
fixity: UnaryFixity,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is an increment or decrement expression its own statement?
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
enum IsStandalone {
|
||||||
|
/// It's standalone, i.e., its own statement.
|
||||||
|
Standalone,
|
||||||
|
/// It's a subexpression, i.e., *not* standalone.
|
||||||
|
Subexpr,
|
||||||
|
/// It's maybe standalone; we're not sure.
|
||||||
|
Maybe,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
enum IncOrDec {
|
enum IncOrDec {
|
||||||
Inc,
|
Inc,
|
||||||
|
@ -1226,11 +1235,9 @@ impl<'a> Parser<'a> {
|
||||||
op_span: Span,
|
op_span: Span,
|
||||||
prev_is_semi: bool,
|
prev_is_semi: bool,
|
||||||
) -> PResult<'a, P<Expr>> {
|
) -> PResult<'a, P<Expr>> {
|
||||||
let kind = IncDecRecovery {
|
let standalone =
|
||||||
standalone: Some(prev_is_semi),
|
if prev_is_semi { IsStandalone::Standalone } else { IsStandalone::Subexpr };
|
||||||
op: IncOrDec::Inc,
|
let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre };
|
||||||
fixity: UnaryFixity::Pre,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.recover_from_inc_dec(operand_expr, kind, op_span)
|
self.recover_from_inc_dec(operand_expr, kind, op_span)
|
||||||
}
|
}
|
||||||
|
@ -1240,8 +1247,11 @@ impl<'a> Parser<'a> {
|
||||||
operand_expr: P<Expr>,
|
operand_expr: P<Expr>,
|
||||||
op_span: Span,
|
op_span: Span,
|
||||||
) -> PResult<'a, P<Expr>> {
|
) -> PResult<'a, P<Expr>> {
|
||||||
let kind =
|
let kind = IncDecRecovery {
|
||||||
IncDecRecovery { standalone: None, op: IncOrDec::Inc, fixity: UnaryFixity::Post };
|
standalone: IsStandalone::Maybe,
|
||||||
|
op: IncOrDec::Inc,
|
||||||
|
fixity: UnaryFixity::Post,
|
||||||
|
};
|
||||||
|
|
||||||
self.recover_from_inc_dec(operand_expr, kind, op_span)
|
self.recover_from_inc_dec(operand_expr, kind, op_span)
|
||||||
}
|
}
|
||||||
|
@ -1271,8 +1281,10 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
match kind.standalone {
|
match kind.standalone {
|
||||||
Some(true) => self.inc_dec_standalone_recovery(&mut err, kind, spans, false),
|
IsStandalone::Standalone => {
|
||||||
Some(false) => {
|
self.inc_dec_standalone_recovery(&mut err, kind, spans, false)
|
||||||
|
}
|
||||||
|
IsStandalone::Subexpr => {
|
||||||
let Ok(base_src) = self.span_to_snippet(base.span)
|
let Ok(base_src) = self.span_to_snippet(base.span)
|
||||||
else { return help_base_case(err, base) };
|
else { return help_base_case(err, base) };
|
||||||
match kind.fixity {
|
match kind.fixity {
|
||||||
|
@ -1284,7 +1296,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
IsStandalone::Maybe => {
|
||||||
let Ok(base_src) = self.span_to_snippet(base.span)
|
let Ok(base_src) = self.span_to_snippet(base.span)
|
||||||
else { return help_base_case(err, base) };
|
else { return help_base_case(err, base) };
|
||||||
match kind.fixity {
|
match kind.fixity {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue