4 ms·
I built a grammar to tackle these sorts of problems when I had trouble writing formal grammar notations for my binary data format. It's even got a syntax highli
by kstenerud 3y ago
I built a grammar to tackle these sorts of problems when I had trouble writing formal grammar notations for my binary data format. It's even got a syntax highlighter.
https://dogma-lang.org/ https://dogma-lang.org/
So far it's been able to describe 90% of what's out there. Some examples:
- 802.3 layer 2 Ethernet: https://github.com/kstenerud/dogma/blob/master/v1/examples/802.3_layer2.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/8...
- Microsoft ICO format: https://github.com/kstenerud/dogma/blob/master/v1/examples/ico.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/i...
- Android Dex v39: https://github.com/kstenerud/dogma/blob/master/v1/examples/dex_v39.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/d...
- IPv4: https://github.com/kstenerud/dogma/blob/master/v1/examples/ipv4.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/i...
- DNS query: https://github.com/kstenerud/dogma/blob/master/v1/examples/dns_query.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/d...
- Microsoft Minidump: https://github.com/kstenerud/dogma/blob/master/v1/examples/minidump.dogma https://github.com/kstenerud/dogma/blob/master/v1/examples/m...
- Concise Binary Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cbe.dogma https://github.com/kstenerud/concise-encoding/blob/master/cb...
- Concise Text Encoding: https://github.com/kstenerud/concise-encoding/blob/master/cte.dogma https://github.com/kstenerud/concise-encoding/blob/master/ct...
- lindig 3y agoThe main feature of interval parsing appears to be that it can jump over content such that a later part in a file does not depend on knowing everything that comes before it. Has Dogma similar expressiveness?
- kstenerud 3y agoYes, the `offset` function does this by specifying a bit-offset to branch to. For example the ICO `dir_entry`, which is a directory list of icon resources in the file. https://github.com/kstenerud/dogma/blob/master/v1/examples/ico.dogma#L26 https://github.com/kstenerud/dogma/blob/master/v1/examples/i... - It's using image_offset*8 because everything in an ICO file is a byte-offset (8 bits) It's also needed to parse Minidump. For example https://github.com/kstenerud/dogma/blob/master/v1/examples/minidump.dogma#L23 https://github.com/kstenerud/dogma/blob/master/v1/examples/m... and https://github.com/kstenerud/dogma/blob/master/v1/examples/minidump.dogma#L62 https://github.com/kstenerud/dogma/blob/master/v1/examples/m...