bnfuzzer
bnfuzzer copied to clipboard
Generate random messages based on their BNF definition
BNF Fuzzer
Generate random messages based on their BNF definition.
Quickl Start
Generate 10 random postal addresses:
$ go build .
$ ./bnfuzzer -file ./examples/postal.bnf -entry postal-address -count 10
Syntax of BNF files
We are trying to support BNF and ABNF syntaxes simultenously, by allowing to use different syntactical elements for the same constructions. For example you can use / and | for Rule Alternatives 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 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.
The descriptions below are stolen from wikipedia.
Comments
; 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...
// comment
Concatenation
fu = %x61 ; a
bar = %x62 ; b
mumble = fu bar fu
Alternative
fubar = fu / bar
or
fubar = fu | bar
Incremental alternatives
The rule
ruleset = alt1 / alt2
ruleset =/ alt3
ruleset =/ alt4 / alt5
is equivalent to
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
OCTAL = %x30-37
is equivalent to
OCTAL = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7"
and also can be written as
OCTAL = "0" ... "9"
or
OCTAL = "\x30" ... "\x37"
Sequence group
group = a (b / c) d
Variable repetition
n*nRule
Specific repetition
nRule
Optional sequence
[Rule]