Actions
Feature #19719
closedUniversal Parser
Feature #19719:
Universal Parser
Status:
Closed
Assignee:
-
Target version:
-
Description
Background¶
There are three use cases where we need a CRuby parser which is independent of other CRuby features like Object, GC. I call such a parser a Universal Parser.
- Use Universal Parser from Ruby applications.
For example RuboCop. RuboCop needs a parser to get AST of source code. Currently RuboCop uses parser gem. In this sense Universal Parser is a replacement of parser gem. - Use Universal Parser from C/C++ or other language.
For example Sorbet. Sorbet is written in C++. It has its own parser. Universal Parser can be used in such scenario. - Use Universal Parser for other Ruby implementations.
mruby, JRuby and other Ruby implementations will use Universal Parser so that they don’t need to develop & manage their own parser.
Design¶
- Implement Universal Parser by changing CRuby source code, especially parse.y and node.c.
IntroduceUNIVERSAL_PARSER
macro and implement Universal Parser by passing all necessary CRuby related functions viastruct rb_parser_config_struct
. In this step there are two build modes with/without Universal Parser. - Reduce CRuby related functions passed by
struct rb_parser_config_struct
. Some of them are copied into parse.y, e.g.rb_isspace
. Other are reimplemented, e.g.NODE_LIT
has new String struct instead ofVALUE
. - Once CRuby related functions needed for Universal Parser are minimized, replace rest CRuby function references with functions provided by
struct rb_parser_config_struct
and removeUNIVERSAL_PARSER
macro.
Release management¶
There are three options for releasing a binary for Universal Parser (“librubyparser”).
- Release it as so/dll
a. Include it into Ruby release process
b. Create another repository for release management of "librubyparser" - Release it as gem (ruby/universal_parser)
"librubyparser" has only pure C interface and data structure. If you want to use it from Ruby code, you need C extension code to translate "librubyparser" data and Ruby objects. I propose to create "universal_parser" gem for this purpose.
I prefer #1-b to #1-a because it doesn’t increase tasks for Ruby release process. I want to make #2 as a first milestone.
Actions
Like4
Like0Like0Like2Like1Like1Like0Like0