Sexp changes from ruby_parser and some changes for caching hash value and tracking 'original' line number of a Sexp.
Returns arglist for method call. This differs from Sexp#args, as Sexp#args does not return a 'real' Sexp (it does not have a node type) but Sexp#arglist returns a s(:arglist, ...)
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2))) ^------------ arglist ------------^
# File lib/ruby_parser/bm_sexp.rb, line 186 def arglist expect :call, :attrasgn, :super, :zsuper case self.node_type when :call, :attrasgn self[3..-1].unshift :arglist when :super, :zsuper if self[1] self[1..-1].unshift :arglist else Sexp.new(:arglist) end end end
Sets the arglist in a method call.
# File lib/ruby_parser/bm_sexp.rb, line 163 def arglist= exp expect :call, :attrasgn start_index = 3 if exp.is_a? Sexp and exp.node_type == :arglist exp = exp[1..-1] end exp.each_with_index do |e, i| self[start_index + i] = e end end
Returns arguments of a method call. This will be an 'untyped' Sexp.
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2))) ^--------args--------^
# File lib/ruby_parser/bm_sexp.rb, line 205 def args expect :call, :attrasgn, :super, :zsuper case self.node_type when :call, :attrasgn if self[3] self[3..-1] else Sexp.new end when :super, :zsuper if self[1] self[1..-1] else Sexp.new end end end
Returns block of a call with a block. Could be a single expression or a block:
s(:iter, s(:call, nil, :x, s(:arglist)), s(:lasgn, :y), s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist)))) ^-------------------- block --------------------------^
# File lib/ruby_parser/bm_sexp.rb, line 350 def block delete = nil unless delete.nil? #this is from RubyParser return find_node :block, delete end expect :iter, :call_with_block, :scope, :resbody case self.node_type when :iter, :call_with_block self[3] when :scope self[1] when :resbody #This is for Ruby2Ruby ONLY find_node :block end end
Returns parameters for a block
s(:iter, s(:call, nil, :x, s(:arglist)), s(:lasgn, :y), <- block_args s(:call, nil, :p, s(:arglist, s(:lvar, :y))))
# File lib/ruby_parser/bm_sexp.rb, line 374 def block_args expect :iter, :call_with_block self[2] end
Method call associated with a block:
s(:iter, s(:call, nil, :x, s(:arglist)), <- block_call s(:lasgn, :y), s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
# File lib/ruby_parser/bm_sexp.rb, line 337 def block_call expect :iter, :call_with_block self[1] end
Returns body of a method definition, class, or module. This will be an untyped Sexp containing a list of Sexps from the body.
# File lib/ruby_parser/bm_sexp.rb, line 462 def body expect :defn, :defs, :methdef, :selfdef, :class, :module case self.node_type when :defn, :methdef, :class self[3..-1] when :defs, :selfdef self[4..-1] when :module self[2..-1] end end
Sets body, which is now a complicated process because the body is no longer a separate Sexp, but just a list of Sexps.
# File lib/ruby_parser/bm_sexp.rb, line 439 def body= exp expect :defn, :defs, :methdef, :selfdef, :class, :module case self.node_type when :defn, :methdef, :class index = 3 when :defs, :selfdef index = 4 when :module index = 2 end self.slice!(index..-1) #Remove old body #Insert new body exp.each do |e| self[index] = e index += 1 end end
Returns the call Sexp in a result returned from FindCall
# File lib/ruby_parser/bm_sexp.rb, line 499 def call expect :result self.last end
# File lib/ruby_parser/bm_sexp.rb, line 486 def class_name expect :class, :module self[1] end
# File lib/ruby_parser/bm_sexp.rb, line 89 def compact @my_hash_value = nil old_compact end
Returns condition of an if expression:
s(:if, s(:lvar, :condition), <-- condition s(:lvar, :then_val), s(:lvar, :else_val)))
# File lib/ruby_parser/bm_sexp.rb, line 303 def condition expect :if self[1] end
# File lib/ruby_parser/bm_sexp.rb, line 224 def each_arg replace = false expect :call, :attrasgn, :super, :zsuper range = nil case self.node_type when :call, :attrasgn if self[3] range = (3...self.length) end when :super, :zsuper if self[1] range = (1...self.length) end end if range range.each do |i| res = yield self[i] self[i] = res if replace end end self end
# File lib/ruby_parser/bm_sexp.rb, line 249 def each_arg! &block self.each_arg true, &block end
Returns 'else' clause of an if expression:
s(:if, s(:lvar, :condition), s(:lvar, :then_val), s(:lvar, :else_val))) ^---else caluse---^
# File lib/ruby_parser/bm_sexp.rb, line 326 def else_clause expect :if self[3] end
Raise a WrongSexpError if the nodes type does not match one of the expected types.
# File lib/ruby_parser/bm_sexp.rb, line 124 def expect *types unless types.include? self.node_type raise WrongSexpError, "Expected #{types.join ' or '} but given #{self.inspect}", caller[1..-1] end end
# File lib/ruby_parser/bm_sexp.rb, line 84 def file= *args @my_hash_value = nil old_file_set(*args) end
# File lib/ruby_parser/bm_sexp.rb, line 94 def find_and_replace_all *args @my_hash_value = nil old_fara(*args) end
# File lib/ruby_parser/bm_sexp.rb, line 99 def find_node *args @my_hash_value = nil old_find_node(*args) end
Returns first argument of a method call.
# File lib/ruby_parser/bm_sexp.rb, line 254 def first_arg expect :call, :attrasgn self[3] end
Sets first argument of a method call.
# File lib/ruby_parser/bm_sexp.rb, line 260 def first_arg= exp expect :call, :attrasgn self[3] = exp end
# File lib/ruby_parser/bm_sexp.rb, line 379 def first_param expect :args self[1] end
# File lib/ruby_parser/bm_sexp.rb, line 426 def formal_args expect :defn, :defs, :methdef, :selfdef case self.node_type when :defn, :methdef self[2] when :defs, :selfdef self[3] end end
# File lib/ruby_parser/bm_sexp.rb, line 66 def hash #There still seems to be some instances in which the hash of the #Sexp changes, but I have not found what method call is doing it. #Of course, Sexp is subclasses from Array, so who knows what might #be going on. @my_hash_value ||= super end
# File lib/ruby_parser/bm_sexp.rb, line 287 def last_arg expect :call, :attrasgn if self[3] self[-1] else nil end end
Returns the left hand side of assignment or boolean:
s(:lasgn, :x, s(:lit, 1)) ^--lhs
# File lib/ruby_parser/bm_sexp.rb, line 388 def lhs expect *ASSIGNMENT_BOOL self[1] end
Sets the left hand side of assignment or boolean.
# File lib/ruby_parser/bm_sexp.rb, line 394 def lhs= exp expect *ASSIGNMENT_BOOL self[1] = exp end
# File lib/ruby_parser/bm_sexp.rb, line 74 def line num = nil @my_hash_value = nil if num old_line(num) end
# File lib/ruby_parser/bm_sexp.rb, line 79 def line= *args @my_hash_value = nil old_line_set(*args) end
Returns method of a method call:
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
^- method
# File lib/ruby_parser/bm_sexp.rb, line 149 def method expect :call, :attrasgn, :super, :zsuper, :result case self.node_type when :call, :attrasgn self[2] when :super, :zsuper :super when :result self.last end end
# File lib/ruby_parser/bm_sexp.rb, line 8 def method_missing name, *args #Brakeman does not use this functionality, #so overriding it to raise a NoMethodError. # #The original functionality calls find_node and optionally #deletes the node if found. raise NoMethodError.new("No method '#{name}' for Sexp", name, args) end
Returns name of method being defined in a method definition.
# File lib/ruby_parser/bm_sexp.rb, line 415 def method_name expect :defn, :defs, :methdef, :selfdef case self.node_type when :defn, :methdef self[1] when :defs, :selfdef self[2] end end
Returns the module the call is inside
# File lib/ruby_parser/bm_sexp.rb, line 506 def module expect :result self[1] end
# File lib/ruby_parser/bm_sexp.rb, line 40 def node_type= type self[0] = type end
# File lib/ruby_parser/bm_sexp.rb, line 56 def original_line line = nil if line @my_hash_value = nil @original_line = line self else @original_line ||= nil end end
# File lib/ruby_parser/bm_sexp.rb, line 104 def paren= arg @my_hash_value = nil @paren = arg end
# File lib/ruby_parser/bm_sexp.rb, line 493 def parent_name expect :class self[2] end
# File lib/ruby_parser/bm_sexp.rb, line 481 def render_type expect :render self[1] end
Return the class the call is inside
# File lib/ruby_parser/bm_sexp.rb, line 513 def result_class expect :result self[2] end
Returns right side (value) of assignment or boolean:
s(:lasgn, :x, s(:lit, 1)) ^--rhs---^
# File lib/ruby_parser/bm_sexp.rb, line 403 def rhs expect *ASSIGNMENT_BOOL self[2] end
Sets the right hand side of assignment or boolean.
# File lib/ruby_parser/bm_sexp.rb, line 409 def rhs= exp expect *ASSIGNMENT_BOOL self[2] = exp end
Returns second argument of a method call.
# File lib/ruby_parser/bm_sexp.rb, line 266 def second_arg expect :call, :attrasgn self[4] end
Sets second argument of a method call.
# File lib/ruby_parser/bm_sexp.rb, line 272 def second_arg= exp expect :call, :attrasgn self[4] = exp end
# File lib/ruby_parser/bm_sexp.rb, line 176 def set_args *exp self.arglist = exp end
Returns target of a method call:
s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
^-----------target-----------^
# File lib/ruby_parser/bm_sexp.rb, line 134 def target expect :call, :attrasgn self[1] end
Sets the target of a method call:
# File lib/ruby_parser/bm_sexp.rb, line 140 def target= exp expect :call, :attrasgn self[1] = exp end
Returns 'then' clause of an if expression:
s(:if, s(:lvar, :condition), s(:lvar, :then_val), <-- then clause s(:lvar, :else_val)))
# File lib/ruby_parser/bm_sexp.rb, line 314 def then_clause expect :if self[2] end
# File lib/ruby_parser/bm_sexp.rb, line 277 def third_arg expect :call, :attrasgn self[5] end
# File lib/ruby_parser/bm_sexp.rb, line 282 def third_arg= exp expect :call, :attrasgn self[5] = exp end
# File lib/ruby_parser/bm_sexp.rb, line 36 def to_sym self.value.to_sym end
Generated with the Darkfish Rdoc Generator 2.