Class: RedParse::CaseNode
- 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
-
#empty_else ⇒ Object
readonly
Returns the value of attribute empty_else.
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(caseword, condition, semi, whens, otherwise, endword) ⇒ CaseNode
constructor
A new instance of CaseNode.
- #parsetree(o) ⇒ Object
- #reducer_ident ⇒ Object
- #to_lisp ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
Methods inherited from ValueNode
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(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_else ⇒ Object (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
#image ⇒ Object
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_ident ⇒ Object
17460 17461 17462 |
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17460 def reducer_ident :CaseNode end |
#to_lisp ⇒ Object
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= 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 |