https://github.com/zepinglee/lua-bibtex-parser
https://github.com/zepinglee/lua-bibtex-parser
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zepinglee/lua-bibtex-parser
- Owner: zepinglee
- License: mit
- Created: 2023-08-20T15:51:57.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T14:59:47.000Z (over 2 years ago)
- Last Synced: 2025-04-13T04:38:23.618Z (about 1 year ago)
- Language: Lua
- Size: 24.4 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-bibtex-parser
Previously I wrote a BibTeX parser for
and I'm planning to make it a standalone project here. This parser is aimed
at matching the original BibTeX's syntax.
## Improvements (TODO)
- Fault-tolerant: Able to parse files with syntax errors
- Exporting matching the original
- Easily modifying
- Formatting options for writing
## BibTeX grammar
The following PEG is largely based on
with small fixes after I checked the BibTeX source code [bibtex.web](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/bibtex.web).
```
bib_db = comment (command_or_entry comment)*
comment = [^@]*
ws = [ \t\n]*
ident = ![0-9] (![ \t"#%'(),={}] [\x20-\x7f])+
command_or_entry = '@' ws (comment_command / preamble / string / entry)
comment_command = 'comment' &[ \t\n{(]
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 = field_token (ws '#' ws field_token)*
field_token
= [0-9]+
/ '{' balanced* '}'
/ '"' (!'"' balanced)* '"'
/ ident
balanced
= '{' balanced* '}'
/ [^{}]
```