https://github.com/hodzanassredin/ebnfconverter
Simple ebnf to gbnf(llama.cpp)/lark converter
https://github.com/hodzanassredin/ebnfconverter
bnf converter ebnf lark
Last synced: 8 months ago
JSON representation
Simple ebnf to gbnf(llama.cpp)/lark converter
- Host: GitHub
- URL: https://github.com/hodzanassredin/ebnfconverter
- Owner: hodzanassredin
- License: bsd-3-clause
- Created: 2025-02-05T09:30:24.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-02-06T12:54:38.000Z (8 months ago)
- Last Synced: 2025-02-13T03:54:20.383Z (8 months ago)
- Topics: bnf, converter, ebnf, lark
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EBNF Converter
This simple script is designed to convert EBNF grammar descriptions into the other formats like GBNF format used in the [llama.cpp](https://github.com/ggerganov/llama.cpp) project and [Lark](https://github.com/lark-parser/lark) .
## Features
- Supports various EBNF variations.
- Allows modification of conversion rules.
- Easy to use.## Problems
- After conversion, you need to handle additional problems like whitespaces and so on.
- for GBNF read the [doc](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md)
- for Lark read the [doc](https://lark-parser.readthedocs.io/en/stable/grammar.html)## Installation
To use this script, you need to install the [Lark](https://github.com/lark-parser/lark) library. Run the following command to install it:
```bash
pip install Lark
```## Usage
To convert an EBNF file to GBNF, run the following command:
```bash
python ebnf_to_gbnf.py example.ebnf
```To convert an EBNF file to Lark, run the following command:
```bash
python ebnf_to_lark.py example.ebnf
```Where `example.ebnf` is your EBNF grammar file.
## Grammar Description
The EBNF grammar is defined in the `ebnf_grammar` variable in the `ebnf_to_XXX.py` file. You can modify it according to your requirements.
## Modifying Conversion Rules
You can modify the conversion rules by changing the functions whose names start with `rebuild_`. These functions handle the transformation of various EBNF elements into their corresponding GBNF elements.
## Error Handling
The script handles the following errors:
- File not found: Displays an error message.
- Parsing errors: Displays an error message with the cause.