Class Sexp
In: lib/ruby_parser/bm_sexp.rb
Parent: Object

Sexp changes from ruby_parser and some changes for caching hash value and tracking ‘original’ line number of a Sexp.

Methods

Constants

ASSIGNMENT_BOOL = [:gasgn, :iasgn, :lasgn, :cvdecl, :cvasgn, :cdecl, :or, :and, :colon2, :op_asgn_or]
CALLS = [:call, :attrasgn, :safe_call, :safe_attrasgn]

External Aliases

sexp_type -> node_type
sexp_body -> values
<< -> old_push
compact -> old_compact
find_and_replace_all -> old_fara
find_node -> old_find_node

Attributes

or_depth  [RW] 
original_line  [RW] 

Public Instance methods

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 ------------^

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--------^

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 --------------------------^

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))))

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))))

Returns body of a method definition, class, or module. This will be an untyped Sexp containing a list of Sexps from the body.

Sets body, which is now a complicated process because the body is no longer a separate Sexp, but just a list of Sexps.

Like Sexp#body, except the returned Sexp is of type :rlist instead of untyped.

Returns the call Sexp in a result returned from FindCall

Join self and exp into an :or Sexp. Sets or_depth. Used for combining "branched" values in AliasProcessor.

Returns condition of an if expression:

    s(:if,
     s(:lvar, :condition), <-- condition
     s(:lvar, :then_val),
     s(:lvar, :else_val)))

Create clone of Sexp and nested Sexps but not their non-Sexp contents. If a line number is provided, also sets line/original_line on all Sexps.

Returns ‘else’ clause of an if expression:

    s(:if,
     s(:lvar, :condition),
     s(:lvar, :then_val),
     s(:lvar, :else_val)))
     ^---else caluse---^

Raise a WrongSexpError if the nodes type does not match one of the expected types.

Returns first argument of a method call.

Sets first argument of a method call.

Returns the left hand side of assignment or boolean:

    s(:lasgn, :x, s(:lit, 1))
               ^--lhs

Sets the left hand side of assignment or boolean.

Returns method of a method call:

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))

                        ^- method

Returns name of method being defined in a method definition.

Returns the module the call is inside

module_name()

Alias for class_name

Return the class the call is inside

Returns right side (value) of assignment or boolean:

    s(:lasgn, :x, s(:lit, 1))
                  ^--rhs---^

Sets the right hand side of assignment or boolean.

Returns second argument of a method call.

Sets second argument of a method call.

Returns target of a method call:

s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))

         ^-----------target-----------^

Returns ‘then’ clause of an if expression:

    s(:if,
     s(:lvar, :condition),
     s(:lvar, :then_val), <-- then clause
     s(:lvar, :else_val)))

[Validate]