Skip to content

Commit

Permalink
Added new grammar for try/catch + let else
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Feb 13, 2024
1 parent f7a3baa commit ee875f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions guide/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Prefix:
Continue |
Break |
Return |
Match> | Term;
Match |
Try> | Term;
Literal: 'true' | 'false';
Expand Down Expand Up @@ -121,8 +122,10 @@ ArrowBody: '=>' <Expression>;
BlockBody: '{' <Chain> '}';
FnMatch: '{' <MatchBody> '}';
Let: 'let' <Pattern> '=' <Expression>;
Var: 'var' <Pattern> '=' <Expression>;
Let: 'let' <VariablePattern>;
Var: 'var' <VariablePattern>;
VariablePattern: <GuardedPattern> '=' <Expression> <VariableElse>?;
VariableElse: 'else' <Expression>;
If: 'if' <Expression> <ThenExpression | Block> <ElseExpression>?;
ThenExpression: 'then' <Expression>;
Expand All @@ -138,7 +141,8 @@ Continue: 'continue' <Label>?;
Break: 'break' <Label>? <Expression>?;
Return: 'return' <Expression>?;
Match: 'match' <Expression> '{' <MatchBody> '}';
Match: 'match' <Expression> <MatchBlock>;
MatchBlock: '{' <MatchBody> '}';
MatchBody: (<MatchPattern> (',' <MatchPattern>)*)?;
MatchPattern: <GuardedPattern> '=>' <Expression>;
GuardedPattern: <Pattern> ('if' <Expression>)?;
Expand All @@ -147,5 +151,9 @@ IdentifierPattern: '_' | <Identifier>;
TuplePattern: '(' (<Pattern> (',' <Pattern>)*)? ')';
ListPattern: '[' (<Pattern> (',' <Pattern>)*)? ']';
Try: 'try' <Expression> ('catch' <MatchBlock | SingleCatch | ArrowCatch>)?;
SingleCatch: <GuardedPattern> <Block>;
ArrowCatch: '=>' <Expression>;
Term: <Identifier | Number | Regex | String | Symbol>;
```
6 changes: 4 additions & 2 deletions guide/src/reference/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
```musebnf
Assignment: <Lookup | Index> ('=' <Assignment>)*;
Let: 'let' <Pattern> '=' <Expression>;
Var: 'var' <Pattern> '=' <Expression>;
Let: 'let' <VariablePattern>;
Var: 'var' <VariablePattern>;
VariablePattern: <GuardedPattern> '=' <Expression> <VariableElse>?;
VariableElse: 'else' <Expression>;
```
4 changes: 4 additions & 0 deletions guide/src/reference/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
```musebnf
TryOperator: '?' <Punctuation>?;
NilCoalesce: '??' <Punctuation>;
Try: 'try' <Expression> ('catch' <MatchBlock | SingleCatch | ArrowCatch>)?;
SingleCatch: <GuardedPattern> <Block>;
ArrowCatch: '=>' <Expression>;
```

0 comments on commit ee875f8

Please sign in to comment.