Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Fix Racc::ParseError so Pattern Matching is supported

未关闭
#145 2 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
compilers

调研方向

首先,将提供的复现代码保存为 snippet.rb,并使用 Ruby 2.7.2 运行它,以确认与模式匹配 in 语法相关的 Racc::ParseError。跟踪 Racc 如何处理此输入,并为该示例添加覆盖;完成的标准是该代码片段能够在不出现所报告错误的情况下完成解析。

由索引模型根据 Issue 内容生成。

描述

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]
主要语言
Yacc
星标
569
派生
94
平均合并
12 小时 11 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/racc 的其他 Issue

查看 ruby/racc 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。