-
Notifications
You must be signed in to change notification settings - Fork 4
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
Parse simple programs (integer, string, float, or rational) with Prism #25
Conversation
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.
A great start, nice work!
I've added a bunch of comments. They can be addressed now or later, since this is WIP I'm not overly worried about them at this point. Most of them were just to convey information as opposed to request changes.
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.
Sick!!!
main/pipeline/pipeline.cc
Outdated
|
||
unique_ptr<parser::Node> parseTree; | ||
|
||
if (parser == "prism") { |
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.
Could you please switch this to a switch
(pun intended), and add a default
case that errors-out?
If we hit that, it indicates that we changed main/options/options.cc
, but forgot to handle the new value here.
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.
So I attempted to implement this because it makes sense, but I realized that Sorbet is implemented in a way that would actually make it impossible to reach the default
part of the switch statement. I can program the options.cc
file to recognize if an invalid parser option is passed, then just use the default option (sorbet
) instead, making any further processing unnecessary.
9d23383
to
9adc704
Compare
…et or prism If `--parser=prism`, diverge in the `pipeline.cc` file and run a separate method that parses the source with prism.
This involves setting up a `convertPrismToSorbet` method that checks against every possible node type. Program and Statements are basically skipped because Sorbet doesn't use them, and then Integer is converted from a prism node to a Sorbet node. Co-authored-by: Vinicius Stock <vinicius.stock@shopify.com>
@Morriar @amomchilov @KaanOzkan how would you feel about merging this? I'm setting up an automated testing pipeline but the changes are going to be somewhat significant because testing with Bazel is complicated 😓 I don't want to have to add a lot more changes to this PR if I don't have to. |
This PR is best read commit-by-commit.
Motivation
--parser=prism
flag to the Sorbet CLI options, allowing the user to choose to parse with PrismProgram
,Statement
,Integer
,Float
,Rational
, andString
nodes 😁Manual tests
You should be able to compile Sorbet:
Then typecheck any Ruby program that is ONLY an integer, string, rational, or float, e.g.:
Automated tests
Still working on this part!