Skip to main content

Module macros

Module macros 

Source
Expand description

Macros: source regions an embedder expands.

A macro invocation is written name!( ... ). Everything between the parentheses is a raw region that candela does not interpret. The region is handed to the expander registered under name, and the candela source the expander returns is parsed in its place, as one expression.

candela never learns what a macro means. It finds where a region starts and ends, calls out, and parses what comes back. The meaning belongs to the host that registers the expander.

use candela::macros::MacroError;

let mut engine = candela::Engine::new();
engine.register_macro("shout", |body: &str| {
    Ok::<String, MacroError>(format!("\"{}!\"", body.trim().to_uppercase()))
});

scan_regions exposes the same region scanner the lexer uses, so a build tool can find every invocation of one macro in a file without compiling it.

Structs§

MacroEnv
The macros a compilation may use, and what an unregistered one does.
MacroError
Why an expander refused the region it was handed.
Region
One name!( ... ) invocation found by scan_regions.

Functions§

scan_regions
Finds every name!( ... ) invocation in src, in source order.