Class: RedParse::SequenceNode
- Inherits:
-
ListOpNode
- Object
- Array
- Node
- ValueNode
- ListOpNode
- RedParse::SequenceNode
- 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
Direct Known Subclasses
Constant Summary collapse
- LITFIX =
LiteralNode&-{:val=>Fixnum}
- LITRANGE =
RangeNode&-{:left=>LITFIX,:right=>LITFIX}
- LITSTR =
Recursive(ls={},StringNode&-{:char=>/^[^`\[{]$/}&+[(String|ls).+])
- LITCAT =
LITCAT=proc{|item| item.grep(~LITSTR).empty?} class<<LITCAT; alias === call; end
StringCatNode& item_that.grep(~LITSTR).empty?
- LITUPLUS =
Recursive(lup={}, UnOpNode&-{:op=>"+@", :val=> (LiteralNode&-{:val=>Symbol|Numeric})| (StringNode&-{:size=>1,:char=>"/"})| lup } )
- LITNODE =
LiteralNode|NopNode|LITSTR|LITCAT|(VarLikeNode&-{:name=>/^__/})|LITUPLUS
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
- #+(other) ⇒ Object
- #[]=(*args) ⇒ Object
- #image ⇒ Object
-
#initialize(*args) ⇒ SequenceNode
constructor
A new instance of SequenceNode.
-
#parsetree(o) ⇒ Object
VarNode| #why not this too?.
- #reducer_ident ⇒ Object
- #rip(p) ⇒ Object
- #to_lisp ⇒ Object
- #to_lisp_with_parens ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
Methods inherited from ValueNode
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, #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 RedParse::Stackable::Meta
#build_exemplars, #enumerate_exemplars, #identity_param
Methods included from FlattenedIvars
#flattened_ivars, #flattened_ivars_equal?
Methods included from Stackable
Constructor Details
#initialize(*args) ⇒ SequenceNode
Returns a new instance of SequenceNode.
1542 1543 1544 1545 1546 |
# File 'lib/redparse/node.rb', line 1542 def initialize(*args) return if args.empty? super @offset=self.first.offset end |
Instance Method Details
#+(other) ⇒ Object
1547 1548 1549 1550 1551 1552 1553 |
# File 'lib/redparse/node.rb', line 1547 def +(other) if SequenceNode===other dup.push( *other ) else dup.push other end end |
#[]=(*args) ⇒ Object
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 |
# File 'lib/redparse/node.rb', line 1555 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 |
#image ⇒ Object
1567 |
# File 'lib/redparse/node.rb', line 1567 def image; '(;)' end |
#parsetree(o) ⇒ Object
VarNode| #why not this too?
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 |
# File 'lib/redparse/node.rb', line 1591 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 result= if items.size>1 items.unshift :block elsif items.size==1 items.first else items end limit=o[:quirks] ? 1 : result.size-1 (0..limit).each{|i| result[i,1]=result[i][1..-1] if Array===result[i] and result[i][0]==:block } return result end |
#reducer_ident ⇒ Object
17345 17346 17347 |
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17345 def reducer_ident :SequenceNode end |
#rip(p) ⇒ Object
77 78 79 |
# File 'lib/redparse/ripper.rb', line 77 def rip p stmts_rip self,p end |
#to_lisp ⇒ Object
1568 1569 1570 |
# File 'lib/redparse/node.rb', line 1568 def to_lisp "#{map{|x| x.to_lisp}.join("\n")}" end |
#to_lisp_with_parens ⇒ Object
1572 1573 1574 |
# File 'lib/redparse/node.rb', line 1572 def to_lisp_with_parens "(#{to_lisp})" end |
#unparse(o = default_unparse_options) ⇒ Object
1631 1632 1633 1634 1635 1636 1637 |
# File 'lib/redparse/node.rb', line 1631 def unparse o= return "" if empty? unparse_nl(first,o,'')+first.unparse(o)+ self[1..-1].map{|expr| unparse_nl(expr,o)+expr.unparse(o) }.join end |