https://github.com/rexim/bnfuzzer
Generate random messages based on their BNF definition
https://github.com/rexim/bnfuzzer
Last synced: about 1 year ago
JSON representation
Generate random messages based on their BNF definition
- Host: GitHub
- URL: https://github.com/rexim/bnfuzzer
- Owner: rexim
- License: mit
- Created: 2023-01-05T07:58:48.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-04-10T07:45:02.000Z (about 1 year ago)
- Last Synced: 2025-05-20T08:08:30.992Z (about 1 year ago)
- Language: Go
- Size: 39.1 KB
- Stars: 87
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BNF Fuzzer
Generate random messages based on their [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) definition.
## Quickl Start
Generate 10 random postal addresses:
```console
$ go build .
$ ./bnfuzzer -file ./examples/postal.bnf -entry postal-address -count 10
```
## Syntax of BNF files
We are trying to support [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) and [ABNF](https://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_form) syntaxes simultenously, by allowing to use different syntactical elements for the same constructions. For example you can use `/` and `|` for [Rule Alternatives](https://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_form#Alternative) and even mix them up in the same file. Both of them are interpreted as aliternatives.
*Maybe with some limitations we can enable support for [EBNF](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) as well, but it's a bit difficult because EBNF uses `;` to indicate the end of the rule definition, but ABNF and BNF use it for [comments](https://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_form#Comment).*
*The descriptions below are stolen from wikipedia.*
### Comments
```lisp
; comment
```
*For some reason I also added C-style comments. Maybe I should remove them so to not create even more confusion between BNF dialects...*
```c
// comment
```
### Concatenation
```lisp
fu = %x61 ; a
bar = %x62 ; b
mumble = fu bar fu
```
### Alternative
```lisp
fubar = fu / bar
```
or
```lisp
fubar = fu | bar
```
### Incremental alternatives
The rule
```lisp
ruleset = alt1 / alt2
ruleset =/ alt3
ruleset =/ alt4 / alt5
```
is equivalent to
```lisp
ruleset = alt1 / alt2 / alt3 / alt4 / alt5
```
*Maybe to maintain the consistency with supporting mixed up syntax, we should allow to use `=|` along with `=/`...*
### Value range
```lisp
OCTAL = %x30-37
```
is equivalent to
```lisp
OCTAL = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7"
```
and also can be written as
```lisp
OCTAL = "0" ... "9"
```
or
```lisp
OCTAL = "\x30" ... "\x37"
```
### Sequence group
```lisp
group = a (b / c) d
```
### Variable repetition
```lisp
n*nRule
```
### Specific repetition
```lisp
nRule
```
### Optional sequence
```lisp
[Rule]
```