From d1a2473bb2d865b0b29a91c1fe1ed6f2113d872e Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 2 May 2018 20:43:05 -0700 Subject: [PATCH] More derive work --- schala-codegen/src/lib.rs | 31 ++++--------------------------- schala-lang/src/lib.rs | 1 + 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/schala-codegen/src/lib.rs b/schala-codegen/src/lib.rs index 2cbecfc..63a39d5 100644 --- a/schala-codegen/src/lib.rs +++ b/schala-codegen/src/lib.rs @@ -7,11 +7,6 @@ extern crate syn; use proc_macro::TokenStream; use syn::{Attribute, DeriveInput}; -#[proc_macro] -pub fn print_a_thing(_input: TokenStream) -> TokenStream { - "println!(\"Invoked from a proc macro\");".parse().unwrap() -} - fn extract_attribute_arg_by_name(name: &str, attrs: &Vec) -> Option { use syn::{Meta, Lit, MetaNameValue}; attrs.iter().map(|attr| attr.interpret_meta()).find(|meta| { @@ -28,32 +23,14 @@ fn extract_attribute_arg_by_name(name: &str, attrs: &Vec) -> Option TokenStream { let ast: DeriveInput = syn::parse(input).unwrap(); let name = &ast.ident; let attrs = &ast.attrs; - let language_name: String = extract_attribute_arg_by_name("LanguageName", attrs).unwrap(); - - println!("LANG NAME: {:?}", language_name); - - /* - println!("ATTRS {:?}", attrs); - let meta: Option = attrs.get(0).unwrap().interpret_meta(); - println!("META: {:?}", meta); - match meta { - Some(syn::Meta::NameValue(syn::MetaNameValue { lit, .. })) => { - println!("GOT LIT: {:?}", lit); - match lit { - syn::Lit::Str(litstr) => println!("VAL: {}", litstr.value()), - _ => panic!("OI") - } - } - _ => panic!("YO") - } - */ - + let language_name: String = extract_attribute_arg_by_name("LanguageName", attrs).expect("LanguageName is required"); + let file_ext = extract_attribute_arg_by_name("SourceFileExtension", attrs).expect("SourceFileExtension is required"); let tokens = quote! { impl ProgrammingLanguageInterface for #name { @@ -62,7 +39,7 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream } fn get_source_file_suffix(&self) -> String { - #language_name.to_string() + #file_ext.to_string() } fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { let mut chain = pass_chain![self, options; diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 4477a99..e6c4a03 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -29,6 +29,7 @@ use self::typechecking::{TypeContext}; #[derive(ProgrammingLanguageInterface)] #[LanguageName = "Schala"] +#[SourceFileExtension = "schala"] pub struct Schala { state: eval::State<'static>, type_context: TypeContext