Binary parsing
#2108
Replies: 1 comment
-
And my questions are:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there! Some time ago I made a parser for C structs using Chevrotain, as a utility for my project over-the-wire, to parse network packets and handle some other low-level tasks (but let’s focus on parsing and building network packets in this discussion). It worked well for a while, but at some point I realized that parsing plain C structs wasn’t enough — for example, parsing a DNS packet involves conditional fields, and TLV values are not straightforward to parse, especially considering there are multiple layers in the buffer, etc.
So I started looking again for JavaScript binary parsing libraries, but none of them seem to fit my current requirements. Here’s what I’m looking for right now:
I tried to write some code with this imaginary library, and it looks something like this:
I’m also thinking about conditional and choice combinators, etc. This is a very rough draft of what I’m aiming for. In Rust there’s the nom library, which I find inspiring, and Haskell’s parsec as well. But the API design is still a work in progress.
Regarding implementation, my current library has poor performance, so I’m considering using new Function to compile the parsers while keeping a declarative, combinator-style syntax.
I know this is kind of off-topic for Chevrotain, but since I think the author of Chevrotain understands parsers in JavaScript better than anyone else, I don’t know a better place to ask for advice.
Beta Was this translation helpful? Give feedback.
All reactions