我需要为分析项目解析 gedcom 5.5 文件。我发现的第一个 ruby 解析器会导致堆栈级别太深的错误,所以我试图找到替代方案。我找到了这个项目:https ://github.com/jslade/gedcom-ruby
包括一些样本,但我也没有让它们工作。
这是解析器本身: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)
为了更好地理解,我在每种方法中都写了一个“gets”,这是异常引发之前的输出:
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
我希望有人可以帮助我。