News for hackers. Stuff that matters.
Re:Parsing Text with Nom by adamch on Wednesday January 12, 2022 @07:59AM (#29905745)
Hi Josh! "Parse, don't validate" is one of my favourite programming blog posts of all time. Between Nom and Serde, I find it very easy to use that approach in Rust.
Re:Parsing Text with Nom by faitswulff on Wednesday January 12, 2022 @08:54AM (#29906279)
As a beginner to both, when do you find yourself reaching for one instead of the other? Or do you use nom when deserializing with serde?
Re:Parsing Text with Nom by adamch on Wednesday January 12, 2022 @09:08AM (#29906452)
Serde is good for self-describing formats like JSON, YAMK, TOML etc. At least that's what I use it for. Nom isn't necessary for them!

Nom is good for protocols where you need to know the schema in advance. E.g. a binary key-value store, where the binary in the key and value has to be deserialised into some special rules.

Nom can also handle bit-level parsers very easily. It's easier to use the parsers in nom::bits than remembering all the bit-shifting tricks I haven't used in five years.

But I'm not an expert on Serde, I suspect it can do bit-level too. I've never written my own Serde library, I just use crates like serde-json.

Re:Parsing Text with Nom by maleldil on Wednesday January 12, 2022 @09:25AM (#29906644)
I use Serde when it's a common format that already has implementations for Serialize/Deserialize, and nom/peg when it's a custom format.
Re:Parsing Text with Nom by imor80 on Wednesday January 12, 2022 @08:43AM (#29906168)
You mean "Parse, don't validate" right?
Re:Parsing Text with Nom by adamch on Wednesday January 12, 2022 @09:10AM (#29906486)
Oops, yes