Project

General

Profile

Actions

Feature #19719

closed

Universal Parser

Added by yui-knk (Kaneko Yuichiro) 11 months ago. Updated 11 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113800]

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.

  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.

Actions

Also available in: Atom PDF

Like4
Like0Like0Like2Like1Like1Like0Like0