我需要为解析项目解析gedcom 5.5文件。 我发现的第一个ruby解析器是一个堆栈级别太深的错误,所以我试图找到替代方案。我发起这个项目:https://github.com/jslade/gedcom-rubyruby gedcom解析器EOF异常
有一些样品,但我也没有让他们工作。
这里是解析器本身:https://github.com/jslade/gedcom-ruby/blob/master/lib/gedcom.rb
如果我试图像这样的例子:
ruby ./samples/count.rb ./samples/royal.ged
我得到以下错误:
D:/rails_projects/gedom_test/lib/gedcom.rb:185:in `readchar': end of file reached (EOFError)
我写了一个 “变” 中每种方法更好地展示,这是异常情况下的输出:
Parsing './samples/royal.ged'...
INIT
BEFORE
CHECK_PROC_OR_BLOCK
BEFORE
CHECK_PROC_OR_BLOCK
PARSE
PARSE_FILE
PARSE_IO
DETECT_RS
引起问题的确切行
while ch = io.readchar
在detect_rs方法
:
# valid gedcom may use either of \r or \r\n as the record separator.
# just in case, also detects simple \n as the separator as well
# detects the rs for this string by scanning ahead to the first occurence
# of either \r or \n, and checking the character after it
def detect_rs io
puts "DETECT_RS"
rs = "\x0d"
mark = io.pos
begin
while ch = io.readchar
case ch
when 0x0d
ch2 = io.readchar
if ch2 == 0x0a
rs = "\x0d\x0a"
end
break
when 0x0a
rs = "\x0a"
break
end
end
ensure
io.pos = mark
end
rs
end
我希望有人能帮助我与此有关。
谢谢你,能解决异常问题,但它不”现在也真的有效。 它说该文件不包含任何人,这不可能是正确的: 'samples/royal.ged'中有0个人和0个家庭。 – Mudvayne
对不起,我不知道gedcom文件 - 我只是想让你通过EOF错误。然而我只是想看到,我在答案中从分支下载了gedcom,并且当我运行'ruby samples/count.rb samples/royal.ged'时,它给了我''样本/ royal.ged中有3010个人和1422个家庭' .'。 –
是啊..我在Windows机器上使用ruby和rails,我在虚拟linux机器上尝试了相同的确切示例并获得正确的输出。 – Mudvayne