31: def visit_Psych_Nodes_Scalar(o)
32: @st[o.anchor] = o.value if o.anchor
33:
34: if klass = Psych.load_tags[o.tag]
35: instance = klass.allocate
36:
37: if instance.respond_to?(:init_with)
38: coder = Psych::Coder.new(o.tag)
39: coder.scalar = o.value
40: instance.init_with coder
41: end
42:
43: return instance
44: end
45:
46: return o.value if o.quoted
47: return @ss.tokenize(o.value) unless o.tag
48:
49: case o.tag
50: when '!binary', 'tag:yaml.org,2002:binary'
51: o.value.unpack('m').first
52: when '!str', 'tag:yaml.org,2002:str'
53: o.value
54: when "!ruby/object:DateTime"
55: require 'date'
56: @ss.parse_time(o.value).to_datetime
57: when "!ruby/object:Complex"
58: Complex(o.value)
59: when "!ruby/object:Rational"
60: Rational(o.value)
61: when "!ruby/class", "!ruby/module"
62: resolve_class o.value
63: when "tag:yaml.org,2002:float", "!float"
64: Float(@ss.tokenize(o.value))
65: when "!ruby/regexp"
66: o.value =~ /^\/(.*)\/([mixn]*)$/
67: source = $1
68: options = 0
69: lang = nil
70: ($2 || '').split('').each do |option|
71: case option
72: when 'x' then options |= Regexp::EXTENDED
73: when 'i' then options |= Regexp::IGNORECASE
74: when 'm' then options |= Regexp::MULTILINE
75: when 'n' then options |= Regexp::NOENCODING
76: else lang = option
77: end
78: end
79: Regexp.new(*[source, options, lang].compact)
80: when "!ruby/range"
81: args = o.value.split(/([.]{2,3})/, 2).map { |s|
82: accept Nodes::Scalar.new(s)
83: }
84: args.push(args.delete_at(1) == '...')
85: Range.new(*args)
86: when /^!ruby\/sym(bol)?:?(.*)?$/
87: o.value.to_sym
88: else
89: @ss.tokenize o.value
90: end
91: end