Class: RedParse::CaseNode

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

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary collapse

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, #reducer_method

Methods inherited from Node

#+, #+@, #==, [], #[]=, #add_parent_links!, #args_rip, #begin_parsetree, #classic_inspect, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #force_stmt_list_rip, #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, #rfind, #rfind_all, #rgrep, #rip_and_rescues, #rip_explode!, #short_inspect, #stmts_rip, #to_parsetree, #to_parsetree_and_warnings, #to_ruby, #to_s, #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(caseword, condition, semi, whens, otherwise, endword) ⇒ CaseNode

Returns a new instance of CaseNode.



4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
# File 'lib/redparse/node.rb', line 4492

def initialize(caseword, condition, semi, whens, otherwise, endword)
  @offset=caseword.offset
  if otherwise
    otherwise=otherwise.val
    @empty_else=!otherwise
  else
    @empty_else=false
  end
  whens.extend ListInNode
  super(condition,whens,otherwise)
end

Instance Attribute Details

#empty_elseObject (readonly)

Returns the value of attribute empty_else.



4504
4505
4506
# File 'lib/redparse/node.rb', line 4504

def empty_else
  @empty_else
end

Instance Method Details

#imageObject



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

def image; "(case)" end

#parsetree(o) ⇒ Object



4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
# File 'lib/redparse/node.rb', line 4526

def parsetree(o)
  result=[:case, condition&&condition.parsetree(o)]+ 
           whens.map{|whennode| whennode.parsetree(o)}
  other=otherwise&&otherwise.parsetree(o)
  return [] if result==[:case, nil] and !other
  if other and other[0..1]==[:case, nil] and !condition
    result.concat other[2..-1]
  else
    result<<other
  end
  return result
end

#reducer_identObject



17460
17461
17462
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17460

def reducer_ident
  :CaseNode
end

#to_lispObject



4519
4520
4521
4522
4523
4524
# File 'lib/redparse/node.rb', line 4519

def to_lisp
  "(case #{case_.to_lisp}\n"+
    whens.map{|x| x.to_lisp}.join("\n")+"\n"+
    "(else #{else_.to_lisp}"+
  "\n)"
end

#unparse(o = default_unparse_options) ⇒ Object



4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
# File 'lib/redparse/node.rb', line 4506

def unparse o=default_unparse_options
  result="case #{condition&&condition.unparse(o)}"+
         whens.map{|wh| wh.unparse o}.join

  result += unparse_nl(otherwise,o)+"else "+otherwise.unparse(o) if otherwise
  result += ";else;" if @empty_else
  result += ";end"

  return result
end