Skip to content

Commit

Permalink
Add flexible rules check. Tag new version. Enforce Julia ^1.6 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Oct 21, 2021
1 parent 68bc8bd commit fca73ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BibInternal"
uuid = "2027ae74-3657-4b95-ae00-e2f7d55c3e64"
authors = ["azzaare"]
version = "0.3.2"
version = "0.3.3"

[compat]
julia = "1.4"
julia = "1.6"
24 changes: 16 additions & 8 deletions src/bibtex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ const rules = Dict{String,Vector{Required}}(
check_entry(fields::Fields)
Check the validity of the fields of a BibTeX entry.
"""
function check_entry(fields)
function check_entry(fields, check, id)
errors = Vector{String}()

for t_field in rules[get(fields, "_type", "misc")]
entry_type = get(fields, "_type", "misc")
if entry_type keys(rules)
if check [:error, :warn]
@warn """KeyError: key "software" not found in BibTeX rules, parsed from the entry `$id` with""" fields
end
check == :error && throw(KeyError(entry_type))
end

for t_field in get(rules, entry_type, Vector{Required}())
at_least_one = false
if typeof(t_field) == Tuple{String,String}
for field in t_field
Expand All @@ -70,17 +78,17 @@ end
make_bibtex_entry(id::String, fields::Fields)
Make an entry if the entry follows the BibTeX guidelines. Throw an error otherwise.
"""
function make_bibtex_entry(id, fields)
function make_bibtex_entry(id, fields; check=:error)
# @info id fields
"eprint" keys(fields) && (fields["_type"] = "eprint")
fields = Dict(lowercase(k) => v for (k, v) in fields) # lowercase tag names
errors = check_entry(fields)
if length(errors) > 0
error(
errors = check_entry(fields, check, id)
if length(errors) > 0 && check [:error, :warn]
message =
"Entry $id is missing the " *
foldl(((x, y) -> x * ", " * y), errors) *
" field(s).",
)
" field(s)."
check == :error ? (@error message) : (@warn message)
end
return Entry(id, fields)
end

0 comments on commit fca73ef

Please sign in to comment.