在一个文件中显然存储了一个多行正则表达式,可以YAML::dump(b1)
毫无问题地保存。
问题,当 Syck 似乎对多行正则表达式有问题时,我该如何加载它?
b2 = YAML::load(File.open("browserObj.yaml", 'r'))
Syck::TypeError: Invalid Regular expression: "/\\A\\s*\n ([a-zA-Z][\\-+.a-zA-Z\\d]*): (?# 1: scheme)\n (?:\n ((?:[\\-_.!~*'()a-zA-Z\\d;?:@&=+$,]|%[a-fA-F\\d]{2})(?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*) \\ (?# 2: opaque)\n |\n (?:(?:\n \\/\\/(?:\n \\ (?:(?:((?:[\\-_.!~*'()a-zA-Z\\d;:&=+$,]|%[a-fA-F\\d]{2})*)@)? \\ (?# 3: userinfo)\n (?:((?:(?:[a-zA-Z0-9\\-.]|%\\h\\h)+|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:(?:[a-fA-F\\d]{1,4}:)*[a-fA-F\\d]{1,4})?::(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))?)\\]))(?::(\\d*))?))? (?# 4: host, 5: port)\n |\n ((?:[\\-_.!~*'()a-zA-Z\\d$,;:@&=+]|%[a-fA-F\\d]{2})+) \\ (?# 6: registry)\n )\n |\n (?!\\/\\/)) \\ (?# XXX: '\\/\\/' is the mark for hostport)\n \\ (\\/(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*(?:;(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*)*(?:\\/(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*(?:;(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*)*)*)? \\ (?# 7: path)\n )(?:\\?((?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*))? \\ (?# 8: query)\n )\n (?:\\#((?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*))? \\ (?# 9: fragment)\n \\s*\\z/x"
from /usr/lib/ruby/1.9.1/syck/rubytypes.rb:284:in `yaml_new'
from /usr/lib/ruby/1.9.1/syck.rb:135:in `transfer'
from /usr/lib/ruby/1.9.1/syck.rb:135:in `node_import'
from /usr/lib/ruby/1.9.1/syck.rb:135:in `load'
from /usr/lib/ruby/1.9.1/syck.rb:135:in `load'
from /usr/lib/ruby/1.9.1/syck.rb:146:in `block in load_file'
from /usr/lib/ruby/1.9.1/syck.rb:145:in `open'
from /usr/lib/ruby/1.9.1/syck.rb:145:in `load_file'
from (irb):428
from /usr/bin/irb:12:in `<main>'
我已经看到有关 rubytypes.rb 补丁的讨论,但除此之外什么都没有。
我宁愿不切换到 Psych,因为这会打开另一个蠕虫罐:
YAML::ENGINE.yamler = "psych"
# attempt to load from file again
TypeError: can't convert Fixnum into String
这是怎么回事?有希望吗?在此错误使其不透明之前,我对 Syck 和 Psych 以及 YAML 解析的内部都一无所知。