Class: RedParse::SequenceNode

Inherits:
ListOpNode show all
Defined in:
lib/redparse/node.rb

Constant Summary collapse

LITFIX =
LiteralNode&-{:val=>Fixnum}
LITRANGE =
RangeNode&-{:left=>LITFIX,:right=>LITFIX}
LITSTR =
StringNode&-{:size=>1,:char=>/^[^`\[{]$/}
#LITCAT=proc{|item| item.grep(~LITSTR).empty?}
#class<<LITCAT; alias === call; end
LITCAT =

LITCAT=proc{|item| item.grep(~LITSTR).empty?} class<<LITCAT; alias === call; end

StringCatNode& item_that.grep(~LITSTR).empty?
LITNODE =
LiteralNode|NopNode|LITSTR|LITCAT|LITRANGE|(VarLikeNode&-{:name=>/^__/})

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary

Attributes inherited from Node

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

Attributes included from RedParse::Stackable::Meta

#boolean_identity_params, #identity_params

Instance Method Summary collapse

Methods inherited from ValueNode

#lvalue

Methods inherited from Node

#+@, #==, [], #add_parent_links!, #begin_parsetree, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #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, #to_parsetree, #to_parsetree_and_warnings, #unary, #walk, #xform_tree!

Methods included from RedParse::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) ⇒ SequenceNode

Returns a new instance of SequenceNode.



1448
1449
1450
1451
# File 'lib/redparse/node.rb', line 1448

def initialize(*args)
  super
  @offset=self.first.offset
end

Instance Method Details

#+(other) ⇒ Object



1452
1453
1454
1455
1456
1457
1458
# File 'lib/redparse/node.rb', line 1452

def +(other)
  if SequenceNode===other
    dup.push( *other )
  else
    dup.push other
  end
end

#[]=(*args) ⇒ Object



1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
# File 'lib/redparse/node.rb', line 1460

def []=(*args)
  val=args.pop
  if SequenceNode===val
    val=Array.new(val)
    #munge args too
    if args.size==1 and Integer===args.first
      args<<1
    end
  end
  super( *args<<val )
end

#imageObject



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

def image; '(;)' end

#parsetree(o) ⇒ Object

VarNode| #why not this too?



1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
# File 'lib/redparse/node.rb', line 1489

def parsetree(o)
  data=compact
  data.empty? and return
  items=Array.new(data[0...-1])
  if o[:quirks]
    items.shift while LITNODE===items.first
  else
    items.reject!{|expr| LITNODE===expr }
  end
  items.map!{|expr| expr.rescue_parsetree(o)}.push last.parsetree(o)
#        items=map{|expr| expr.parsetree(o)}
  items.reject!{|expr| []==expr }
  if o[:quirks] 
    unless BeginNode===data[0]
      header=items.first
      (items[0,1] = *header[1..-1]) if header and header.first==:block
    end
  else
    (items.size-1).downto(0){|i|
      header=items[i]
      (items[i,1] = *header[1..-1]) if header and header.first==:block
    }     
  end
  if items.size>1
    items.unshift :block
  elsif items.size==1
    items.first
  else
    items
  end
end

#to_lispObject



1473
1474
1475
# File 'lib/redparse/node.rb', line 1473

def to_lisp
  "#{map{|x| x.to_lisp}.join("\n")}"
end

#to_lisp_with_parensObject



1477
1478
1479
# File 'lib/redparse/node.rb', line 1477

def to_lisp_with_parens
  "(#{to_lisp})"
end

#unparse(o = default_unparse_options) ⇒ Object



1521
1522
1523
1524
1525
1526
1527
# File 'lib/redparse/node.rb', line 1521

def unparse o=default_unparse_options
  return "" if empty?
  unparse_nl(first,o,'')+first.unparse(o)+
  self[1..-1].map{|expr| 
    unparse_nl(expr,o)+expr.unparse(o)
  }.join
end