Skip to content

Commit

Permalink
wip: f me up
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Oct 22, 2023
1 parent 5ae27cc commit c7bdf6f
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions xparser/src/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,18 +763,26 @@ pub fn block(input: ParseInput) -> ParseResult<ParseInput, Ast> {
let input = next(input);
let (input, start_loc) = position(input)?;

if let Ok((input, _)) = tokens::if_tok(input) {
unit_if(input, start_loc.into())
let (input, stmt) = if let Ok((input, _)) = tokens::if_tok(input) {
unit_if(input, start_loc.into())?
} else if let Ok((input, kind)) =
alt((tokens::func_tok, tokens::test_tok, tokens::mock_tok))(input)
{
unit_func(input, kind, start_loc.into())
unit_func(input, kind, start_loc.into())?
} else if tokens::left_curly_bracket(input).is_ok() {
// TODO: This does not work to have a block as the last expression of another block
// `stmt` will parse it and return it as a statement
// we need to do something smarted like lifting the last statement to an expression if there was no semicolon

// we don't update `input` here so that we can just call `block`
block(input)
block(input)?
} else {
expr_semicolon(input)
}
expr_semicolon(input)?
};

let (input, _) = opt(tokens::semicolon)(input)?;

Ok((input, stmt))
};

let (input, stmts) = opt(many1(stmt))(input)?;
Expand Down Expand Up @@ -2329,4 +2337,37 @@ mod tests {

assert!(expr(input).is_ok());
}

#[test]
fn early_return395() {
let input = span!("func halloween(b: bool) -> int { if b { return 14 }; 15 }");

assert!(expr(input).is_ok());
}

#[test]
fn inner_block_with_semi395() {
let input = span!(
"func halloween() -> int { func inner() -> int { { { { { return 14; } } } } }; 15 }"
);

assert!(expr(input).is_ok())
}

#[test]
fn inner_nested_function395() {
let input = span! {r#"
func halloween() -> string {
func inner() -> string {
{ { { {
return "boo";
} } } }
};
"different string"
}
"#};

assert!(expr(input).is_ok())
}
}

0 comments on commit c7bdf6f

Please sign in to comment.