From df0c370059859758e899b0379b64559b129da927 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Thu, 29 Jun 2023 10:55:13 -0600 Subject: [PATCH] Added let-exprs to grammar, and fixed patterns --- grammar.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/grammar.txt b/grammar.txt index 73af91c..962dfe0 100644 --- a/grammar.txt +++ b/grammar.txt @@ -3,7 +3,7 @@ expression -> // | apply | unary | binary -// | let + | let | compound | control | field @@ -17,16 +17,19 @@ binary -> expression operator expression ; operator -> | "==" | "!=" | "<" | "<=" | ">" | ">=" | "+" | "-" | "*" | "/" -// | "|>" | "<|" | ">>" | "<<" + | "|>" | "<|" | ">>" | "<<" | "++" ; +pattern -> "_" | record_pattern | variant_pattern | identifier ; +record_pattern -> "{" ( identifier ( "=" pattern )? ( "," identifier ( "=" pattern )? )* ) ( "|" identifier ) "}" +variant_pattern -> "`" identifier ( "(" ( "_" | compound_pattern | identifier ) ")" )? ; +let -> "let" pattern "=" expression ( "and" pattern "=" expression )* "in" expression ; control -> | if | when if -> "if" expression "then" expression "else" expression ; -variant_pattern -> "`" identifier ( "(" ( ( "_" | identifier ) ( "," ( "_" | identifier )* )? ) ")" )? ; -when -> "when" expression "is" ( variant_pattern "=>" expression )+ ; +when -> "when" expression "is" ( pattern "=>" expression )+ ; compound -> variant | record | list ; -variant -> "`" identifier ( "(" ( expression ( "," expression)* )? ")" )? ; +variant -> "`" identifier ( "(" expression ")" )? ; base_record -> expression ( "with" identifier "=" expression ( "," "with" identifier "=" expression )* )? record -> "{" ( identifier ("=" expression)? ( "," identifier ("=" expression)? )* )? ( "|" base_record )* "}" ;