Commit ad5cfb18 authored by Andrey Golovizin's avatar Andrey Golovizin

Merge branch 'jannschu/master'

Fixes #95.
parents a6d43a6e 0de51caf
......@@ -77,7 +77,7 @@ import six
from pybtex import textutils
from pybtex.bibtex.utils import split_name_list
from pybtex.database import Entry, Person
from pybtex.database import Entry, Person, BibliographyDataError
from pybtex.database.input import BaseParser
from pybtex.scanner import (
Literal, Pattern, PrematureEOF, PybtexSyntaxError, Scanner
......@@ -111,6 +111,10 @@ class UndefinedMacro(PybtexSyntaxError):
error_type = 'undefined string'
class DuplicatePersonField(BibliographyDataError):
pass
class LowLevelParser(Scanner):
NAME = Pattern(r'[{0}][{1}]*'.format(re.escape(NAME_CHARS), re.escape(NAME_CHARS + digits)), 'a valid name')
KEY_PAREN = Pattern(r'[^\s\,]+', 'entry key')
......@@ -350,11 +354,19 @@ class Parser(BaseParser):
key = 'unnamed-%i' % self.unnamed_entry_counter
self.unnamed_entry_counter += 1
already_handled_person_fields = set()
for field_name, field_value_list in fields:
field_value = textutils.normalize_whitespace(self.flatten_value_list(field_value_list))
if field_name in self.person_fields:
if field_name in already_handled_person_fields:
error_message = 'entry with key {} has a duplicate {} field'.format(
key, field_name
)
self.handle_error(DuplicatePersonField(error_message))
continue
for name in split_name_list(field_value):
entry.add_person(Person(name), field_name)
already_handled_person_fields.add(field_name)
else:
entry.fields[field_name] = field_value
self.data.add_entry(key, entry)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment