forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🖊️ Improved error message for missing colons in level 17 (hedyorg#5465)
- Add preprocessing rules which take an argument in order to allow for a rule to turn into an error without copying the old rule definition. For example, `error_ifelse<old_rule_to_error ifelse>` is used in level 8 to transform the old flat if-else to an error. - Add errors for if-else statements, loops and function definitions missing a colon in level 17 Fixes hedyorg#5222 **How to test** - Automated tests are added for the new preprocessing functionality and for the commands missing colons in level 17. - To see the error message, run the following program in level 17 and try removing any of the colons at a time. The message should direct you to the right line. ``` define function with b: i = 1 while i < b: print i i = i + 1 b = 10 if b is 1: call function with b elif b is 2: call function with b else: call function with b if b is pressed: call function with b elif c is pressed: call function with b else: call function with b ```
- Loading branch information
1 parent
828a928
commit 74a94fc
Showing
61 changed files
with
638 additions
and
157 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
// We add the : at the end of if and else and elif and for/while | ||
// In this level we add a colon to if-else statements, function definitions, and loops. | ||
// The `<rule_name>` syntax specifies a preprocessor rule which would be applied in the grammar merger. | ||
// The merger will find the appropriate function for this annotation and modify it accordingly. | ||
// The preprocessor can also accept a parameter via the syntax <rule_name argument>. | ||
|
||
command: += if_pressed (if_pressed_elifs)* if_pressed_elses? | ifs (elifs)* elses? -= ifs elses? | ||
command: += (if_pressed | if_pressed_no_colon) (if_pressed_elifs | if_pressed_elifs_no_colon)* (if_pressed_elses | if_pressed_elses_no_colon)? | (ifs | ifs_no_colon) (elifs | elifs_no_colon)* (elses | elses_no_colon)? | for_list_no_colon | for_loop_no_colon | while_loop_no_colon | define_no_colon -= ifs elses? | ||
|
||
// These will be handled by the preprocessor step in the merger | ||
// It will find the appropiate function for this anotation and modify it accordingly | ||
if_pressed<needs_colon> | ||
if_pressed_no_colon<old_rule_to_error if_pressed> | ||
|
||
if_pressed_else<needs_colon> | ||
|
||
if_pressed_elses<needs_colon> | ||
if_pressed_elses_no_colon<old_rule_to_error if_pressed_elses> | ||
|
||
if_pressed_elifs: _EOL _ELIF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _COLON _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK | ||
if_pressed_elifs_no_colon: _EOL _ELIF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK | ||
|
||
|
||
|
||
ifs<needs_colon> | ||
ifs_no_colon<old_rule_to_error ifs> | ||
|
||
elses<needs_colon> | ||
elses_no_colon<old_rule_to_error elses> | ||
|
||
elifs: _EOL _ELIF _conditions _COLON _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK | ||
elifs_no_colon: _EOL _ELIF _conditions _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK | ||
|
||
|
||
|
||
for_list<needs_colon> | ||
for_list_no_colon<old_rule_to_error for_list> | ||
|
||
for_loop<needs_colon> | ||
for_loop_no_colon<old_rule_to_error for_loop> | ||
|
||
while_loop<needs_colon> | ||
while_loop_no_colon<old_rule_to_error while_loop> | ||
|
||
define<needs_colon> | ||
define_no_colon<old_rule_to_error define> |
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
Oops, something went wrong.