Project

General

Profile

Bug #19175

Updated by tompng (tomoya ishida) almost 2 years ago

Ripepr does not recognize hshptn and aryptn splat defining local variables. 
 ~~~ruby 
 Ripper.sexp('a in [*x]; x') 
 # => 
 [:program, 
  [[:case, [:vcall, [:@ident, "a", [1, 0]]], [:in, [:aryptn, nil, nil, [:var_field, [:@ident, "x", [1, 7]]], nil], nil, nil]], 
   [:vcall, [:@ident, "x", [1, 11]]]]] 

 Ripper.sexp('a in {x:}; x') 
 # => 
 [:program,                                                                   
  [[:case, [:vcall, [:@ident, "a", [1, 0]]], [:in, [:hshptn, nil, [[[:@label, "x:", [1, 6]], nil]], nil], nil, nil]], 
   [:vcall, [:@ident, "x", [1, 11]]]]]  
 ~~~ 
 RubyVM::AbstractSyntaxTree returns `(LVAR@1:11-1:12 :x)` 
 I think `[:vcall, [:@ident, "x", [1, 11]]]` should be `[:var_ref, [:@ident, "x", [1, 11]]]` 


 Ripper cannot parse this syntax OK code because rippter thinks local variable x is not defined. 
 ~~~ruby 
 {x:10} in {x:}; x /2 #=> 5 
 Ripper.sexp '{x:10} in {x:}; x /2' #=> nil 
 ~~~ 

 Other pattern seems to be OK. 
 ~~~ruby 
 Ripper.sexp('a in [x, y => z]; x; y; z') 
 # => 
 [:program, 
  [[:case, 
    [:vcall, [:@ident, "a", [1, 0]]], 
    [:in, 
     [:aryptn, 
      nil, 
      [[:var_field, [:@ident, "x", [1, 6]]], 
       [:binary, [:var_field, [:@ident, "y", [1, 9]]], :"=>", [:var_field, [:@ident, "z", [1, 14]]]]], 
      nil, 
      nil], 
     nil, 
     nil]], 
   [:var_ref, [:@ident, "x", [1, 18]]], 
   [:var_ref, [:@ident, "y", [1, 21]]], 
   [:var_ref, [:@ident, "z", [1, 24]]]]] 
 ~~~ 

Back