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

[CHORE] move exceptions into isvalid #4838

Merged
merged 35 commits into from
Dec 7, 2023
Merged

[CHORE] move exceptions into isvalid #4838

merged 35 commits into from
Dec 7, 2023

Conversation

Felienne
Copy link
Member

@Felienne Felienne commented Dec 1, 2023

First step towards #4836

This PR cleans up the handling of exceptions a lot! As I explained in #4836 I think I initially was planning to create a function that would return a boolean, is this tree valid or not, with a transformer. But as the code got more advanced, and more experience people worked in it, we started to use exceptions more and it became a bit of a mess.

This trigger for this specific refactoring was there was not an easy way to call one function to detect if a tree was valid, which is needed for the new translation mechanism. So it does not fully close #4836 as I still have to call it on the translation part but this is already quite big and hard to review so let's do that separately.

How to test
Verify nothing breaks :)

hedy.py Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Dec 1, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@Felienne Felienne requested a review from jpelay December 5, 2023 05:04
@Felienne Felienne marked this pull request as ready for review December 5, 2023 05:12
@Felienne Felienne marked this pull request as draft December 5, 2023 12:07
@Felienne
Copy link
Member Author

Felienne commented Dec 5, 2023

Need to improve the command extraction (maybe rewrite it entirely than trying to improve what we have now!)

@Felienne Felienne marked this pull request as ready for review December 6, 2023 09:25
@Felienne
Copy link
Member Author

Felienne commented Dec 6, 2023

Hi @jpelay!

I think I managed to clean all up now! Can you take a look when you have the chance, because this will cause annoying changes to other PRs (such as #4848 ) Thanks! 🙏

Copy link
Member

@jpelay jpelay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this change! It simplifies the process a lot and cleans the code very nicely. Also, everything seems to work correctly. Great work :D

@@ -63,7 +63,7 @@ def __init__(self, level, line_number, fixed_code, fixed_result):
level=level,
line_number=line_number,
fixed_code=fixed_code,
fixed_result=fixed_result)
fixed_result=fixed_result) # what is the difference??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed code holds the fixed hedy code, f.e: print hello world. Fixed result holds the ParseResult object of parsing that code

raise exceptions.MissingCommandException(level=level, line_number=line)
# IsValid raises the appropriate exception when an error production (starting with error_)
# is found in the parse tree
IsValid(level, lang, input_string).transform(program_root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much better way of doing this!

if level > HEDY_MAX_LEVEL:
raise Exception(f'Levels over {HEDY_MAX_LEVEL} not implemented yet')

def create_AST(input_string, level, lang="en"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name too!

Copy link
Contributor

mergify bot commented Dec 7, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 4c59da4 into main Dec 7, 2023
11 checks passed
@mergify mergify bot deleted the clean-up-invalid branch December 7, 2023 17:22
Copy link
Contributor

mergify bot commented Dec 7, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@ToniSkulj ToniSkulj mentioned this pull request Dec 9, 2023
mergify bot pushed a commit that referenced this pull request Dec 11, 2023
Fixes #4863.

After #4838, the processing of the string was done after setting the input string on the source map.
This led to 2 tests failing.

This PR first uses process_input_string before setting the input on the source map. Fixing the failing tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CHORE] refactor isvalid
2 participants