commit | 795ee428ffc3bbdafbb4b51ce7090c82e9c30363 | [log] [tgz] |
---|---|---|
author | David Tolnay <dtolnay@gmail.com> | Tue Sep 27 18:08:35 2016 -0700 |
committer | GitHub <noreply@github.com> | Tue Sep 27 18:08:35 2016 -0700 |
tree | dbe92bc235296cca176e2a0e7c484310eede547a | |
parent | a3faf259f2620fc6cc38d81b96a6814716f119b6 [diff] | |
parent | 1b69f6830344d3b517d29e45add5ef6418fc6ca5 [diff] |
Merge pull request #14 from gregkatz/master Added an infinite loop parser and tests.
Parse Rust structs and enums without a Syntex dependency, intended for use with Macros 1.1.
Designed for fast compile time.
syn
(from scratch including all dependencies): 4 secondssyntex
/quasi
/aster
stack: 60+ seconds[dependencies] syn = "0.8" quote = "0.2" [lib] rustc-macro = true
#![feature(rustc_macro, rustc_macro_lib)] extern crate rustc_macro; use rustc_macro::TokenStream; extern crate syn; #[macro_use] extern crate quote; #[rustc_macro_derive(MyMacro)] pub fn my_macro(input: TokenStream) -> TokenStream { let source = input.to_string(); // Parse a string of items to an AST let ast = syn::parse_macro_input(&source).unwrap(); // Build the output, possibly using quasi-quotation let expanded = quote! { // ... }; // Parse this back to a token stream and return it expanded.to_string().parse().unwrap() }
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.