Class: RedParse::ConstantNode

Inherits:
ListOpNode show all
Defined in:
lib/redparse/node.rb,
lib/redparse/ripper.rb,
lib/redparse/ReduceWithsFor_RedParse_1_9.rb,
lib/redparse/ReduceWithsFor_RedParse_1_8.rb

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary collapse

Attributes inherited from Node

#endline, #errors, #offset, #parent, #startline

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Instance Method Summary collapse

Methods inherited from ValueNode

#reducer_method

Methods inherited from Node

#+, #+@, #==, [], #[]=, #add_parent_links!, #args_rip, #begin_parsetree, #classic_inspect, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #force_stmt_list_rip, #initialize_ivars, inline_symbols, #lhs_unparse, #linerange, #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, #rfind, #rfind_all, #rgrep, #rip_and_rescues, #rip_explode!, #short_inspect, #stmts_rip, #to_parsetree, #to_parsetree_and_warnings, #to_ruby, #to_s, #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

#identity_name

Constructor Details

#initialize(*args) ⇒ ConstantNode

Returns a new instance of ConstantNode.



1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
# File 'lib/redparse/node.rb', line 1914

def initialize(*args)
  @offset=args.first.offset
  args.unshift nil if args.size==2
  args.map!{|node| 
    if VarNode===node and (?A..?Z)===node.ident[0]
    then node.ident 
    else node
    end
  }
  super(*args)  
end

Instance Attribute Details

#lvalueObject



1952
1953
1954
1955
# File 'lib/redparse/node.rb', line 1952

def lvalue
  return @lvalue if defined? @lvalue
  @lvalue=true
end

Instance Method Details

#inspect(label = nil, indent = 0, verbose = false) ⇒ Object



1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
# File 'lib/redparse/node.rb', line 1959

def inspect label=nil,indent=0,verbose=false
  result=' '*indent
  result+="#{label}: " if label 
  result+='Constant '
  unless String===first or nil==first
    head=first
    rest=self[1..-1]
  end
  result+=(rest||self).map{|name| name.inspect}.join(', ')+"\n"
  result+=head.inspect("head",indent+2,verbose) if head
  return result
end

#lvalue_parsetree(o) ⇒ Object



1934
1935
1936
# File 'lib/redparse/node.rb', line 1934

def lvalue_parsetree(o)
  [:cdecl,parsetree(o)]
end

#parsetree(o) ⇒ Object



1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
# File 'lib/redparse/node.rb', line 1937

def parsetree(o)
  if !first
    result=[:colon3, self[1].to_sym]
    i=2
  else
    result=first.respond_to?(:parsetree) ? 
             first.parsetree(o) :
             [:const,first.to_sym]
    i=1
  end
  (i...size).inject(result){|r,j| 
    [:colon2, r, self[j].to_sym]
  }
end

#reducer_identObject



17355
17356
17357
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17355

def reducer_ident
  :ConstantNode
end

#rip(p) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/redparse/ripper.rb', line 204

def rip p
  if first
    start=p.on_var_ref \
      p.on_const(first)
    start_i=1
  else
    start=p.on_top_const_ref \
      p.on_const(self[1])
    start_i=2
  end
  (start_i...size).inject(start){|sum,i| 
    p.on_const_path_ref(sum,p.on_const(self[i])) 
  }
end

#unparse(o = default_unparse_options) ⇒ Object Also known as: image



1925
1926
1927
1928
1929
1930
1931
1932
# File 'lib/redparse/node.rb', line 1925

def unparse(o=default_unparse_options)
  if Node===first
    result=dup
    result[0]= first.unparse(o)#.gsub(/\s+\Z/,'')
    result.join('::')
  else join('::')
  end
end