From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-06-09T14:12:26+00:00 Subject: [ruby-core:113858] [Ruby master Feature#19719] Universal Parser Issue #19719 has been updated by Eregon (Benoit Daloze). As I discussed with @matz and @yui-knk at RubyKaigi, the API, serialization to convert efficiently from C to Java, and AST format (a much cleaner AST) needed for JRuby and TruffleRuby are the ones developed in YARP. JRuby and TruffleRuby are already working on migrating to YARP. So for use case 3, I see this only achievable if the Universal Parser would match exactly what YARP does (and matz agreed Universal Parser should match YARP's API/AST). So I am confused, why trying to reinvent YARP then? Also none of the design steps mention how to make the AST any easier to consume (relevant for all 3 use cases), it is still the internal messy AST with weird abbreviations created by bison/lrama and type-unsafe `RNode` unions. That is not usable by other Ruby implementations and by tools, just like `RubyVM::AbstractSyntaxTree` is not a proper API (#14844). Also I think to pretend to be a "Universal Parser" it would need support and extended discussions with Ruby implementations authors (not just CRuby) and tool authors. We probably need to have a discussion on the bug tracker about pros/cons of YARP and lrama Universal Parser. First of all, I think @yui-knk should show the status of Universal Parser and how it improves over YARP, otherwise it seems to purposefully ignore a much more advanced and established project (YARP). ---------------------------------------- Feature #19719: Universal Parser https://bugs.ruby-lang.org/issues/19719#change-103506 * 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/