From 61b757313d96329e9f5b4b7649510af8dba63fb0 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 10 Oct 2019 02:34:56 -0700 Subject: [PATCH] Alter grammar of if-blocks --- schala-lang/language/src/parsing.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 2d20ea5..869465e 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -113,19 +113,26 @@ //! record_pattern_entry := IDENTIFIER | IDENTIFIER ":" Pattern //! tuple_struct_pattern := qualified_identifier "(" (pattern, ",")* ")" //! ``` +//! ### If expressions +//! +//! TODO: it would be nice if the grammar could capture an incomplete precedence expr in the +//! discriminator //! -//! ### If-expressions //! ```text -//! if_expr := "if" discriminator ("then" condititional | "is" simple_pattern_match | guard_block) -//! discriminator := precedence_expr (operator)+ -//! conditional := expr_or_block else_clause -//! simple_pattern_match := pattern "then" conditional -//! else_clause := ε | "else" expr_or_block -//! guard_block := "{" (guard_arm, ",")* "}" -//! guard_arm := guard "then" expr_or_block | "else" expr_or_block -//! guard := "is" pattern | (operator)+ precedence_expr +//! if_expr := "if" discriminator ("then" simple_conditional | "is" simple_pattern_match | cond_block) +//! discriminator := ε | expression +//! simple_conditional := expr_or_block else_clause +//! simple_pattern_match := pattern "then" simple_conditional +//! else_clause := "else" expr_or_block +//! +//! cond_block := "{" (cond_arm comma_or_delimiter)* "}" +//! cond_arm := condition guard "then" expr_or_block +//! condition := "is" pattern | operator precedence_expr | expression +//! guard := "if" expression +//! comma_or_delimiter := "," | delimiter //! ``` //! +//! //! ### While expressions //! ```text //! while_expr := "while" while_cond "{" (statement delimiter)* "}"