Class: RedParse::VarNode
- Includes:
- FlattenedIvars
- Defined in:
- 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 collapse
-
#endline ⇒ Object
(also: #startline)
Returns the value of attribute endline.
-
#in_def ⇒ Object
readonly
Returns the value of attribute in_def.
- #lvalue ⇒ Object
-
#lvar_type ⇒ Object
readonly
Returns the value of attribute lvar_type.
-
#offset ⇒ Object
Returns the value of attribute offset.
Attributes inherited from Node
Attributes included from Stackable::Meta
#boolean_identity_params, #identity_params
Instance Method Summary collapse
- #all_current_lvars ⇒ Object
- #dup ⇒ Object
-
#initialize(tok) ⇒ VarNode
constructor
A new instance of VarNode.
- #lvalue_parsetree(o) ⇒ Object
- #parsetree(o) ⇒ Object
- #reducer_ident ⇒ Object
- #rip(p) ⇒ Object
- #unparse(o = default_unparse_options) ⇒ Object (also: #lhs_unparse)
- #varname2assigntype ⇒ Object
Methods included from FlattenedIvars
#flattened_ivars, #flattened_ivars_equal?
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, #linerange, #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 Stackable
Constructor Details
#initialize(tok) ⇒ VarNode
Returns a new instance of VarNode.
1207 1208 1209 1210 1211 1212 1213 |
# File 'lib/redparse/node.rb', line 1207 def initialize(tok) super(tok.ident) @lvar_type=tok.lvar_type @offset=tok.offset @endline=@startline=tok.endline @in_def=tok.in_def end |
Instance Attribute Details
#endline ⇒ Object Also known as: startline
Returns the value of attribute endline.
1201 1202 1203 |
# File 'lib/redparse/node.rb', line 1201 def endline @endline end |
#in_def ⇒ Object (readonly)
Returns the value of attribute in_def.
1202 1203 1204 |
# File 'lib/redparse/node.rb', line 1202 def in_def @in_def end |
#lvalue ⇒ Object
1273 1274 1275 1276 |
# File 'lib/redparse/node.rb', line 1273 def lvalue return @lvalue if defined? @lvalue @lvalue=true end |
#lvar_type ⇒ Object (readonly)
Returns the value of attribute lvar_type.
1202 1203 1204 |
# File 'lib/redparse/node.rb', line 1202 def lvar_type @lvar_type end |
#offset ⇒ Object
Returns the value of attribute offset.
1201 1202 1203 |
# File 'lib/redparse/node.rb', line 1201 def offset @offset end |
Instance Method Details
#all_current_lvars ⇒ Object
1280 1281 1282 |
# File 'lib/redparse/node.rb', line 1280 def all_current_lvars lvar_type==:current ? [ident] : [] end |
#dup ⇒ Object
1285 1286 1287 1288 1289 |
# File 'lib/redparse/node.rb', line 1285 def dup result=super result.ident=ident.dup if ident return result end |
#lvalue_parsetree(o) ⇒ Object
1267 1268 1269 |
# File 'lib/redparse/node.rb', line 1267 def lvalue_parsetree(o) [varname2assigntype, ident.to_sym] end |
#parsetree(o) ⇒ Object
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'lib/redparse/node.rb', line 1222 def parsetree(o) type=case ident[0] when ?$ case ident[1] when ?1..?9; return [:nth_ref,ident[1..-1].to_i] when ?&,?+,?`,?'; return [:back_ref,ident[1].chr.to_sym] #` else :gvar end when ?@ if ident[1]==?@ :cvar else :ivar end when ?A..?Z; :const else case lvar_type when :local; :lvar when :block; :dvar when :current; :dvar#_curr else fail end end return [type,ident.to_sym] end |
#reducer_ident ⇒ Object
17605 17606 17607 |
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17605 def reducer_ident :VarNode end |
#rip(p) ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/redparse/ripper.rb', line 191 def rip p p.on_var_ref( case name[0] when ?$; p.on_gvar(name) when ?@; name[1]==?@ ? p.on_cvar(name) : p.on_ivar(name) when ?A..?Z; p.on_const(name) else p.on_ident(name) end ) end |
#unparse(o = default_unparse_options) ⇒ Object Also known as: lhs_unparse
1293 |
# File 'lib/redparse/node.rb', line 1293 def unparse o=; ident end |
#varname2assigntype ⇒ Object
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/redparse/node.rb', line 1248 def varname2assigntype case ident[0] when ?$; :gasgn when ?@ if ident[1]!=?@; :iasgn elsif in_def; :cvasgn else :cvdecl end when ?A..?Z; :cdecl else case lvar_type when :local; :lasgn when :block; :dasgn when :current; :dasgn_curr else fail end end end |