Some function call fixes#684
Conversation
| let mut i_before = *i; | ||
| let mut level_guard = i.state.level.guard(); | ||
| while let Some(((op, span), rhs)) = opt((ws(op.with_span()), inner)).parse_next(i)? { | ||
| let mut next = opt(|i: &mut _| { | ||
| // We need to make sure that we decrement the level before we enter the right-hand side. | ||
| let i_before = *i; | ||
| let op = ws(op.with_span()).parse_next(i)?; | ||
| level_guard.nest(&i_before)?; | ||
| Ok((op, inner(i)?)) | ||
| }); | ||
| while let Some(((op, span), rhs)) = next.parse_next(i)? { | ||
| expr = WithSpan::new(Box::new(Expr::BinOp(BinOp { op, lhs: expr, rhs })), span); | ||
| i_before = *i; | ||
| } |
There was a problem hiding this comment.
This function was a red herring. The change did not fix the problem with the function calls, but I still think the old implementation was not exactly correct.
| fn comma<'a: 'l, 'l>(i: &mut InputStream<'a, 'l>) -> ParseResult<'a, ()> { | ||
| (ws(','), no_comma).void().parse_next(i) | ||
| } | ||
|
|
||
| fn no_comma<'a: 'l, 'l>(i: &mut InputStream<'a, 'l>) -> ParseResult<'a, ()> { | ||
| if let Some(span) = opt(','.span()).parse_next(i)? { | ||
| cut_error!("stray comma `,` in argument list", span) | ||
| } else { | ||
| Ok(()) | ||
| } | ||
| } |
There was a problem hiding this comment.
The introduction of the repeated-comma check is not necessarily part of the PR, but I think it makes for better error messages, and I was reviewing the function anyway. :)
|
|
||
| fn no_comma<'a: 'l, 'l>(i: &mut InputStream<'a, 'l>) -> ParseResult<'a, ()> { | ||
| if let Some(span) = opt(','.span()).parse_next(i)? { | ||
| cut_error!("stray comma `,` in argument list", span) |
There was a problem hiding this comment.
This is a nit, not something that necessarily needs a fix but: I'd write expected an expression, found a comma in argument list.
There was a problem hiding this comment.
Yeah, makes sense to tell the user what we expected instead of the comma.
There was a problem hiding this comment.
Following compiler example. :)
|
Apart from the nit, looks all good to me, thanks! |
4f11aa2 to
e7fff80
Compare
| fn no_comma<'a: 'l, 'l>(i: &mut InputStream<'a, 'l>) -> ParseResult<'a, ()> { | ||
| if let Some(span) = opt(','.span()).parse_next(i)? { | ||
| cut_error!( | ||
| "expected an expression, but found a comma in argument list", |
There was a problem hiding this comment.
nitpicking++
| "expected an expression, but found a comma in argument list", | |
| "expected an expression, found a comma in argument list", |
* Parsing function calls is expensive. Make sure not to stack overflow. * We only need to to call `level.nest()` if we descent, but we need to call it before we descent.
|
Thanks! |
level.nest()if we descent, but we need to call it before we descent.I de-indented a good chunk of the code, so the diff might be more readable with hidden white-space changes.
Fixes #682.