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

Macro for parsing KCL at Rust compile-time #1049

Merged
merged 2 commits into from
Nov 10, 2023
Merged

Conversation

adamchalmers
Copy link
Collaborator

@adamchalmers adamchalmers commented Nov 9, 2023

This adds a new parse_kcl! macro which takes a string as input. It parses the string into KCL source code at compile-time. Invalid KCL will make your Rust project fail to compile.

Here's an example of how to use it:

extern crate alloc; 
use kcl_compile_macro::parse_kcl;

let ast: kcl_lib::ast::types::Program = parse_kcl!("const y = 4");

The extern crate alloc is an external crate included with Rust in the standard distribution -- it's not a third-party crate, so you don't need to add it to Cargo.toml or anything.

Closes #1018

Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Nov 10, 2023 4:24pm

@lf94
Copy link
Contributor

lf94 commented Nov 10, 2023

Might want to switch the naming for the future of adding more kcl macros: kcl_parse!, kcl_execute!, etc

This adds a new `parse_kcl!` macro which takes a string as input. It parses the string into KCL source code _at compile-time_. Invalid KCL will make your Rust project fail to compile.
@adamchalmers
Copy link
Collaborator Author

Renamed to kcl_macros::parse! I expect we'll re-export it from the kcl library so it would become kcl::parse!

@adamchalmers adamchalmers merged commit 9f0ac5f into main Nov 10, 2023
15 checks passed
@adamchalmers adamchalmers deleted the achalmers/kcl-macro branch November 10, 2023 16:36
@pierremtb pierremtb mentioned this pull request Nov 14, 2023
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

Successfully merging this pull request may close these issues.

Compile-time KCL parser
2 participants