Class: RedParse::WhenNode

Inherits:
Node
  • Object
show all
Defined in:
lib/redparse/node.rb

Overview

not to appear in final tree?

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 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!, #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(whenword, when_, thenword, then_) ⇒ WhenNode



4270
4271
4272
4273
4274
4275
# File 'lib/redparse/node.rb', line 4270

def initialize(whenword,when_,thenword,then_)
  @offset=whenword.offset
  when_=Array.new(when_) if CommaOpNode===when_
  when_.extend ListInNode if when_.class==Array
  super(when_,then_)
end

Instance Method Details

#imageObject



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

def image; "(when)" end

#parsetree(o) ⇒ Object



4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
# File 'lib/redparse/node.rb', line 4303

def parsetree(o)
  conds=
    if Node|Token===condition
      [condition.rescue_parsetree(o)]
    else
      condition.map{|cond| cond.rescue_parsetree(o)}
    end
  if conds.last[0]==:splat
    conds.last[0]=:when
    conds.last.push nil
  end
  [:when, [:array, *conds],
    consequent&&consequent.parsetree(o)
  ]
end

#to_lispObject



4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
# File 'lib/redparse/node.rb', line 4291

def to_lisp
  unless Node|Token===condition
    "(when (#{condition.map{|cond| cond.to_lisp}.join(" ")}) #{
      consequent&&consequent.to_lisp
    })"
  else
    "(#{when_.to_lisp} #{then_.to_lisp})"
  end
  

end

#unparse(o = default_unparse_options) ⇒ Object



4282
4283
4284
4285
4286
4287
4288
4289
# File 'lib/redparse/node.rb', line 4282

def unparse o=default_unparse_options
  result=unparse_nl(self,o)+"when "
  result+=condition.class==Array ? 
            condition.map{|cond| cond.unparse(o)}.join(',') : 
            condition.unparse(o) 
  result+=unparse_nl(consequent,o)+consequent.unparse(o) if consequent
  result
end