From 48d6ef7eadd7e2b46fa7ddbc35ad3c4349cfe56e Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 18 Jun 2019 16:59:48 -0700 Subject: [PATCH] Split parsing and generation into separate modules. --- src/gen.rs | 27 +++++++++++++++++++++++++++ src/lib.rs | 5 +++-- src/{event.rs => parse.rs} | 26 ++------------------------ 3 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 src/gen.rs rename src/{event.rs => parse.rs} (94%) diff --git a/src/gen.rs b/src/gen.rs new file mode 100644 index 00000000..30fdf61e --- /dev/null +++ b/src/gen.rs @@ -0,0 +1,27 @@ +//! Details of generating code for the `ruma_event` procedural macro. + +use proc_macro2::TokenStream; +use quote::{quote, ToTokens}; + +use crate::parse::RumaEventInput; + +/// The result of processing the `ruma_event` macro, ready for output back to source code. +pub struct RumaEvent; + +impl From for RumaEvent { + // TODO: Provide an actual impl for this. + fn from(_input: RumaEventInput) -> Self { + Self + } +} + +impl ToTokens for RumaEvent { + // TODO: Provide an actual impl for this. + fn to_tokens(&self, tokens: &mut TokenStream) { + let output = quote!( + pub struct Foo {} + ); + + output.to_tokens(tokens); + } +} diff --git a/src/lib.rs b/src/lib.rs index 40948117..537e7198 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,9 +34,10 @@ extern crate proc_macro; use proc_macro::TokenStream; use quote::ToTokens; -use crate::event::{RumaEvent, RumaEventInput}; +use crate::{gen::RumaEvent, parse::RumaEventInput}; -mod event; +mod gen; +mod parse; // A note about the `example` modules that appears in doctests: // diff --git a/src/event.rs b/src/parse.rs similarity index 94% rename from src/event.rs rename to src/parse.rs index 40980b30..d4812147 100644 --- a/src/event.rs +++ b/src/parse.rs @@ -1,8 +1,7 @@ -//! Details of the `ruma_event` procedural macro. +//! Details of parsing input for the `ruma_event` procedural macro. -use proc_macro2::{Span, TokenStream}; +use proc_macro2::Span; -use quote::{quote, ToTokens}; use syn::{ braced, parse::{self, Parse, ParseStream}, @@ -12,27 +11,6 @@ use syn::{ TypePath, }; -/// The result of processing the `ruma_event` macro, ready for output back to source code. -pub struct RumaEvent; - -impl From for RumaEvent { - // TODO: Provide an actual impl for this. - fn from(_input: RumaEventInput) -> Self { - Self - } -} - -impl ToTokens for RumaEvent { - // TODO: Provide an actual impl for this. - fn to_tokens(&self, tokens: &mut TokenStream) { - let output = quote!( - pub struct Foo {} - ); - - output.to_tokens(tokens); - } -} - /// The entire `ruma_event!` macro structure directly as it appears in the source code.. pub struct RumaEventInput { /// Outer attributes on the field, such as a docstring.