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

🧹 Refactor Pygame Code #5117

Merged
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
70f3986
Change making of if_pressed_command
ToniSkulj Feb 9, 2024
9f600b5
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
ToniSkulj Feb 9, 2024
dcc9d39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
1d4e1c6
Make if_pressed command return promise
ToniSkulj Feb 9, 2024
af04886
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
ToniSkulj Feb 9, 2024
cae61ae
Refactor making if_pressed command
Feb 23, 2024
42024b1
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
ToniSkulj Feb 23, 2024
a42ad4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
7340661
update level 5 tests
Felienne Feb 23, 2024
222698f
Merge branch '3966-chore-remove-superflous-code-in-generated-pygame-c…
Felienne Feb 23, 2024
1a0f248
[CHORE] Renamd pygame-modal to keybinding-modal since PyGame dependen…
Feb 9, 2024
6de5bd9
[CHORE] renamed translation key from to
Feb 9, 2024
4a2caad
[CHORE] removed pygame dependencies from frontend if-pressed feature
Feb 9, 2024
18704aa
[CHORE] removed PyGame-skulpt frontend libraries
Feb 9, 2024
171252f
update level 5 tests
Feb 23, 2024
7ab00fc
Change grammar for if_pressed
Feb 29, 2024
3f07fc0
Change hedy.py logic
Feb 29, 2024
a9be00b
Change pressed prefix
Feb 29, 2024
97e1d96
Remove/rename everything pygame related
Feb 29, 2024
186cd6b
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
Feb 29, 2024
f493ff8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 29, 2024
98a11a7
Fix if pressed key is number
Feb 29, 2024
5120f37
Change if pressed function names
Feb 29, 2024
e70207d
add possibility to use variables & change function naming
Feb 29, 2024
a9f1dc6
Remove extra line ending after extension call
Feb 29, 2024
5462314
Update tests level 5
Feb 29, 2024
da49cc2
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
Mar 4, 2024
60ecb72
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
Felienne Mar 12, 2024
827417d
fix text level 7
Felienne Mar 12, 2024
285446a
🤖 Automatically update generated files
Felienne Mar 12, 2024
8a799bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2024
0061806
level 8
Felienne Mar 12, 2024
fcbc71b
level 9
Felienne Mar 12, 2024
b95989d
level 10
Felienne Mar 12, 2024
ac138b8
level 11 & 12
Felienne Mar 12, 2024
beaf735
Merge branch '3966-chore-remove-superflous-code-in-generated-pygame-c…
Felienne Mar 12, 2024
6e46614
levels 15 to 17
Felienne Mar 12, 2024
7330b7d
level 18
Felienne Mar 12, 2024
cf28bce
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
Mar 14, 2024
5c87d01
Fix tests for level 7, 8 & 17
Mar 14, 2024
4181688
🤖 Automatically update generated files
ToniSkulj Mar 14, 2024
bfbbf8d
Remove uuid import
Mar 14, 2024
535d7e4
Merge branch '3966-chore-remove-superflous-code-in-generated-pygame-c…
Mar 14, 2024
27667a8
deleting unnecessary file
jpelay Mar 26, 2024
c6ca987
Fix animation when pressing keys
jpelay Mar 26, 2024
9b38b2e
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
jpelay Mar 26, 2024
b737b9b
🤖 Automatically update generated files
jpelay Mar 26, 2024
e9bb4e6
see if this makes the linter happy
jpelay Mar 27, 2024
6d9e53c
keep making the linter happy
jpelay Mar 27, 2024
8e7b838
Update test_level_12.py
jpelay Mar 27, 2024
22dd162
Another unterminated string
jpelay Mar 27, 2024
23a5e96
fix tests
jpelay Mar 27, 2024
7b8c90e
Merge branch 'main' into 3966-chore-remove-superflous-code-in-generat…
jpelay Mar 27, 2024
d4d7d3d
🤖 Automatically update generated files
jpelay Mar 27, 2024
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
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ def parse():

response['source_map'] = source_map_result

if transpile_result.has_pygame:
response['has_pygame'] = True
if transpile_result.has_pressed:
response['has_pressed'] = True

if transpile_result.has_turtle:
response['has_turtle'] = True
Expand Down
4 changes: 2 additions & 2 deletions build-tools/heroku/generate-prefixes-ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cat <<EOF > $python_prefix_ts
*
* !!! THIS FILE HAS BEEN GENERATED. DO NOT EDIT !!!
*
* Make desired changes to prefixes/{normal,pygame,turtle,music}.py
* Make desired changes to prefixes/{normal,pressed,turtle,music}.py
*
* Add/edit tests for those changes in tests/test_python_prefixes.py
*
Expand All @@ -19,7 +19,7 @@ cat <<EOF > $python_prefix_ts
*******************************************************************************/
EOF

for prefix in turtle pygame normal music; do
for prefix in turtle pressed normal music; do
echo >> $python_prefix_ts
echo "export const ${prefix}_prefix = " >> $python_prefix_ts
echo -n '`' >> $python_prefix_ts
Expand Down
2 changes: 1 addition & 1 deletion grammars/level15-Additions.lark
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
command: += while_loop | ifpressed -= error_ifpressed_missing_else >> error_ifelse | ifs
command: += while_loop | if_pressed -= error_if_pressed_missing_else >> error_ifelse | ifs

// new : while loop
while_loop: _WHILE (_conditions) _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
Expand Down
9 changes: 5 additions & 4 deletions grammars/level17-Additions.lark
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// We add the : at the end of if and else and elif and for/while

command: += ifpressed (ifpressed_elifs)* ifpressed_elses? | ifs (elifs)* elses? -= ifs elses?
command: += if_pressed (if_pressed_elifs)* if_pressed_elses? | ifs (elifs)* elses? -= 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
ifpressed_else<needs_colon>
ifpressed<needs_colon>
ifpressed_elifs: _EOL _ELIF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _COLON _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
if_pressed<needs_colon>
if_pressed_else<needs_colon>
if_pressed_elses<needs_colon>
if_pressed_elifs: _EOL _ELIF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _COLON _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK

ifs<needs_colon>
elses<needs_colon>
Expand Down
7 changes: 4 additions & 3 deletions grammars/level5-Additions.lark
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _empty_program: (_EOL | _SPACE)*
_non_empty_program: _EOL* (command | error_invalid) _SPACE* (_EOL+ command _SPACE*)* _EOL* //lines may end on spaces and might be separated by many newlines

//placing assign after print means print is will print 'is' and print is Felienne will print 'is Felienne'
command: += assign_button | ifpressed_else | error_ifpressed_missing_else | ifelse | ifs -= error_invalid >> assign
command: += assign_button | if_pressed_else | error_if_pressed_missing_else | if_pressed_without_else | ifelse | ifs -= error_invalid >> assign
_if_less_command: print | ask | play | turtle | assign_button | assign_list | add | remove | sleep | error_print_no_quotes | assign

// error_invalid is moved from to command to program, so that command rules have priority over error_invalid
Expand All @@ -21,8 +21,9 @@ assign: var _IS (list_access | textwithspaces)
error_print_no_quotes: _PRINT (textwithoutspaces | list_access | var_access) (_SPACE (textwithoutspaces | list_access | var_access))* -> error_print_nq

// new commands for level 5
ifpressed_else: _IF (LETTER_OR_NUMERAL | var) _IS _PRESSED _EOL* _if_less_command (_SPACE+ _EOL* | _SPACE* _EOL+) _ELSE (_SPACE+ _EOL* | _SPACE* _EOL+) _if_less_command
error_ifpressed_missing_else: _IF (LETTER_OR_NUMERAL | var) _IS _PRESSED _EOL* _if_less_command
if_pressed_else: _IF (LETTER_OR_NUMERAL | var) _IS _PRESSED _EOL* _if_less_command (_SPACE+ _EOL* | _SPACE* _EOL+) _ELSE (_SPACE+ _EOL* | _SPACE* _EOL+) _if_less_command
if_pressed_without_else: _IF (LETTER_OR_NUMERAL | var) _IS _PRESSED _EOL* _if_less_command
error_if_pressed_missing_else: if_pressed_without_else

_if_clause: _IF (condition (_SPACE+ _EOL* | _SPACE* _EOL+) | condition_spaces _SPACE* _EOL+ | error_condition) _if_less_command
error_condition: condition_spaces _SPACE
Expand Down
2 changes: 1 addition & 1 deletion grammars/level6-Additions.lark
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _print_argument: (_SPACE | quoted_text | list_access | expression | print_expres
?print_expression: var_access_print | error_unsupported_number | INT

// redefining it entirely since it has many order-depending rules
command: clear | error_non_decimal | print | turtle | play | add | remove | error_add_missing_to | error_remove_missing_from | sleep | error_print_no_quotes | error_print_one_quote_only | ifpressed_else | error_ifpressed_missing_else | ifelse | ifs | ask | error_ask_no_quotes| assign_button | assign | assign_list | error_invalid_space | error_text_no_print | empty_line
command: clear | error_non_decimal | print | turtle | play | add | remove | error_add_missing_to | error_remove_missing_from | sleep | error_print_no_quotes | error_print_one_quote_only | if_pressed_else | error_if_pressed_missing_else | if_pressed_without_else | ifelse | ifs | ask | error_ask_no_quotes| assign_button | assign | assign_list | error_invalid_space | error_text_no_print | empty_line
_if_less_command: print | turtle | play | add | remove | sleep | error_print_no_quotes | error_print_one_quote_only | ask | error_ask_no_quotes | assign_button | assign | assign_list

//splitting these commands into two rules, one for equals and one for is so they can be properly handled in the translator
Expand Down
12 changes: 6 additions & 6 deletions grammars/level8-Additions.lark
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
command: += error_repeat_dep_8 | error_ifelse | error_ifpressed_missing_else | ifpressed ifpressed_elses? | ifs elses? -= error_invalid_space | ifelse
command: += error_repeat_dep_8 | error_ifelse | if_pressed_without_else | if_pressed if_pressed_elses? | ifs elses? -= error_invalid_space | ifelse

repeat.1: _REPEAT (INT | var_access) _TIMES _SPACE? _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
error_repeat_dep_8: _REPEAT (INT | var_access) _TIMES _SPACE command
Expand All @@ -7,14 +7,14 @@ error_repeat_dep_8: _REPEAT (INT | var_access) _TIMES _SPACE command
// not sure of we want it, but we could
equality_check: (textwithoutspaces | NUMBER) (_IS | _EQUALS) (textwithoutspaces | NUMBER) (_SPACE | textwithoutspaces | NUMBER)*

// from level 8 on ifpressed is implemented slightly differently
ifpressed: _IF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
ifpressed_else: _IF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK (_SPACE)* _ELSE (_SPACE)* _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
error_ifpressed_missing_else: ifpressed
// from level 8 on if_pressed is implemented slightly differently
if_pressed: _IF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
if_pressed_else: _IF (LETTER_OR_NUMERAL | NAME) _IS _PRESSED _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK (_SPACE)* _ELSE (_SPACE)* _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
if_pressed_without_else: if_pressed

// from level 8 on if is implemented slightly differently
elses: _EOL (_SPACE)* _ELSE (_SPACE)* _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
ifpressed_elses: elses
if_pressed_elses: _EOL (_SPACE)* _ELSE (_SPACE)* _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK
//'if' cannot be used in Python, hence the name of the rule is 'ifs'
ifs: _IF condition _EOL (_SPACE command) (_EOL _SPACE command)* _EOL? _END_BLOCK

Expand Down
Loading
Loading