Class: RedParse::RangeNode

Inherits:
RawOpNode show all
Defined in:
lib/redparse/node.rb,
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

Attributes inherited from Node

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

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RawOpNode

create, #image, #raw_unparse

Methods inherited from ValueNode

#lvalue, #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, #image, #initialize_ivars, inline_symbols, #inspect, #lhs_unparse, #linerange, #lvalue, #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) ⇒ RangeNode

Returns a new instance of RangeNode.



1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
# File 'lib/redparse/node.rb', line 1695

def initialize(*args)
  options=Hash===args.last ? args.pop : {}
  if args.size==2
    left,right=*args
    op=".."
  else
    left,op,right=*args
    op=op.ident if op.respond_to? :ident
  end
  @exclude_end=!!op[2]
  @as_flow_control=false
  super(left,op,right,options)
end

Class Method Details

.[](*list) ⇒ Object

def self.[] *list

  result=RawOpNode[*list]
  result.extend RangeNode
  return result
end


1720
1721
1722
# File 'lib/redparse/node.rb', line 1720

def self.[] *list
  new(*list)
end

Instance Method Details

#beginObject



1708
# File 'lib/redparse/node.rb', line 1708

def begin; first end

#endObject



1709
# File 'lib/redparse/node.rb', line 1709

def end; last end

#exclude_end?Boolean

Returns:

  • (Boolean)


1712
# File 'lib/redparse/node.rb', line 1712

def exclude_end?; @exclude_end end

#leftObject



1710
# File 'lib/redparse/node.rb', line 1710

def left; first end

#parsetree(o) ⇒ Object



1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
# File 'lib/redparse/node.rb', line 1724

def parsetree(o)
  first=first().parsetree(o)
  last=last().parsetree(o)
  if @as_flow_control
    if :lit==first.first and Integer===first.last 
      first=[:call, [:lit, first.last], :==, [:array, [:gvar, :$.]]]
    elsif :lit==first.first && Regexp===first.last or 
          :dregx==first.first || :dregx_once==first.first
      first=[:match, first]
    end

    if :lit==last.first and Integer===last.last
      last=[:call, [:lit, last.last], :==, [:array, [:gvar, :$.]]]
    elsif :lit==last.first && Regexp===last.last or 
          :dregx==last.first || :dregx_once==last.first
      last=[:match, last]
    end

    tag="flip"
  else
    if :lit==first.first and :lit==last.first and
       Fixnum===first.last and Fixnum===last.last and
       LiteralNode===first() and LiteralNode===last()
      return [:lit, Range.new(first.last,last.last,@exclude_end)]
    end
    tag="dot"
  end
  count= @exclude_end ? ?3 : ?2
  tag << count
  [tag.to_sym, first, last]
end

#reducer_identObject



17600
17601
17602
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17600

def reducer_ident
  :RangeNode
end

#rightObject



1711
# File 'lib/redparse/node.rb', line 1711

def right; last end

#rip(p) ⇒ Object



372
373
374
375
# File 'lib/redparse/ripper.rb', line 372

def rip p
  dots= exclude_end? ? :on_dot3 : :on_dot2
  p.send dots, left.rip(p), right.rip(p)
end

#special_conditions!Object



1756
1757
1758
# File 'lib/redparse/node.rb', line 1756

def special_conditions!
  @as_flow_control=true
end

#unparse(o = default_unparse_options) ⇒ Object



1760
1761
1762
1763
1764
1765
# File 'lib/redparse/node.rb', line 1760

def unparse(o=default_unparse_options)
  result=left.unparse(o)+'..'
  result+='.' if exclude_end?
  result << right.unparse(o)
  return result      
end