Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to parse BNF grammars at compile time #89

Open
LoganDark opened this issue Mar 9, 2022 · 3 comments
Open

Ability to parse BNF grammars at compile time #89

LoganDark opened this issue Mar 9, 2022 · 3 comments

Comments

@LoganDark
Copy link

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

@shnewto
Copy link
Owner

shnewto commented Mar 9, 2022

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)]

image

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.

🥂

@LoganDark
Copy link
Author

Interesting - maybe you could at least provide deserialization at compile-time so that I can use a build script to parse the grammar?

@shnewto
Copy link
Owner

shnewto commented Mar 11, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants