whitequark / whitequark/parser

Part of the parsing for the ternary operator is not compatible with Ruby 2.2+

Open
#1,041 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Yacc
Stars
1.6k
Forks
205
PR merge metrics
No merged PRs in 30d

Description

The following changes have been made between Ruby 2.1 and earlier and 2.2 and later:

Ruby 2.1 and earlier:

$ ruby -cve 'x ? !y: z'
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin13.0]
-e:1: syntax error, unexpected tLABEL
x ? !y: z
       ^

Ruby 2.2 and later:

$ ruby -cve 'x ? !y: z'
ruby 2.2.10p489 (2018-03-28 revision 63023) [x86_64-darwin17]
Syntax OK

Expected Behavior:

In Ruby 2.2 and later, the expression x ? !y : z is successfully parsed without parse error.

Actual Behavior:

The latest version of the Parser gem (3.3.5.0) still follows the behavior of Ruby 2.1 and earlier, which raises a syntax error when attempting to parse x ? !y : z.

For example:

$ ruby-parse --22 -e 'x ? !y: z'
(fragment:0):1:6: error: unexpected token tLABEL
(fragment:0):1: x ? !y: z
(fragment:0):1:      ^~

$ ruby-parse --33 -e 'x ? !y: z'
(fragment:0):1:6: error: unexpected token tLABEL
(fragment:0):1: x ? !y: z
(fragment:0):1:      ^~

Contributor guide

Open the contributing guide

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 reproducing the reported expression with ruby-parse using the --22 and --33 options. Trace the parser's handling of the ternary expression and compare it with Ruby 2.2 and later, where the expression parses successfully. Done means x ? !y : z no longer raises the reported tLABEL error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.