diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index 75dd493..2a54ee6 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -424,6 +424,16 @@ fn primary_expr(input: Span) -> ParseResult { context( "primary-expr", alt(( + primary_expr_no_struct, + )), + )(input) +} + +fn primary_expr_no_struct(input: Span) -> ParseResult { + context( + "primary-expr-no-struct", + alt(( + while_expr, list_expr, paren_expr, string_literal, @@ -435,6 +445,15 @@ fn primary_expr(input: Span) -> ParseResult { )(input) } +fn while_expr(input: Span) -> ParseResult { + let id = fresh_id(&input); + map(preceded(kw("while"), pair(opt(expression), block)), + move |(condition, body)| ExpressionKind::WhileExpression { + condition: condition.map(Box::new), + body, + })(input) +} + fn paren_expr(input: Span) -> ParseResult { delimited( tok(char('(')), diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 84ce6a2..3139fa8 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -375,8 +375,8 @@ fn index() { fn while_expression() { use ExpressionKind::*; - assert_expr!("while { }", expr(WhileExpression { condition: None, body: Block::default() })); - assert_expr!( + // assert_expr_comb!("while { }", expr(WhileExpression { condition: None, body: Block::default() })); + assert_expr_comb!( "while a == b { }", expr(WhileExpression { condition: Some(bx(binop("==", expr(Value(qn!(a))), expr(Value(qn!(b)))))),