Project

General

Profile

Actions

Bug #5002

closed

Ripper fails to distinguish local vars from vcalls [PATCH]

Added by adgar (Michael Edgar) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-core:37908]

Description

Ripper always parses the variable grammar production (which includes identifiers, {i,c,g}vars, nil, FILE, etc) as a var_ref node, whose only child is the token itself.

This is a problem for one huge reason: local variables look exactly like vcalls: no-arg, no-receiver method calls. More importantly, the parse tree defines whether a given bareword identifier is a local variable reference or a method call. Thus, given a ripper parse tree, in order to distinguish local variable references from vcalls, one must reconstruct the parse order, re-implement the local variable introduction rules (local variable assigned in some way, for loops, block arg, rescue exception variable, named regex capture groups, ....), and then relabel those var_ref nodes which are method calls as vcall nodes.

This is quite a nasty workaround. There are a lot of edge cases to mess up. I've implemented it as the ripper-plus gem, but it's a huge pain, I'm not sure it's entirely correct, and is something the parser should be doing anyway.

The funny thing is, the parser already is doing almost all of the work! It's just not looking at the local variable tables when it comes time to generate the Ripper event. The patch I've attached does do so - it's a small change for a huge benefit for Ripper users.

I'd like to see this land in 1.9.3 - it's a small patch, and given the other bug fixes Ripper's had this cycle, would make Ripper pretty much sufficient for an entire Ruby implementation.


Files

ripper.vcall.diff (1.64 KB) ripper.vcall.diff adgar (Michael Edgar), 07/09/2011 12:24 PM
vcall.breaking.diff (3.51 KB) vcall.breaking.diff Implementation which changes error messages for `nil = foo` adgar (Michael Edgar), 07/10/2011 04:55 AM
vcall.same_errors.diff (4.24 KB) vcall.same_errors.diff Implementation with additional grammar rules to match existing error messages adgar (Michael Edgar), 07/10/2011 04:55 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0