Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Prism as a Ruby parser #446

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Support Prism as a Ruby parser #446

merged 1 commit into from
Mar 5, 2024

Commits on Mar 5, 2024

  1. Support Prism as a Ruby parser

    Follow up rubocop/rubocop-ast#277
    
    In Prism (`Prism::Translation::Parser`), `match-with-lvasgn` can be distinctly differentiated.
    
    It is unclear whether to conform to the current behavior of the Parser gem, but initially,
    `def_node_matcher` has been updated to accept the following incompatibilities for
    `Performance/EndWith`, `Performance/StringInclude`, and `Performance/StartWith` cops
    to ensure it works with Prism 0.24.0 as well.
    
    ## Parser gem
    
    Returns an `match_with_lvasgn` node:
    
    ```console
    $ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/foo/ =~ bar")'
    ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
    s(:match_with_lvasgn,
      s(:regexp,
        s(:str, "foo"),
        s(:regopt)),
      s(:send, nil, :bar))
    ```
    
    Returns an `match_with_lvasgn` node:
    
    ```console
    $ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/(?<foo>)foo/ =~ bar")'
    ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
    s(:match_with_lvasgn,
      s(:regexp,
        s(:str, "(?<foo>)foo"),
        s(:regopt)),
      s(:send, nil, :bar))
    ```
    
    This lvar-injecting feature appears to have not been supported by Parser gem for a long time:
    whitequark/parser#69 (comment)
    
    ## Prism
    
    Returns an `send` node:
    
    ```console
    $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")'
    ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
    s(:send,
      s(:regexp,
        s(:str, "foo"),
        s(:regopt)), :=~,
      s(:send, nil, :bar))
    ```
    
    Returns an `match_with_lvasgn` node:
    
    ```console
    $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/(?<foo>)foo/ =~ bar")'
    ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
    s(:match_with_lvasgn,
      s(:regexp,
        s(:str, "(?<foo>)foo"),
        s(:regopt)),
      s(:send, nil, :bar))
    ```
    koic committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    2059d28 View commit details
    Browse the repository at this point in the history