Skip to content

Instantly share code, notes, and snippets.

@houshuang
Last active December 16, 2015 10:59
Show Gist options
  • Save houshuang/5424464 to your computer and use it in GitHub Desktop.
Save houshuang/5424464 to your computer and use it in GitHub Desktop.
Instaparse definition for BibTeX
@article{laurillard2009pedagogical,
Author = {Laurillard, Diana},
Date-Added = {2013-01-18 20:15:33 +0000},
Date-Modified = {2013-01-18 20:15:33 +0000},
Doi = {10.1007/s11412-008-9056-2},
Journal = {International Journal of Computer-Supported Collaborative Learning},
Month = {mar},
Number = {1},
Pages = {5-20},
Publisher = {Springer-Verlag},
Title = {The pedagogical challenges to collaborative technologies},
Url = {http://dx.doi.org/10.1007/s11412-008-9056-2},
Volume = {4},
Year = {2009},
Bdsk-Url-1 = {http://dx.doi.org/10.1007/s11412-008-9056-2}}
bibfile := entry_or_junk+
entry_or_junk := (tb, object) / (tb, junk)
object := entry / macro / preamble / comment_entry
entry := '@', entry_type, tb, ( '{' , tb, contents, tb, '}' ) / ( '(' , tb, contents, tb, ')' )
macro := '@string', tb, ( '{' , tb, macro_contents, tb, '}' ) / ( '(' , tb, macro_contents, tb, ')' )
preamble := '@', entry_type, tb, ( '{' , tb, preamble_contents, tb, '}' ) / ( '(' , tb, preamble_contents, tb, ')' )
comment_entry := '@', entry_type, tb, string
contents := citekey , tb, ',' , tb, fields
macro_contents := field
preamble_contents := value
entry_type := alpha_name
citekey := number / name
fields := (field_comma / field)+
field_comma := field , tb, ',', tb
field := name, tb, '=' , tb, value
value := simple_value / (simple_value, (tb,'#', tb, simple_value)+)
simple_value := string / number / name
alpha_name := #"[a-zA-Z]+"
name := #"[^a-z_A-Z!$&+./:;<>?^`|']" , #"[^a-z_A-Z0-9!$&+./:;<>?^`|']*"
number := #"[0-9]+" | (#"[0-9]+", tb, #"[-]+", tb, #"[0-9]+")
string := ('\"' , quotes_string?, '\"') | ('{' , braces_string?, '}')
<braces_string> := (#"[^{}@]+" | string)+
<quotes_string> := (#"[^\"]+" | ('{', braces_string,'}'))+
<junk> := #"[^ \t\r\n]+"
<tb> := (comment | ws)*
<ws> := #"[ \t\n\r]"
<comment> := '%' , #"[^\n]*", '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment