Class: RedParse::LoopNode
- Inherits:
-
ValueNode
show all
- Defined in:
- lib/redparse/node.rb,
lib/redparse/ripper.rb,
lib/redparse/ReduceWithsFor_RedParse_1_9.rb,
lib/redparse/ReduceWithsFor_RedParse_1_8.rb
Constant Summary
FlattenedIvars::EXCLUDED_IVARS
Instance Attribute Summary
Attributes inherited from Node
#endline, #errors, #offset, #parent, #startline
#boolean_identity_params, #identity_params
Instance Method Summary
collapse
Methods inherited from ValueNode
#lvalue, #reducer_method
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!
#build_exemplars, #enumerate_exemplars, #identity_param
#flattened_ivars, #flattened_ivars_equal?
Methods included from Stackable
#identity_name
Constructor Details
#initialize(loopword, condition, thenword, body, endtok) ⇒ LoopNode
Returns a new instance of LoopNode.
4434
4435
4436
4437
4438
4439
4440
|
# File 'lib/redparse/node.rb', line 4434
def initialize(loopword,condition,thenword,body,endtok)
@offset=loopword.offset
condition.special_conditions! if condition.respond_to? :special_conditions!
super(condition,body)
@reverse= loopword.ident=="until"
@loopword_offset=loopword.offset
end
|
Instance Method Details
#image ⇒ Object
4444
|
# File 'lib/redparse/node.rb', line 4444
def image; "(#{loopword})" end
|
#parsetree(o) ⇒ Object
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
|
# File 'lib/redparse/node.rb', line 4475
def parsetree(o)
cond=condition.rescue_parsetree(o)
if cond.first==:not
reverse=!@reverse
cond=cond.last
else
reverse=@reverse
end
[reverse ? :until : :while, cond, body&&body.parsetree(o), true]
end
|
#reducer_ident ⇒ Object
17445
17446
17447
|
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17445
def reducer_ident
:LoopNode
end
|
#reversed ⇒ Object
4462
4463
4464
|
# File 'lib/redparse/node.rb', line 4462
def reversed
@reverse
end
|
#rip(p) ⇒ Object
352
353
354
355
|
# File 'lib/redparse/ripper.rb', line 352
def rip p
event= @reverse ? :on_until : :on_while
p.send(event, condition.rip(p), force_stmt_list_rip(body,p))
end
|
#test_first ⇒ Object
4466
4467
4468
|
# File 'lib/redparse/node.rb', line 4466
def test_first
false
end
|
#to_lisp ⇒ Object
4470
4471
4472
4473
|
# File 'lib/redparse/node.rb', line 4470
def to_lisp
body=body()
"(#{@reverse ? :until : :while} #{condition.to_lisp}\n#{body.to_lisp})"
end
|
#unparse(o = default_unparse_options) ⇒ Object
4446
4447
4448
4449
4450
4451
4452
|
# File 'lib/redparse/node.rb', line 4446
def unparse o=default_unparse_options
[@reverse? "until " : "while ",
condition.unparse(o), unparse_nl(body||self,o),
body&&body.unparse(o),
";end"
].join
end
|
#until ⇒ Object
4458
4459
4460
|
# File 'lib/redparse/node.rb', line 4458
def until
@reverse ? condition : negate(condition, @loopword_offset)
end
|
#while ⇒ Object
4454
4455
4456
|
# File 'lib/redparse/node.rb', line 4454
def while
@reverse ? negate(condition, @loopword_offset) : condition
end
|