Module: RedParse::HasRescue

Included in:
BeginNode, MethodNode, NamespaceNode
Defined in:
lib/redparse/node.rb

Instance Method Summary collapse

Instance Method Details

#parsetree_and_rescues(o) ⇒ Object



2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
# File 'lib/redparse/node.rb', line 2082

def parsetree_and_rescues(o)
    body=body()
    body=body.clone if body
    target=result=[]   #was: [:begin, ]

    #body,rescues,else_,ensure_=*self
    target.push target=[:ensure, ] if ensure_ or @empty_ensure

    rescues=rescues().map{|resc| resc.parsetree(o)}
    if rescues.empty?
      if else_
        body= body ? SequenceNode.new(body,nil,else_) : else_
      end
      else_=nil
    else
      target.push newtarget=[:rescue, ]
      else_=else_()
    end
    if body
#              needbegin=  (BeginNode===body and body.after_equals)
        body=body.parsetree(o)
#              body=[:begin, body] if needbegin and body.first!=:begin and !o[:ruby187]
        (newtarget||target).push body if body
    end
    target.push ensure_.parsetree(o) if ensure_
    target.push [:nil] if @empty_ensure
    target=newtarget if newtarget

    unless rescues.empty?
      target.push linked_list(rescues)
    end
    target.push else_.parsetree(o) if  else_ #and !body
    result.size==0 and result=[[:nil]]
    if o[:ruby187] and !rescues.empty?
      result.unshift :begin
    else
      result=result.last
    end
    result
end

#unparse_and_rescues(o) ⇒ Object



2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
# File 'lib/redparse/node.rb', line 2123

def unparse_and_rescues(o)
    result=" "
    result+= body.unparse(o) if body
    result+=unparse_nl(rescues.first,o) if rescues
    rescues.each{|resc| result+=resc.unparse(o) } if rescues
    result+=unparse_nl(else_,o)+"else "+else_.unparse(o) if else_
    result+=";else" if defined? @empty_else and @empty_else
    result+=unparse_nl(ensure_,o)+"ensure "+ensure_.unparse(o) if ensure_
    result+=";ensure" if defined? @empty_ensure and @empty_ensure
    return result
end