Class: RedParse::LogicalNode
- Includes:
- KeywordOpNode
- Defined in:
- lib/redparse/node.rb,
lib/redparse/node.rb
Constant Summary collapse
- OP_EXPAND =
{?o=>"or", ?a=>"and", ?&=>"&&", ?|=>"||", nil=>""}
- OP_EQUIV =
{?o=>"or", ?a=>"and", ?&=>"and", ?|=>"or"}
Constants included from FlattenedIvars
FlattenedIvars::EXCLUDED_IVARS
Instance Attribute Summary collapse
-
#opmap ⇒ Object
readonly
Returns the value of attribute opmap.
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
-
#initialize(left, op, right) ⇒ LogicalNode
constructor
A new instance of LogicalNode.
- #left ⇒ Object
- #left=(val) ⇒ Object
- #parsetree(o) ⇒ Object
- #right ⇒ Object
- #right=(val) ⇒ Object
- #special_conditions! ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object
Methods inherited from RawOpNode
Methods inherited from ValueNode
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!, #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, #to_parsetree, #to_parsetree_and_warnings, #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
Constructor Details
#initialize(left, op, right) ⇒ LogicalNode
Returns a new instance of LogicalNode.
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 |
# File 'lib/redparse/node.rb', line 2656 def initialize(left,op,right) op=op.ident if op.respond_to? :ident @opmap=op[0,1] case op when "&&"; op="and" when "||"; op="or" end #@reverse= op=="or" #@op=op replace [left,right] (size-1).downto(0){|i| expr=self[i] if self.class==expr.class self[i,1]=Array.new expr opmap[i,0]=expr.opmap end } end |
Instance Attribute Details
#opmap ⇒ Object (readonly)
Returns the value of attribute opmap.
2674 2675 2676 |
# File 'lib/redparse/node.rb', line 2674 def opmap @opmap end |
Class Method Details
.[](*list) ⇒ Object
2647 2648 2649 2650 2651 2652 2653 2654 |
# File 'lib/redparse/node.rb', line 2647 def self.[](*list) =list.pop if Hash===list.last result=allocate.replace list opmap=[:@opmap] if and [:@opmap] opmap||=result.op[0,1]*(list.size-1) result.instance_variable_set(:@opmap, opmap) return result end |
Instance Method Details
#left ⇒ Object
2691 2692 2693 |
# File 'lib/redparse/node.rb', line 2691 def left self[0] end |
#left=(val) ⇒ Object
2694 2695 2696 |
# File 'lib/redparse/node.rb', line 2694 def left= val self[0]=val end |
#parsetree(o) ⇒ Object
2704 2705 2706 2707 2708 2709 2710 2711 2712 |
# File 'lib/redparse/node.rb', line 2704 def parsetree(o) result=[].replace(self).reverse last=result.shift.begin_parsetree(o) first=result.pop result=result.inject(last){|sum,x| [op.to_sym, x.begin_parsetree(o), sum] } [op.to_sym, first.rescue_parsetree(o), result] end |
#right ⇒ Object
2697 2698 2699 |
# File 'lib/redparse/node.rb', line 2697 def right self[1] end |
#right=(val) ⇒ Object
2700 2701 2702 |
# File 'lib/redparse/node.rb', line 2700 def right= val self[1]=val end |
#special_conditions! ⇒ Object
2714 2715 2716 2717 2718 2719 2720 |
# File 'lib/redparse/node.rb', line 2714 def special_conditions! each{|x| if x.respond_to? :special_conditions! and !(ParenedNode===x) x.special_conditions! end } end |
#unparse(o = default_unparse_options) ⇒ Object
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 |
# File 'lib/redparse/node.rb', line 2679 def unparse o= result='' each_with_index{|expr,i| result.concat expr.unparse(o) result.concat ?\s result.concat OP_EXPAND[@opmap[i]] result.concat ?\s } return result end |