Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: If statement initializers #23

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/syntax-if-statements-initializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,24 @@ end

# Design

If statements with initializers must match (following the Luau grammar) `'if' 'local' bindinglist ['=' explist] 'then'` and `'local' bindinglist ['=' explist] where exp 'then'` syntax. The variables declared by an initializer are only available to the if statement's blocks; any code after the if statement won't have the variables defined.
If statements with initializers must match the below grammar. The variables declared by an initializer are only available to the if statement's blocks; any code after the if statement won't have the variables defined.

```diff
stat = varlist '=' explist |
...
'repeat' block 'until' exp |
- 'if' exp 'then' block {'elseif' exp 'then' block} ['else' block] 'end' |
+ 'if' cond 'then' block {'elseif' cond 'then' block} ['else' block] 'end' |
'for' binding '=' exp ',' exp [',' exp] 'do' block 'end' |
...

- ifelseexp = 'if' exp 'then' exp {'elseif' exp 'then' exp} 'else' exp
+ ifelseexp = 'if' cond 'then' exp {'elseif' cond 'then' exp} 'else' exp

TheGreatSageEqualToHeaven marked this conversation as resolved.
Show resolved Hide resolved
+ cond = 'local' binding '=' exp ['where' exp] |
+ 'local' bindinglist '=' explist 'where' exp |
+ exp
```

In the former case, the value of the first declared variable will be checked.

Expand Down