https://github.com/oncomouse/lpeg-bibtex
BibTeX Parser in Lua using LPEG
https://github.com/oncomouse/lpeg-bibtex
Last synced: 9 months ago
JSON representation
BibTeX Parser in Lua using LPEG
- Host: GitHub
- URL: https://github.com/oncomouse/lpeg-bibtex
- Owner: oncomouse
- Created: 2022-09-02T19:38:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-14T18:38:15.000Z (almost 4 years ago)
- Last Synced: 2025-01-21T15:48:47.464Z (over 1 year ago)
- Language: Lua
- Size: 12.7 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# LPEG BibTeX
This is a very rudimentary (for now) PEG parser (using [LPEG](http://www.inf.puc-rio.br/~roberto/lpeg/) and Lua) for BibTeX files.
It is based on the grammar described at [aclements/biblib](https://github.com/aclements/biblib) and reproduced below:
```
bib_db = comment (command_or_entry comment)*
comment = [^@]*
ws = [ \t\n]*
ident = ![0-9] (![ \t"#%'(),={}] [\x20-\x7f])+
command_or_entry = '@' ws (comment / preamble / string / entry)
comment = 'comment'
preamble = 'preamble' ws ( '{' ws preamble_body ws '}'
/ '(' ws preamble_body ws ')' )
preamble_body = value
string = 'string' ws ( '{' ws string_body ws '}'
/ '(' ws string_body ws ')' )
string_body = ident ws '=' ws value
entry = ident ws ( '{' ws key ws entry_body? ws '}'
/ '(' ws key_paren ws entry_body? ws ')' )
key = [^, \t}\n]*
key_paren = [^, \t\n]*
entry_body = (',' ws ident ws '=' ws value ws)* ','?
value = piece (ws '#' ws piece)*
piece
= [0-9]+
/ '{' balanced* '}'
/ '"' (!'"' balanced)* '"'
/ ident
balanced
= '{' balanced* '}'
/ [^{}]
```