diff --git a/Project.toml b/Project.toml index beb4170..0c21bf9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "XAM" uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c" authors = ["Kenta Sato ", "Ben J. Ward ", "Ciarán O'Mara "] -version = "0.2.6" +version = "0.2.7" [deps] Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" diff --git a/src/sam/reader.jl b/src/sam/reader.jl index a20fd4c..aa5546e 100644 --- a/src/sam/reader.jl +++ b/src/sam/reader.jl @@ -94,17 +94,21 @@ end Read a `Record` into `rec`; overwriting or adding to existing field values. It is assumed that `rec` is already initialized or empty. """ -function Base.read!(rdr::Reader, rec::Record) +function Base.read!(rdr::Reader, record::Record) - cs, ln, f = readrecord!(rdr.state.stream, rec, (rdr.state.state, rdr.state.linenum)) + cs, ln, found = readrecord!(rdr.state.stream, record, (rdr.state.state, rdr.state.linenum)) rdr.state.state = cs rdr.state.linenum = ln - rdr.state.filled = f + rdr.state.filled = found - if !f - cs == 0 && throw(EOFError()) - throw(ArgumentError("malformed SAM file")) + if found + return record end - return rec + + if cs == 0 || eof(rdr.state.stream) + throw(EOFError()) + end + + throw(ArgumentError("malformed SAM file")) end diff --git a/src/sam/readrecord.jl b/src/sam/readrecord.jl index 4bc0761..e2d6669 100644 --- a/src/sam/readrecord.jl +++ b/src/sam/readrecord.jl @@ -134,11 +134,10 @@ const sam_machine_metainfo, sam_machine_record, sam_machine_header, sam_machine_ cat(re"\r?", lf) end - header′ = rep(cat(metainfo, newline)) - header′.actions[:exit] = [:header] - header = cat(header′, opt(any() \ cat('@'))) # look ahead + header = rep(cat(metainfo, newline)) + header.actions[:exit] = [:header] - body = rep(cat(record, newline)) + body = record * rep(newline * record) * opt(newline) body.actions[:exit] = [:body] sam = cat(header, body) @@ -200,10 +199,6 @@ const sam_actions_header = merge( finish_header = true - if !eof(stream) - p -= 1 # cancel look-ahead - end - @escape end ) @@ -308,10 +303,6 @@ Automa.Stream.generate_reader( const sam_loopcode_header = quote - if cs < 0 - throw(ArgumentError("malformed metainfo at line $(linenum)")) - end - if finish_header @goto __return__ end diff --git a/test/test_sam.jl b/test/test_sam.jl index e669757..c6fadc1 100644 --- a/test/test_sam.jl +++ b/test/test_sam.jl @@ -194,5 +194,11 @@ close(reader) + # Test blank file. + file_sam = joinpath(samdir, "xx#blank.sam") + + records = open(collect, SAM.Reader, file_sam) + @test records == [] + end end