Class: RedParse::WhenNode
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
- #image ⇒ Object
-
#initialize(whenword, when_, thenword, then_) ⇒ WhenNode
constructor
A new instance of WhenNode.
- #parsetree(o) ⇒ Object
- #to_lisp ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
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
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
#image ⇒ Object
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_lisp ⇒ Object
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= 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 |