easy-plugin

Crates.ioeasy-plugin
lib.rseasy-plugin
version0.11.8
sourcesrc
created_at2015-11-12 21:44:32.833684
updated_at2017-01-19 22:36:45.767521
descriptionA compiler plugin that makes it easier to write compiler plugins.
homepage
repositoryhttps://github.com/KyleMayes/easy-plugin
max_upload_size
id3403
size59,984
Kyle Mayes (KyleMayes)

documentation

https://kylemayes.github.io/easy-plugin/easy_plugin

README

easy-plugin

crates.io Travis CI

A compiler plugin that makes it easier to write compiler plugins.

Released under the Apache License 2.0.

Supported Configurations

By default, easy-plugin expects to be compiled by a nightly Rust compiler. easy-plugin is also supported on the stable and beta channels of Rust with syntex. To enable this support, enable the stable Cargo feature.

Note: If the syntex crate is not in sync with the latest nightly, you may not be able to use the latest version of this crate on the stable or beta Rust channels.

Example

The following usage of easy_plugin! defines a plugin which accepts key-value pairs.

easy_plugin! {
    // A key can either be an identifier or a string literal.
    enum Key {
        Ident { $key:ident },
        Lit { $key:lit_str },
    }

    // A key-value pair is a key followed by `=>` and any expression.
    struct KeyValuePair {
        $key:$Key => $value:expr
    }

    // This plugin accepts one or more comma-separated key-value pairs.
    struct Arguments {
        $($kvp:$KeyValuePair), + $(,)?
    }

    pub fn expand_kvp(
        _: &mut ExtCtxt, span: Span, arguments: Arguments
    ) -> PluginResult<Box<MacResult>> {
        for KeyValuePair { key, value } in arguments.kvp {
            match key {
                Key::Ident { key } => println!("Key:   {}", key.node),
                Key::Lit { key } => println!("Key:   {:?}", key.0),
            }
            println!("Value: {}", pprust::expr_to_string(&value));
        }
        Ok(DummyResult::any(span))
    }
}

#[plugin_registrar]
pub fn plugin_registrar(registry: &mut Registry) {
    registry.register_macro("kvp", expand_kvp);
}
Commit count: 0

cargo fmt