Ask HN: Please help me by reviewing KBNF

6 points by kstenerud ↗ HN
Hi everyone! Merry Christmas and happy new year!

I'm making a modernized BNF-style metalanguage that supports grammars for text and binary formats, but unless there's some kind of outside review, I won't find any blind spots I have until long after release.

If you have experience in grammars or protocols (text or binary), could you take a quick look?

Note: I'm not aiming for perfect expressivity; just 80-90% of use cases without making things overcomplicated so that it can be used descriptively in documentation.

https://github.com/kstenerud/kbnf/blob/master/kbnf.md

Some examples of it in use:

* Internet Prodocol, version 4: https://github.com/kstenerud/kbnf/blob/master/ipv4.kbnf

* Concise Text Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cte.kbnf

* Concise Binary Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cbe.kbnf

* The KBNF grammar itself: https://github.com/kstenerud/kbnf/blob/master/kbnf.md#the-kbnf-grammar-in-kbnf

2 comments

[ 2.9 ms ] story [ 19.1 ms ] thread
It looks ok but I think you would need to try and implement something in it to see if there are any problems. I was a bit wary of the programmatic parts at first but I see where they can be used to cut down on repitition in the grammar. I thought that the functions should be more different than the rules/identifiers for instance.

part = @bind(number, @uint(8,~)) & @uint(16,~) & number

Because if you are writing the grammar for a language you may have similar constructs.

Hmm yeah, I can see how visual differentiation of the functions from symbols and macros could help readability.

The base grammar minus macros and functions is mostly like any other BNF, and so would have its strengths and weaknesses when it comes to describing a language vs a format.

The main inspiration for this was because I couldn't describe CTE and CBE (whose grammars are listed above). I also tried it out describing IPV4 (also listed above).

I'll probably try describing something like protobufs or PNG or something like that to see how well it fares, but for now I'm interested in peoples immediate reaction to it in case there are glaring problems.