Function withSigilHandler

Source
pub fn withSigilHandler<T: StartMarker + Clone>(
    c: Configuration<T>,
    v: Variables<'_, T>,
    data: Option<TokenStream>,
    t: TokenStream,
) -> Result<(Variables<'_, T>, TokenStream), (Variables<'_, T>, TokenStream)>
Expand description

Redefine which sigil to use within the scope of the handler.

Syntax: $(withSigil <newSigil> <codeUsingNewSigil>)

In a context where the sigil was $ and you want to complicatedly generate a lot of macro_rules! code based on some table, you might use it like so

// various other code
$(withSigil %
    %(var
      table = {%(array mk ...)} // The multidimensional table data, which will be nested arrays
    )
    %(let
      pattern = {...} // The template inner macro code for each arm
      macro_rules_inner = { %(arg_pattern %(array ith get 0 %inner_table) %(array ith get 1 %inner_table)) => { %(inner_pattern %inner_table) } }
    )
    %(mk arg_pattern ($ %1:item, $ %(string_to_ident %(concat "real_" $(run %1))):item, $real:item, %(array map true item %pattern %(run %2))))
    %(mk macro_rules macro_rules! %(run %1) { %(array map true inner_table %(run %2) %(run %3)) })
    %(array each macro_rules %table))

It is also useful to import code that uses a different sigil; for example, if you have a shared header that defines some common handlers and data, but it is used in invocations that use different sigils, you can wrap the import in a withSigil matching the sigil the imported file uses.