Skip to content

Commit

Permalink
edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Mar 4, 2024
1 parent c265427 commit 24e8076
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chunker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,24 @@ class BibTeXParser {
}
}

private entry(d) {
private entry(d: string, guard: string) {
this.entries.unshift({ type: d, key: '', fields: {} })

if (this.tryMatch(guard)) return // empty entry

let key = this.key()
if (this.tryMatch(',')) { // some people seem to think the key is optional...
this.match(',')
this.entries[0].key = key
key = ''
}
if (!key && this.tryMatch(guard)) return // no fields

this.key_equals_value(key)
while (this.tryMatch(',')) {
this.match(',')
// fixes problems with commas at the end of a list
if (this.tryMatch('}')) {
if (this.tryMatch(guard)) {
break
}
this.key_equals_value()
Expand Down Expand Up @@ -471,7 +475,7 @@ class BibTeXParser {

default:
guard = this.matchGuard()
this.entry(d)
this.entry(d, guard)
this.match(guard)
chunk.entry = true
break
Expand Down

0 comments on commit 24e8076

Please sign in to comment.