Split parsing and generation into separate modules.
This commit is contained in:
		
							parent
							
								
									65bd8e86cc
								
							
						
					
					
						commit
						48d6ef7ead
					
				
							
								
								
									
										27
									
								
								src/gen.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/gen.rs
									
									
									
									
									
										Normal file
									
								
							@ -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<RumaEventInput> 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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:
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
@ -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<RumaEventInput> 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.
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user