Commit 577f2986 authored by Igor Dejanovic's avatar Igor Dejanovic

Fix for bibtex comments. Any text between bib entries are considered comment.

parent 4c52e8ba
...@@ -16,14 +16,14 @@ from arpeggio import RegExMatch as _ ...@@ -16,14 +16,14 @@ from arpeggio import RegExMatch as _
import logging import logging
def bibfile(): return ZeroOrMore(bibentry), EndOfFile def bibfile(): return ZeroOrMore([bibentry, comment]), EndOfFile
def bibentry(): return bibtype, "{", bibkey, ",", field, ZeroOrMore(",", field), "}" def bibentry(): return bibtype, "{", bibkey, ",", field, ZeroOrMore(",", field), "}"
def bibtype(): return _(r'@\w+') def bibtype(): return _(r'@\w+')
def bibkey(): return _(r'[^\s,]+'), def bibkey(): return _(r'[^\s,]+'),
def field(): return fieldname, "=", '"', fieldvalue, '"' def field(): return fieldname, "=", '"', fieldvalue, '"'
def fieldname(): return _(r'\w+') def fieldname(): return _(r'\w+')
def fieldvalue(): return _(r'[^"]*') def fieldvalue(): return _(r'[^"]*')
def comment(): return _(r'%[^\n]*') def comment(): return _(r'[^@]+')
# Semantic actions # Semantic actions
class BibFileSem(SemanticAction): class BibFileSem(SemanticAction):
...@@ -46,7 +46,7 @@ class BibEntrySem(SemanticAction): ...@@ -46,7 +46,7 @@ class BibEntrySem(SemanticAction):
if isinstance(field, tuple): if isinstance(field, tuple):
bib_entry_map[field[0]] = field[1] bib_entry_map[field[0]] = field[1]
return bib_entry_map return bib_entry_map
class FieldSem(SemanticAction): class FieldSem(SemanticAction):
'''Constructs a tuple (fieldname, fieldvalue).''' '''Constructs a tuple (fieldname, fieldvalue).'''
...@@ -81,7 +81,7 @@ if __name__ == "__main__": ...@@ -81,7 +81,7 @@ if __name__ == "__main__":
# First we will make a parser - an instance of the bib parser model. # First we will make a parser - an instance of the bib parser model.
# Parser model is given in the form of python constructs therefore we # Parser model is given in the form of python constructs therefore we
# are using ParserPython class. # are using ParserPython class.
parser = ParserPython(bibfile, comment_def=comment, reduce_tree=True) parser = ParserPython(bibfile, reduce_tree=True)
# Then we export it to a dot file in order to visualise it. This is # Then we export it to a dot file in order to visualise it. This is
# particulary handy for debugging purposes. # particulary handy for debugging purposes.
......
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