Class: RedParse::WhenNode
- Defined in:
- lib/redparse/node.rb,
lib/redparse/ReduceWithsFor_RedParse_1_9.rb,
lib/redparse/ReduceWithsFor_RedParse_1_8.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
- #image ⇒ Object
-
#initialize(whenword, when_, thenword, then_) ⇒ WhenNode
constructor
A new instance of WhenNode.
- #parsetree(o) ⇒ Object
- #reducer_ident ⇒ Object
- #reducer_method(stack) ⇒ Object
- #to_lisp ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
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
Constructor Details
#initialize(whenword, when_, thenword, then_) ⇒ WhenNode
4542 4543 4544 4545 4546 4547 |
# File 'lib/redparse/node.rb', line 4542 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
4552 |
# File 'lib/redparse/node.rb', line 4552 def image; "(when)" end |
#parsetree(o) ⇒ Object
4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 |
# File 'lib/redparse/node.rb', line 4575 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 |
#reducer_ident ⇒ Object
17168 17169 17170 |
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17168 def reducer_ident :WhenNode end |
#reducer_method(stack) ⇒ Object
17165 17166 17167 |
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17165 def reducer_method(stack) :reduce_with_tos_WhenNode end |
#to_lisp ⇒ Object
4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 |
# File 'lib/redparse/node.rb', line 4563 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
4554 4555 4556 4557 4558 4559 4560 4561 |
# File 'lib/redparse/node.rb', line 4554 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 |