class RedParse::ListInNode::LiteralNode
Constants
- Inf
- Nan
Attributes
offset[RW]
string[RW]
Public Class Methods
create(old_val)
click to toggle source
# 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) #ugly hack: this isn't literal else val=old_val.raw.translate_escapes(old_val.raw.elems.first).to_sym end else #val=val[1..-1].to_sym 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)
click to toggle source
# File lib/redparse/node.rb, line 4115 def self.inline_symbols data #don't mangle symbols when constructing node like: LiteralNode[:foo] data end
Public Instance Methods
[]=(*args)
click to toggle source
# File lib/redparse/node.rb, line 4120 def []=(*args) original_brackets_assign( *args ) end
bare_method()
click to toggle source
# File lib/redparse/node.rb, line 4124 def bare_method Symbol===val || StringNode===val end
image()
click to toggle source
# File lib/redparse/node.rb, line 4130 def image; "(#{':' if Symbol===val}#{val})" end
parsetree(o)
click to toggle source
# File lib/redparse/node.rb, line 4163 def parsetree(o) val=val() case val when StringNode #ugly hack 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
to_lisp()
click to toggle source
# File lib/redparse/node.rb, line 4132 def to_lisp return val.to_s end
unparse(o=default_unparse_options)
click to toggle source
# File lib/redparse/node.rb, line 4139 def unparse o=default_unparse_options val=val() case val when StringNode #ugly hack ":"+ 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