Class: RedParse::ForNode
- Defined in:
- lib/redparse/node.rb
Constant Summary
Constants included from FlattenedIvars
RedParse::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(forword, for_, inword, in_, doword, do_, endword) ⇒ ForNode
constructor
A new instance of ForNode.
- #parsetree(o) ⇒ 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(forword, for_, inword, in_, doword, do_, endword) ⇒ ForNode
Returns a new instance of ForNode.
4322 4323 4324 4325 4326 4327 4328 |
# File 'lib/redparse/node.rb', line 4322 def initialize(forword,for_,inword,in_,doword,do_,endword) @offset=forword.offset #elide 1 layer of parens if present for_=for_.first if ParenedNode===for_ for_=CommaOpNode===for_ ? Array.new(for_) : [for_] super(BlockParams.new(for_),in_,do_) end |
Instance Method Details
#image ⇒ Object
4334 |
# File 'lib/redparse/node.rb', line 4334 def image; "(for)" end |
#parsetree(o) ⇒ Object
4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 |
# File 'lib/redparse/node.rb', line 4342 def parsetree(o) =begin case vars=@data[0] when Node: vars=vars.parsetree(o) if vars.first==:call vars[0]=:attrasgn vars[2]="#{vars[2]}=".to_sym end vars when Array: vars=[:masgn, [:array, *vars.map{|lval| res=lval.parsetree(o) res[0]=lval.varname2assigntype if VarNode===lval res } ]] when VarNode ident=vars.ident vars=vars.parsetree(o) (vars[0]=vars.varname2assigntype) rescue nil else fail end =end vars=self.for.lvalue_parsetree(o) collection= self.in.begin_parsetree(o) if ParenedNode===self.in and collection.first==:begin assert collection.size==2 collection=collection[1] end result=[:for, collection, vars] result.push self.do.parsetree(o) if self.do result end |
#unparse(o = default_unparse_options) ⇒ Object
4336 4337 4338 4339 4340 |
# File 'lib/redparse/node.rb', line 4336 def unparse o= result=unparse_nl(self,o)+" for #{iterator.lhs_unparse(o)[1...-1]} in #{enumerable.unparse o}" result+=unparse_nl(body,o)+" #{body.unparse(o)}" if body result+=";end" end |