class RedParse::ListInNode::AssignNode
Public Class Methods
create(*args)
click to toggle source
Calls superclass method
RedParse::ListInNode::Node::create
# File lib/redparse/node.rb, line 2334 def self.create(*args) if args.size==5 if args[3].ident=="rescue3" lhs,op,rescuee,op2,rescuer=*args if MULTIASSIGN===lhs or !rescuee.is_list return RescueOpNode.new(AssignNode.new(lhs,op,rescuee),nil,rescuer) else rhs=RescueOpNode.new(rescuee.val,op2,rescuer) end super(lhs,op,rhs) else super(args[0],args[1],args[3]) end else super end end
new(*args)
click to toggle source
Calls superclass method
RedParse::ListInNode::Node::new
# File lib/redparse/node.rb, line 2351 def initialize(*args) if args.size==5 #this branch should be dead now if args[3].ident=="rescue3" lhs,op,rescuee,op2,rescuer=*args if MULTIASSIGN===lhs or rescuee.is_list? huh else rhs=RescueOpNode.new(rescuee.val,op2,rescuer) end else lhs=args.shift op=args.shift args.shift #bogus1 rhs=args.shift end else lhs,op,rhs=*args rhs=rhs.val if AssignmentRhsNode===rhs end case lhs when UnaryStarNode #look for star on lhs lhs=MultiAssign.new([lhs]) unless lhs.after_comma when ParenedNode if !lhs.after_comma #look for () around lhs if CommaOpNode===lhs.first lhs=MultiAssign.new(Array.new(lhs.first)) @lhs_parens=true elsif UnaryStarNode===lhs.first lhs=MultiAssign.new([lhs.first]) @lhs_parens=true elsif ParenedNode===lhs.first @lhs_parens=true lhs=lhs.first else lhs=lhs.first end end when CommaOpNode lhs=MultiAssign.new lhs #rhs=Array.new(rhs) if CommaOpNode===rhs end if CommaOpNode===rhs rhs=Array.new(rhs) lhs=MultiAssign.new([lhs]) unless MultiAssign===lhs end op=op.ident if Array==rhs.class rhs.extend ListInNode end @offset=lhs.offset return super(lhs,op,rhs) #punting, i hope the next layer can handle += and the like =begin #in theory, we should do something more sophisticated, like this: #(but the presence of side effects in lhs will screw it up) if op=='=' super else super(lhs,OpNode.new(lhs,OperatorToken.new(op.chomp('=')),rhs)) end =end end
Public Instance Methods
all_current_lvars()
click to toggle source
# File lib/redparse/node.rb, line 2450 def all_current_lvars left.respond_to?(:all_current_lvars) ? left.all_current_lvars : [] end
image()
click to toggle source
# File lib/redparse/node.rb, line 2425 def image; '(=)' end
multi?()
click to toggle source
# File lib/redparse/node.rb, line 2421 def multi? MultiAssign===left end
parsetree(o)
click to toggle source
# File lib/redparse/node.rb, line 2455 def parsetree(o) case left when ParenedNode; huh when RescueOpNode; huh when BeginNode; huh when ConstantNode; left.lvalue_parsetree(o) << right.parsetree(o) when MultiAssign; lhs=left.lvalue_parsetree(o) rhs= right.class==Array ? right.dup : [right] star=rhs.pop if UnaryStarNode===rhs.last rhs=rhs.map{|x| x.rescue_parsetree(o)} if rhs.size==0 star or fail rhs= star.parsetree(o) elsif rhs.size==1 and !star and !(UnaryStarNode===left.first) rhs.unshift :to_ary else rhs.unshift(:array) if star splat=star.val.rescue_parsetree(o) #if splat.first==:call #I don't see how this can be right.... # splat[0]=:attrasgn # splat[2]="#{splat[2]}=".to_sym #end rhs=[:argscat, rhs, splat] end if left.size==1 and !(UnaryStarNode===left.first) and !(NestedAssign===left.first) rhs=[:svalue, rhs] if CallNode===left.first rhs=[:array, rhs] end end end if left.size==1 and BracketsGetNode===left.first and right.class==Array #hack lhs.last<<rhs lhs else lhs<< rhs end when CallSiteNode op=op().chomp('=') rcvr=left.receiver.parsetree(o) prop=left.name.+('=').to_sym args=right.rescue_parsetree(o) UnaryStarNode===right and args=[:svalue, args] if op.empty? [:attrasgn, rcvr, prop, [:array, args] ] else [:op_asgn2, rcvr,prop, op.to_sym, args] end when BracketsGetNode args=left.params if op()=='=' result=left.lvalue_parsetree(o) #[:attrasgn, left[0].parsetree(o), :[]=] result.size==3 and result.push [:array] rhs=right.rescue_parsetree(o) UnaryStarNode===right and rhs=[:svalue, rhs] if args result[-1]=[:argspush,result[-1]] if UnaryStarNode===args.last #else result[-1]=[:zarray] end result.last << rhs result else =begin args&&=args.map{|x| x.parsetree(o)}.unshift(:array) splat=args.pop if :splat==args.last.first if splat and left.params.size==1 args=splat elsif splat args=[:argscat, args, splat.last] end =end lhs=left.parsetree(o) if lhs.first==:fcall rcvr=[:self] args=lhs[2] else rcvr=lhs[1] args=lhs[3] end args||=[:zarray] result=[ :op_asgn1, rcvr, args, op().chomp('=').to_sym, right.rescue_parsetree(o) ] end when VarNode node_type=left.varname2assigntype if /^(&&|\|\|)=$/===op() return ["op_asgn_#{$1[0]==?& ? "and" : "or"}".to_sym, left.parsetree(o), [node_type, left.ident.to_sym, right.rescue_parsetree(o)] ] end if op()=='=' rhs=right.rescue_parsetree(o) UnaryStarNode===right and rhs=[:svalue, rhs] # case left # when VarNode; [node_type, left.ident.to_sym, rhs] # else [node_type, left.data[0].parsetree(o), left.data[1].data[0].ident.+('=').to_sym ,[:array, rhs]] # end =begin these branches shouldn't be necessary now elsif node_type==:op_asgn2 [node_type, @data[0].data[0].parsetree(o), @data[0].data[1].data[0].ident.+('=').to_sym, op().ident.chomp('=').to_sym, @data[2].parsetree(o) ] elsif node_type==:attrasgn [node_type] =end else [node_type, left.ident.to_sym, [:call, left.parsetree(o), op().chomp('=').to_sym, [:array, right.rescue_parsetree(o)] ] ] end else huh end end
to_lisp()
click to toggle source
# File lib/redparse/node.rb, line 2427 def to_lisp case left when ParenedNode; huh when BeginNode; huh when RescueOpNode; huh when ConstantNode; huh when BracketsGetNode; huh when VarNode "(set #{left.to_lisp} (#{op.chomp('=')} #{left.to_lisp} #{right.to_lisp}))" when CallSiteNode if op=='=' "(#{left.receiver.to_lisp} #{left.name}= #{right.to_lisp})" else op_=op.chomp('=') varname=nil "(let #{varname=huh} #{left.receiver.to_lisp} "+ "(#{varname} #{left.name}= "+ "(#{op_} (#{varname} #{op}) #{right.to_lisp})))" end else huh end end
unparse(o=default_unparse_options)
click to toggle source
# File lib/redparse/node.rb, line 2594 def unparse(o=default_unparse_options) result=lhs.lhs_unparse(o) result="(#{result})" if defined? @lhs_parens result+' '+op+' '+ (rhs.class==Array ? rhs.map{|rv| rv.unparse o}.join(',') : rhs.unparse(o) ) end