Class: RedParse::CaseNode
- Defined in:
- lib/redparse/node.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
- #to_lisp ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
Methods inherited from ValueNode
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(caseword, condition, semi, whens, otherwise, endword) ⇒ CaseNode
Returns a new instance of CaseNode.
4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 |
# File 'lib/redparse/node.rb', line 4220 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.
4232 4233 4234 |
# File 'lib/redparse/node.rb', line 4232 def empty_else @empty_else end |
Instance Method Details
#image ⇒ Object
4245 |
# File 'lib/redparse/node.rb', line 4245 def image; "(case)" end |
#parsetree(o) ⇒ Object
4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 |
# File 'lib/redparse/node.rb', line 4254 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 |
#to_lisp ⇒ Object
4247 4248 4249 4250 4251 4252 |
# File 'lib/redparse/node.rb', line 4247 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
4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 |
# File 'lib/redparse/node.rb', line 4234 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 |