Skip to content

Fix Racc::ParseError so Pattern Matching is supported #145

@bkuhlmann

Description

@bkuhlmann

Overview

When using Flog on a project that uses Ruby Pattern Matching, I get the following error:

 bkuhlmann@vilya  rubysmith  alchemists.io  ⑂ release +    flog
ERROR: parsing ruby file ./lib/rubysmith/cli/shell.rb
ERROR! Aborting. You may want to run with --continue.
Traceback (most recent call last):
	23: from /Users/bkuhlmann/.gem/ruby/2.7.2/bin/flog:23:in `<main>'
	22: from /Users/bkuhlmann/.gem/ruby/2.7.2/bin/flog:23:in `load'
	21: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/bin/flog:5:in `<top (required)>'
	20: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog_cli.rb:28:in `run'
	19: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog_cli.rb:162:in `flog'
	18: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog.rb:177:in `flog'
	17: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog.rb:177:in `each'
	16: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog.rb:182:in `block in flog'
	15: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog.rb:194:in `flog_ruby'
	14: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/flog-4.6.4/lib/flog.rb:224:in `flog_ruby!'
	13: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser.rb:33:in `process'
	12: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser.rb:33:in `each'
	11: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser.rb:36:in `block in process'
	10: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser_extras.rb:1317:in `process'
	 9: from /Users/bkuhlmann/.rubies/ruby-2.7.2/lib/ruby/2.7.0/timeout.rb:110:in `timeout'
	 8: from /Users/bkuhlmann/.rubies/ruby-2.7.2/lib/ruby/2.7.0/timeout.rb:33:in `catch'
	 7: from /Users/bkuhlmann/.rubies/ruby-2.7.2/lib/ruby/2.7.0/timeout.rb:33:in `catch'
	 6: from /Users/bkuhlmann/.rubies/ruby-2.7.2/lib/ruby/2.7.0/timeout.rb:33:in `block in catch'
	 5: from /Users/bkuhlmann/.rubies/ruby-2.7.2/lib/ruby/2.7.0/timeout.rb:95:in `block in timeout'
	 4: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser_extras.rb:1329:in `block in process'
	 3: from (eval):3:in `do_parse'
	 2: from (eval):3:in `_racc_do_parse_c'
	 1: from /Users/bkuhlmann/.gem/ruby/2.7.2/gems/ruby_parser-3.15.0/lib/ruby_parser_extras.rb:1304:in `on_error'
/Users/bkuhlmann/.gem/ruby/2.7.2/gems/racc-1.5.1/lib/racc/parser.rb:538:in `on_error': ./lib/rubysmith/cli/shell.rb:27 :: parse error on value ["in", 27] (kIN) (Racc::ParseError)

Steps to Recreate

To recreate, I'm using Flog to illustrate since Flog has Racc as a dependency. Save the following to snippet.rb and run as ruby snippet.rb to see the issue:

# frozen_string_literal: true

require "bundler/inline"

gemfile true do
  source "https://rubygems.org"
  gem "flog", "~> 4.6"
end

collection = {
  a: 1,
  b: 2
}

case collection
  in a: value then puts value
  in b: value then puts value
end

Desired Behavior

Would like to see Racc handle pattern matching without error.

Environment

ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions