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

Support -p, -n, -a, and -l command line options #2511

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Support -p, -n, -a, and -l command line options #2511

merged 1 commit into from
Feb 27, 2024

Conversation

kddnewton
Copy link
Collaborator

The current CRuby parser supports these options by mutating the AST. I don't want to do that, and instead would prefer to do it in the compiler. But that work is for another day, and this will be far easier than wading into those waters. So instead, we now support the following options:

  • command_line_p
  • command_line_n
  • command_line_a
  • command_line_l

These correspond with the respective command line flags. They mutate the AST such that you get back what would be executed (this pretty much exactly matches what the current parser does).

cc @enebo, @eregon, @seven1m — you may want to use these or you may not. I'm assuming all of you currently have your own solutions for this. It's not that much code at the end of the day so entirely up to you.

Fixes #2002

@kddnewton kddnewton merged commit 65d492f into main Feb 27, 2024
53 of 55 checks passed
@kddnewton kddnewton deleted the cli branch February 27, 2024 04:22
@eregon
Copy link
Member

eregon commented Feb 27, 2024

This looks convenient, we should try it, cc @andrykonchin.
I remember when we implemented (more of) these flags in TruffleRuby (years ago) we were wondering if we could do it by just prepending/appending code around the input code but that didn't fly for some reason (I don't recall why, maybe simply because it would cause all node locations to be wrong, but with this that shouldn't be an issue).

@enebo
Copy link
Collaborator

enebo commented Feb 27, 2024

@kddnewton Nice! I manually write the syntax tree around the contents of -e but being able to delete that code would be a nice simplification.

JRuby-proper is written around wrapping these nodes around something already parsed so I have to look at how easy it will be to achieve this as part of the original parse call (obviously old parser does not work this way so I need to consider that as well).

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.

Support -n, -p, -l, and -a command-line options
3 participants