Class: RedParse::LoopNode
- Defined in:
- lib/redparse/node.rb
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(loopword, condition, thenword, body, endtok) ⇒ LoopNode
constructor
A new instance of LoopNode.
- #parsetree(o) ⇒ Object
- #to_lisp ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
- #until ⇒ Object
- #while ⇒ 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(loopword, condition, thenword, body, endtok) ⇒ LoopNode
Returns a new instance of LoopNode.
4170 4171 4172 4173 4174 4175 4176 |
# File 'lib/redparse/node.rb', line 4170 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
4180 |
# File 'lib/redparse/node.rb', line 4180 def image; "(#{loopword})" end |
#parsetree(o) ⇒ Object
4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 |
# File 'lib/redparse/node.rb', line 4203 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 |
#to_lisp ⇒ Object
4198 4199 4200 4201 |
# File 'lib/redparse/node.rb', line 4198 def to_lisp body=body() "(#{@reverse ? :until : :while} #{condition.to_lisp}\n#{body.to_lisp})" end |
#unparse(o = default_unparse_options) ⇒ Object
4182 4183 4184 4185 4186 4187 4188 |
# File 'lib/redparse/node.rb', line 4182 def unparse o= [@reverse? "until " : "while ", condition.unparse(o), unparse_nl(body||self,o), body&&body.unparse(o), ";end" ].join end |
#until ⇒ Object
4194 4195 4196 |
# File 'lib/redparse/node.rb', line 4194 def until @reverse ? condition : negate(condition, @loopword_offset) end |
#while ⇒ Object
4190 4191 4192 |
# File 'lib/redparse/node.rb', line 4190 def while @reverse ? negate(condition, @loopword_offset) : condition end |