Skip to content

Commit

Permalink
Merge branch 'hotfix/issue-34'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Apr 1, 2021
2 parents a51e911 + c423694 commit 22667dc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "XAM"
uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c"
authors = ["Kenta Sato <[email protected]>", "Ben J. Ward <[email protected]>", "Ciarán O'Mara <[email protected]>"]
version = "0.2.6"
version = "0.2.7"

[deps]
Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
Expand Down
18 changes: 11 additions & 7 deletions src/sam/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 3 additions & 12 deletions src/sam/readrecord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -200,10 +199,6 @@ const sam_actions_header = merge(

finish_header = true

if !eof(stream)
p -= 1 # cancel look-ahead
end

@escape
end
)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/test_sam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit 22667dc

@CiaranOMara
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/33296

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.7 -m "<description of version>" 22667dc7afe68a76cd5cdbc22c65b77c0ddf15b3
git push origin v0.2.7

Please sign in to comment.