Small C-style macro expansion library.
let result = ppx::parse_string(
"
#param A
#define B hello
#define fn(name) name!
B A fn(John)
",
base_dir,
["world"].into_iter()
);
// result = "hello world John!"More examples in the tests folder.
#param: A parameter that can be passed when including the file, or from theparse*functions.#define: Define a simple substition, or a function-like macro- paste operator: use
##to paste two tokens
- paste operator: use
#include: Include another file and parse it as well. Optionally accepts parameters which will be used for substituting the names specified by#param.#pragma once: only include a file once- Conditional branching with
#if,#elif,#else,#endif
Optional features:
- Macros
include_ppx!andinclude_ppx_string!: Parse a template at compile time instead of at runtime. Enable macros with featuremacroormacro-stable. vfsfeature: allows using virtual filesystem from the vfs crate as the input.
This crate follows semantic versioning since 1.0.
cargo test --workspaceOr better, with the cargo-all-features subcommand:
cargo +nightly all-features test --workspaceMIT or Apache-2.0.