-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement while statement parsing and evaluation #22
Conversation
Intern basic parser types - Number, String, Bool, any - to make pointer comparison trivial without requiring deep comparison.
Visit the preview URL for this PR (updated for commit 6284a93): https://evy-lang--pr22-while-9nzpficc.web.app (expires Tue, 11 Oct 2022 22:45:20 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
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.
Really nice. I like how simple it is to add the while construct. Confirms that you have a good parsing structure in place. 🐉
pkg/evaluator/scope.go
Outdated
return nil, false | ||
} | ||
if _, ok := s.values[name]; ok { | ||
return s, ok |
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.
nit: I would make this return s, true
. Since ok
is always true in this branch, the literal makes it easier to read and understand at a glance.
Fix setting variable value in correct scope. The variable value needs to be updated in the scope the variable was declared rather than in the current scope so that an update inside a block is still available when the block has terminated.
Ensure the value of a `return` is propagated along with whether a conditional block was executed as `val, ok`. Previously we only returned TRUE or FALSE for branch taken or not which swallowed returned statements.
Implement while statement parsing and evaluation. Reuse conditional Block execution from If-statements parsing and evaluation and factor out shared code.
Implement while statement parsing and evaluation by reusing conditional
Block execution from If-statements parsing and evaluation and factor
out shared code.
Fix various bugs that popped up while implementing while statements: