Add Rust API for parsing with scope locals (eval/binding support) #4103
sisshiki1969
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone — monochrome here, building a Ruby implementation + JIT in Rust from scratch over at monoruby.
Motivation
I recently switched monoruby's parser to Prism, but I had to use Prism from a fork because there's no Rust-side API for passing scope locals (the surrounding binding's variable names) into the parser. That's needed for
Kernel#eval/Binding#eval, where an identifier might be either a local from the outer scope or a method call — Prism needs the local names to disambiguate.The C side already has all the machinery (pm_options_*, pm_options_scope_t); it just isn't exposed through ruby-prism-sys / ruby-prism.
Proposed change
ruby-prism-sys:
extend the bindgen allowlist for the missing symbols (
pm_options_free,pm_options_line_set,pm_options_scope_init,pm_options_scope_forwarding_set,pm_options_scopes_init,pm_string_constant_init).ruby-prism:
add
Options,Scope, andparse_with_options().Usage on the Rust side:
A working version is on the monoruby branch of sisshiki1969/prism (~240 lines vs v1.9.0, no C / build-script changes).
Diff is here.
If this looks reasonable I'd be happy to send a PR.
Any feedback on the API shape before I do?
Beta Was this translation helpful? Give feedback.
All reactions