-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Using multiple loops with "if pressed" command (#4028)
Will fix #3865, The Good ✅: This PR makes it possible to encapsulate multiple _if pressed_ commands with a _repeat_, _for loop_ & _while loop_ **from level 9 onwards** , notice that this is the general problem that is discovered in #3865. <details> <summary>Some Examples</summary> ### Level 9 ```python repeat 3 times if x is pressed forward 15 repeat 3 times if y is pressed forward 15 repeat 3 times if z is pressed forward 15 ``` ### Level 10 ```python animals is dog, cat, blobfish for animal in animals if x is pressed print animal for animal in animals if y is pressed print animal for animal in animals if z is pressed print animal ``` ### Level 15 ```python answer = 0 while answer != 20 if x is pressed answer = answer + 10 print "Answer raise by 10!" while answer != 60 if y is pressed answer = answer + 20 print "Answer raise by 20!" ``` </details> The Bad ❗: There is still an issue with the original problem in level 7. For some (unknown) reason when running: ``` repeat 3 times if x is pressed forward 15 repeat 3 times if y is pressed forward 15 repeat 3 times if z is pressed forward 15 ``` The parser translates the second line to: ``` if 'y' == 'pressed forward 15': ``` Essentially, a 'normal' if statement. To make it a bit more complicated, this only happens when there are more than 2 loops. The example: ``` repeat 3 times if x is pressed forward 15 repeat 3 times if y is pressed forward 15 ``` Works fine. What I Know 🔍: The parser uses the _condition_spaces_ rule found in _level5-Additions.lark_ for the failing example above, because of that it becomes a _ifs_ rule, instead of a _ifpressed_ rule. I have tried to figure out why and how to fix it but no luck... @Felienne, @jpelay I hope it's okay to ask some help from you (cause I'm sort of stuck)! Will post updates here if I discover something!
- Loading branch information
Showing
4 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters