diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 15:05:27 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 15:05:27 -0700 |
commit | 66daee0543ca38db854b6960256d2a4fe9d77295 (patch) | |
tree | 15c0623295a369a82bcaa8239e388ba86d5439aa /lib | |
parent | cace67f720786328ba94009195b85945244962db (diff) | |
download | psych-66daee0543ca38db854b6960256d2a4fe9d77295.zip |
return explicit strings
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/scalar_scanner.rb | 12 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 5 |
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index 538edb3..e8cd748 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -22,20 +22,20 @@ module Psych [:NULL, nil] when /^:/i [:SYMBOL, @string.sub(/^:/, '').to_sym] - when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/ + when /^[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+$/ i = 0 @string.split(':').each_with_index do |n,e| - i += (n.to_f * 60 ** (e - 2).abs) + i += (n.to_i * 60 ** (e - 2).abs) end - [:FLOAT, i] - when /^[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+$/ + [:INTEGER, i] + when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/ i = 0 @string.split(':').each_with_index do |n,e| - i += (n.to_i * 60 ** (e - 2).abs) + i += (n.to_f * 60 ** (e - 2).abs) end - [:INTEGER, i] + [:FLOAT, i] else return [:FLOAT, Float(@string.gsub(/[,_]/, ''))] rescue ArgumentError return [:INTEGER, Integer(@string.gsub(/[,_]/, ''))] rescue ArgumentError diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 836c0b6..a83892f 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -13,9 +13,10 @@ module Psych def visit_Psych_Nodes_Scalar o @st[o.anchor] = o.value if o.anchor - return ScalarScanner.new(o.value).tokenize.last unless o.quoted + return o.value if ['!str', 'tag:yaml.org,2002:str'].include?(o.tag) + return o.value if o.quoted - o.value + return ScalarScanner.new(o.value).tokenize.last unless o.quoted end def visit_Psych_Nodes_Sequence o |