Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rexim/bnfuzzer
Generate random messages based on their BNF definition
https://github.com/rexim/bnfuzzer
Last synced: 3 months 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 (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-15T22:12:14.000Z (about 2 years ago)
- Last Synced: 2024-06-21T15:43:08.453Z (7 months ago)
- Language: Go
- Size: 38.1 KB
- Stars: 30
- Watchers: 4
- Forks: 0
- 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]
```