-
Notifications
You must be signed in to change notification settings - Fork 289
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
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…to clean-up-invalid
for more information, see https://pre-commit.ci
This reverts commit 310df05.
Need to improve the command extraction (maybe rewrite it entirely than trying to improve what we have now!) |
for more information, see https://pre-commit.ci
…to clean-up-invalid
There was a problem hiding this 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?? |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better name too!
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). |
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). |
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 :)