From: "yui-knk (Kaneko Yuichiro) via ruby-core" <ruby-core@...>
Date: 2023-06-08T02:14:17+00:00
Subject: [ruby-core:113800] [Ruby master Feature#19719] Universal Parser

Issue #19719 has been reported by yui-knk (Kaneko Yuichiro).



----------------------------------------

Feature #19719: Universal Parser

https://bugs.ruby-lang.org/issues/19719



* Author: yui-knk (Kaneko Yuichiro)

* Status: Open

* Priority: Normal

----------------------------------------

# 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.

1. 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.

2. 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.

3. 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.

Introduce `UNIVERSAL_PARSER` macro and implement Universal Parser by passing all necessary CRuby related functions via `struct 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 of `VALUE`.

* 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 remove `UNIVERSAL_PARSER` macro.



# Release management

There are three options for releasing a binary for Universal Parser (���librubyparser���).

1. Release it as so/dll

  a. Include it into Ruby release process

  b. Create another repository for release management of "librubyparser"

2. 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.









-- 

https://bugs.ruby-lang.org/

 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/