ruby / ruby/racc

Fix Racc::ParseError so Pattern Matching is supported

Open
#145 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Yacc
Stars
569
Forks
93
Avg merge
4d 19h
Merged PRs (30d)
4

Description

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]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by saving the supplied reproduction as snippet.rb and running it with Ruby 2.7.2 to confirm the Racc::ParseError around the pattern-matching in syntax. Trace how Racc handles this input and add coverage for the example; done means the snippet parses without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.