Open LoganDark opened 2 years ago
Hey @LoganDark it's a cool idea but fwiw the reason isn't just from_str
, the crate we use for parsing, nom
isn't const fn
compatible. If there's a parser combinator library out there that is const fn
compatible I haven't spotted it yet, and it'd take some evaluation to go that route if it exists. Even for some basic errors like the screen shot below there are unstable features required to get there, i.e.
#![feature(const_impl_trait)]
#![feature(const_mut_refs)]
It's not as elegant but I guess you could use the bnf crate to generate the grammar object and serialize it for use in an app you don't want to have to parse and validate at runtime.
🥂
Interesting - maybe you could at least provide deserialization at compile-time so that I can use a build script to parse the grammar?
I'm not sure deserialization will be easier to manage at compile time, or at least not in ways that seem like they could be a stable-ish feature for this crate. I'll keep my eyes open though, thanks for creating this issue!
Is your feature request related to a problem? Please describe. There's no reason to include an entire BNF parser in the compiled application if I just have a set grammar that I want to use that is constant. However, this is what happens if I use the bnf crate in my application - it must parse and validate at runtime.
Describe the solution you'd like Allow BNF syntax to be parsed at compile-time. Make the required functions const (FromStr::from_str is not const)
Describe alternatives you've considered N/A
Additional context N/A