Class: RedParse::LiteralNode
- Inherits:
-
ValueNode
show all
- 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
Constant Summary
collapse
- Inf =
"999999999999999999999999999999999.9e999999999999999999999999999999999999"
- Nan =
"****shouldnt ever happen****"
FlattenedIvars::EXCLUDED_IVARS
Instance Attribute Summary collapse
Attributes inherited from Node
#endline, #errors, #parent, #startline
#boolean_identity_params, #identity_params
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ValueNode
#lvalue, #reducer_method
Methods inherited from Node
#+, #+@, #==, [], #add_parent_links!, #args_rip, #begin_parsetree, #classic_inspect, #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, #initialize_ivars, #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
This class inherits a constructor from RedParse::Node
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
4077
4078
4079
|
# File 'lib/redparse/node.rb', line 4077
def offset
@offset
end
|
#string ⇒ Object
Returns the value of attribute string.
4077
4078
4079
|
# File 'lib/redparse/node.rb', line 4077
def string
@string
end
|
Class Method Details
.create(old_val) ⇒ Object
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
|
# File 'lib/redparse/node.rb', line 4078
def self.create(old_val)
offset=old_val.offset
val=old_val.ident
case old_val
when SymbolToken
case val[1]
when ?' assert !old_val.raw.has_str_inc?
val=old_val.raw.translate_escapes(old_val.raw.elems.first).to_sym
when ?" if old_val.raw.has_str_inc? or old_val.raw.elems==[""]
val=StringNode.new(old_val.raw) else
val=old_val.raw.translate_escapes(old_val.raw.elems.first).to_sym
end
else val=old_val.raw
if StringToken===val
val=val.translate_escapes(val.elems.first)
elsif /^[!~]@$/===val
val=val.chop
end
val=val.to_sym
end
when NumberToken
case val
when /\A[+-]?0([^.]|\Z)/; val=val.oct
when /[.e]/i; orig=val; val=val.to_f
else val=val.to_i
end
end
result=LiteralNode.new(val)
result.string=orig if orig
result.offset=offset
result
end
|
.inline_symbols(data) ⇒ Object
4115
4116
4117
4118
|
# File 'lib/redparse/node.rb', line 4115
def self.inline_symbols data
data
end
|
Instance Method Details
#[]=(*args) ⇒ Object
4120
4121
4122
|
# File 'lib/redparse/node.rb', line 4120
def []=(*args)
original_brackets_assign( *args )
end
|
#bare_method ⇒ Object
4124
4125
4126
|
# File 'lib/redparse/node.rb', line 4124
def bare_method
Symbol===val || StringNode===val
end
|
#image ⇒ Object
4130
|
# File 'lib/redparse/node.rb', line 4130
def image; "(#{':' if Symbol===val}#{val})" end
|
#parsetree(o) ⇒ Object
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
|
# File 'lib/redparse/node.rb', line 4163
def parsetree(o)
val=val()
case val
when StringNode result= val.parsetree(o)
result[0]=:dsym
return result
=begin
when String
#float or real string? or keyword?
val=
case val
when Numeric: val
when Symbol: val
when String: val
when "true": true
when "false": false
when "nil": nil
when "self": return :self
when "__FILE__": "wrong-o"
when "__LINE__": "wrong-o"
else fail "unknown token type in LiteralNode: #{val.class}"
end
=end
end
return [:lit,val]
end
|
#reducer_ident ⇒ Object
17340
17341
17342
|
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17340
def reducer_ident
:LiteralNode
end
|
#rip(p) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/redparse/ripper.rb', line 63
def rip p
if Symbol===val
p.on_symbol_literal \
p.on_symbol \
p.on_ident(val.to_s)
elsif Integer===val
p.on_int(val.to_s)
else fail
end
end
|
#to_lisp ⇒ Object
4132
4133
4134
|
# File 'lib/redparse/node.rb', line 4132
def to_lisp
return val.to_s
end
|
#unparse(o = default_unparse_options) ⇒ Object
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
|
# File 'lib/redparse/node.rb', line 4139
def unparse o=default_unparse_options
val=val()
case val
when StringNode ":"+
val.unparse(o)
when Float
if defined? @string;
@string
else
s= val.accurate_to_s
case s
when /-inf/i; s="-"+Inf
when /inf/i; s= Inf
when /nan/i; s= Nan
else
fail "float coercion not stable" unless [s.to_f].pack("d")==[val].pack("d")
end
s
end
else val.inspect
end
end
|