Class: RedParse::AssigneeList

Inherits:
ValueNode show all
Defined in:
lib/redparse/node.rb

Overview

abstract

Direct Known Subclasses

BlockParams, MultiAssign, NestedAssign

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary

Attributes inherited from Node

#endline, #errors, #offset, #parent, #startline

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Instance Method Summary collapse

Methods inherited from ValueNode

#lvalue

Methods inherited from Node

#+, #+@, #==, [], #[]=, #add_parent_links!, #begin_parsetree, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #image, #initialize_ivars, inline_symbols, #inspect, #lhs_unparse, #linerange, #lvalue, #lvars_defined_in, #merge_replacement_session, namelist, #negate, #original_brackets_assign, param_names, #parsetrees, #pretty_print, #prohibit_fixup, #replace_ivars_and_self, #replace_value, #rescue_parsetree, #to_parsetree, #to_parsetree_and_warnings, #unary, #walk, #xform_tree!

Methods included from Stackable::Meta

#build_exemplars, #enumerate_exemplars, #identity_param

Methods included from FlattenedIvars

#flattened_ivars, #flattened_ivars_equal?

Methods included from Stackable

#identity_name

Constructor Details

#initialize(data) ⇒ AssigneeList

Returns a new instance of AssigneeList.



2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
# File 'lib/redparse/node.rb', line 2477

def initialize(data)
  data.each_with_index{|datum,i|
    if ParenedNode===datum
      first=datum.first
      list=case first
      when CommaOpNode; Array.new(first)
      when UnaryStarNode,ParenedNode; [first]
      end 
      data[i]=NestedAssign.new(list) if list
    end
  }
  replace data
  @offset=self.first.offset
  @startline=self.first.startline
  @endline=self.last.endline
end

Instance Method Details

#all_current_lvarsObject



2561
2562
2563
2564
2565
2566
2567
2568
# File 'lib/redparse/node.rb', line 2561

def all_current_lvars
  result=[]
  each{|lvar|
    lvar.respond_to?(:all_current_lvars) and
      result.concat lvar.all_current_lvars 
  }
  return result
end

#lvalue_parsetree(o) ⇒ Object



2570
# File 'lib/redparse/node.rb', line 2570

def lvalue_parsetree(o); parsetree(o) end

#old_parsetree(o) ⇒ Object



2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
# File 'lib/redparse/node.rb', line 2498

def old_parsetree o
  lhs=data.dup
  if UnaryStarNode===lhs.last
    lstar=lhs.pop.val
  end
  lhs.map!{|x| 
    res=x.parsetree(o)
    res[0]=x.varname2assigntype if VarNode===x
    res
  }
  lhs.unshift(:array) if lhs.size>1 or lstar
  result=[lhs]
  if lstar.respond_to? :varname2assigntype
    result << lstar.varname2assigntype 
  elsif lstar #[]=, attrib=, or A::B=
    huh  
  else #do nothing
  end
  result

end

#parsetree(o) ⇒ Object



2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
# File 'lib/redparse/node.rb', line 2520

def parsetree(o) 
  data=self
  data.empty? and return nil 
#        data=data.first if data.size==1 and ParenedNode===data.first and data.first.size==1
  data=Array.new(data)
  star=data.pop if UnaryStarNode===data.last
  result=data.map{|x| x.lvalue_parsetree(o) }
=begin
  {
    if VarNode===x
      ident=x.ident
      ty=x.varname2assigntype
#            ty==:lasgn and ty=:dasgn_curr
      [ty, ident.to_sym] 
    else
      x=x.parsetree(o)
      if x[0]==:call
        x[0]=:attrasgn
        x[2]="#{x[2]}=".to_sym
      end
      x
    end
  }
=end
  if result.size==0   #just star on lhs
    star or fail
    result=[:masgn]
    result.push nil #why??? #if o[:ruby187]
    result.push star.lvalue_parsetree(o)
  elsif result.size==1 and !star and !(NestedAssign===data.first)  #simple lhs, not multi
    result=result.first
  else
    result=[:masgn, [:array, *result]]
    result.push nil if (!star or DanglingCommaNode===star) #and o[:ruby187]
    result.push star.lvalue_parsetree(o) if star and not DanglingCommaNode===star
  end
  result
end

#unparse(o = default_unparse_options) ⇒ Object



2494
2495
2496
# File 'lib/redparse/node.rb', line 2494

def  unparse o=default_unparse_options
  map{|lval| lval.lhs_unparse o}.join(', ')      
end