From 97ec5772fd977b5836097c115bc7a2c072a093b6 Mon Sep 17 00:00:00 2001 From: JJ Date: Mon, 24 Jul 2023 23:05:19 -0700 Subject: docs: attempt to define scope (to revisit after implementation) --- docs/SYNTAX.md | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/docs/SYNTAX.md b/docs/SYNTAX.md index 8f6edb2..49fdd59 100644 --- a/docs/SYNTAX.md +++ b/docs/SYNTAX.md @@ -8,7 +8,7 @@ We now shall take a look at a more formal description of Puck's syntax. Syntax r ### Identifiers ``` -IDENT ::= LETTER (LETTER | DIGIT | '_')* +IDENT ::= LETTER (LETTER | DIGIT | '_')* # todo: support _ LETTER ::= 'A'..'Z' | 'a'..'z' | '\x80'..'\xff' # todo DIGIT ::= '0'..'9' ``` @@ -94,19 +94,19 @@ INTERFACE ::= 'interface' '[' SIGNATURE (',' SIGNATURE)* ('for' TYPE_DESC)? '] ## Control Flow ``` -IF_EXPR ::= 'if' EXPR ':' EXPR ('elif' EXPR ':' EXPR)* 'else' ':' EXPR -IF_STMT ::= 'if' EXPR ':' STMT ('elif' EXPR ':' STMT)* ('else' ':' STMT)? -WHEN_EXPR ::= 'when' EXPR ':' EXPR ('else' ':' EXPR)? -WHEN_STMT ::= 'when' EXPR ':' STMT ('else' ':' STMT)? -BLOCK_EXPR ::= 'block' IDENT? ':' EXPR -BLOCK_STMT ::= 'block' IDENT? ':' STMT -MATCH_EXPR ::= 'match' EXPR ':' - ('case' EXPR ('where' EXPR)? (',' EXPR ('where' EXPR)?)* ':' EXPR)+ -MATCH_STMT ::= 'match' EXPR ':' - ('case' EXPR ('where' EXPR)? (',' EXPR ('where' EXPR)?)* ':' STMT)+ -LOOP_STMT ::= 'loop' ':' STMT -WHILE_STMT ::= 'while' EXPR ':' STMT -FOR_STMT ::= 'for' GROUP 'in' EXPR ':' STMT +IF_EXPR ::= 'if' EXPR '{' EXPR '}' ('elif' EXPR '{' EXPR '}')* 'else' '{' EXPR '}' +IF_STMT ::= 'if' EXPR '{' STMT '}' ('elif' EXPR '{' STMT '}')* ('else' '{' STMT '}')? +WHEN_EXPR ::= 'when' EXPR '{' EXPR '}' ('elif' EXPR '{' EXPR '}')* 'else' '{' EXPR '}' +WHEN_STMT ::= 'when' EXPR '{' STMT '}' ('elif' EXPR '{' EXPR '}')* ('else' '{' STMT '}')? +BLOCK_EXPR ::= 'block' IDENT? '{' EXPR '}' +BLOCK_STMT ::= 'block' IDENT? '{' STMT '}' +MATCH_EXPR ::= 'match' EXPR '{' + ('case' EXPR ('where' EXPR)? (',' EXPR ('where' EXPR)?)* '{' EXPR '}')+ '}' +MATCH_STMT ::= 'match' EXPR '{' + ('case' EXPR ('where' EXPR)? (',' EXPR ('where' EXPR)?)* '{' STMT '}')+ '}' +LOOP_STMT ::= 'loop' '{' STMT '}' +WHILE_STMT ::= 'while' EXPR '{' STMT '}' +FOR_STMT ::= 'for' GROUP 'in' EXPR '{' STMT '}' ``` ## Modules @@ -115,14 +115,14 @@ IMPORT_STMT ::= 'import' IDENT_AS? ('/' (IDENT_AS | '[' (IDENT_AS (',' IDENT_AS)*)? ']'))* EXPORT_STMT ::= 'export' IDENT_AS? ('/' (IDENT_AS | '[' (IDENT_AS (',' IDENT_AS)*)? ']'))* -MODULE_STMT ::= 'module' IDENT ':' STMT +MODULE_STMT ::= 'module' IDENT '{' STMT '}' IDENT_AS ::= IDENT ('as' IDENT)? ``` ## Macros ``` MACRO_FUNC ::= IDENT '(' EXPR ')' -MACRO_BLOCK ::= IDENT ':' EXPR # todo +MACRO_BLOCK ::= IDENT '{' EXPR '}' # todo ``` ## Calls, Statements, and Expressions @@ -130,18 +130,17 @@ MACRO_BLOCK ::= IDENT ':' EXPR # todo OPERATION ::= EXPR OPERATOR EXPR PREFIX ::= OPERATOR EXPR SUFFIX ::= EXPR OPERATOR -APPLICATION ::= IDENT EXPR | IDENT PARAMS? | (IDENT | APPLICATION) '.' IDENT PARAMS? +APPLICATION ::= IDENT PARAMS? | IDENT EXPR | (APPLICATION | PREFIX | SUFFIX) '.' IDENT PARAMS? PARAMS ::= '(' ((IDENT '=')? EXPR (',' (IDENT '=')? EXPR)*)? ')' ``` ``` -STMT ::= SINGLE_STMT | STMT+ -SINGLE_STMT ::= IF_STMT | WHEN_STMT | BLOCK_STMT | MATCH_STMT | - LOOP_STMT | WHILE_STMT | FOR_STMT | - IMPORT_STMT | EXPORT_STMT | MODULE_STMT | - DECL | (EXPR ';') -EXPR ::= IF_EXPR | WHEN_EXPR | BLOCK_EXPR | MATCH_EXPR | - MACRO_FUNC | MACRO_BLOCK | - APPLICATION | OPERATION | PREFIX | SUFFIX | - VALUE | (STMT EXPR) +EXPR ::= IF_EXPR | WHEN_EXPR | BLOCK_EXPR | MATCH_EXPR | + MACRO_FUNC | MACRO_BLOCK | + APPLICATION | OPERATION | PREFIX | SUFFIX | + VALUE | (STMT EXPR) # todo +STMT ::= IF_STMT | WHEN_STMT | BLOCK_STMT | MATCH_STMT | + LOOP_STMT | WHILE_STMT | FOR_STMT | + IMPORT_STMT | EXPORT_STMT | MODULE_STMT | + ((APPLICATION | OPERATION | PREFIX | SUFFIX | DECL) ';') | (STMT+ STMT) ``` -- cgit v1.2.3-70-g09d2