Class: RedParse::LogicalNode
- Inherits:
-
RawOpNode
show all
- Includes:
- KeywordOpNode
- Defined in:
- lib/redparse/node.rb,
lib/redparse/node.rb,
lib/redparse/ReduceWithsFor_RedParse_1_9.rb,
lib/redparse/ReduceWithsFor_RedParse_1_8.rb
Constant Summary
collapse
- OP_EXPAND =
{?o=>"or", ?a=>"and", ?&=>"&&", ?|=>"||", nil=>""}
- OP_EQUIV =
{?o=>"or", ?a=>"and", ?&=>"and", ?|=>"or"}
FlattenedIvars::EXCLUDED_IVARS
Instance Attribute Summary collapse
Attributes inherited from Node
#endline, #errors, #offset, #parent, #startline
#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!
#build_exemplars, #enumerate_exemplars, #identity_param
#flattened_ivars, #flattened_ivars_equal?
Methods included from Stackable
#identity_name
Constructor Details
#initialize(left, op, right) ⇒ LogicalNode
Returns a new instance of LogicalNode.
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
|
# File 'lib/redparse/node.rb', line 2827
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
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
Returns the value of attribute opmap.
2845
2846
2847
|
# File 'lib/redparse/node.rb', line 2845
def opmap
@opmap
end
|
Class Method Details
.[](*list) ⇒ Object
2818
2819
2820
2821
2822
2823
2824
2825
|
# File 'lib/redparse/node.rb', line 2818
def self.[](*list)
options=list.pop if Hash===list.last
result=allocate.replace list
opmap=options[:@opmap] if options and options[:@opmap]
opmap||=result.op[0,1]*(list.size-1)
result.instance_variable_set(:@opmap, opmap)
return result
end
|
Instance Method Details
#left ⇒ Object
2862
2863
2864
|
# File 'lib/redparse/node.rb', line 2862
def left
self[0]
end
|
#left=(val) ⇒ Object
2865
2866
2867
|
# File 'lib/redparse/node.rb', line 2865
def left= val
self[0]=val
end
|
#parsetree(o) ⇒ Object
2875
2876
2877
2878
2879
2880
2881
2882
2883
|
# File 'lib/redparse/node.rb', line 2875
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
|
#reducer_ident ⇒ Object
17395
17396
17397
|
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17395
def reducer_ident
:LogicalNode
end
|
#right ⇒ Object
2868
2869
2870
|
# File 'lib/redparse/node.rb', line 2868
def right
self[1]
end
|
#right=(val) ⇒ Object
2871
2872
2873
|
# File 'lib/redparse/node.rb', line 2871
def right= val
self[1]=val
end
|
#special_conditions! ⇒ Object
2885
2886
2887
2888
2889
2890
2891
|
# File 'lib/redparse/node.rb', line 2885
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
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
|
# File 'lib/redparse/node.rb', line 2850
def unparse o=default_unparse_options
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
|