More experimentation

This commit is contained in:
greg 2018-04-28 15:35:04 -07:00
parent bf7533cdbe
commit 9015cbee21
2 changed files with 18 additions and 35 deletions

View File

@ -10,12 +10,22 @@ use syn::{Expr, Lit, ExprLit};
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
use syn::synom::Synom; use syn::synom::Synom;
fn tok() -> String {
"ONE THING FROM A MACRO|".to_string()
}
fn pars() -> String { fn get_string_args(input: Expr) -> Vec<String> {
"ANOTHER MACRO THING|".to_string() let mut contained_strings = Vec::new();
match input {
Expr::Array(array) => {
for item in array.elems {
if let Expr::Lit(ExprLit { lit: Lit::Str(s), ..}) = item {
contained_strings.push(s.value());
} else {
panic!("Non-string-literal input to compiler_pass_sequence");
}
}
},
_ => panic!("Non-array input to compiler_pass_sequence"),
}
contained_strings
} }
#[proc_macro] #[proc_macro]
@ -30,34 +40,9 @@ pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream {
} }
*/ */
let mut contained_strings = Vec::new();
let input: Expr = syn::parse(input).unwrap(); let input: Expr = syn::parse(input).unwrap();
match input { let stages = get_string_args(input);
Expr::Array(array) => { let from_macro = format!("{:?}", stages);
for item in array.elems {
if let Expr::Lit(ExprLit { lit: Lit::Str(s), ..}) = item {
contained_strings.push(s.value());
} else {
panic!("BAD INPUT");
}
}
},
_ => panic!("BAD INPUT"),
}
let mut from_macro = String::new();
for item in contained_strings {
if item == "tok" {
from_macro.push_str(tok().as_ref());
}
if item == "pars" {
from_macro.push_str(pars().as_ref());
}
}
let output = quote! { let output = quote! {
fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation { fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation {
@ -107,6 +92,4 @@ mod tests {
Outcome::from(req, responder); Outcome::from(req, responder);
} }
*/ */

View File

@ -43,7 +43,7 @@ impl Schala {
impl ProgrammingLanguageInterface for Schala { impl ProgrammingLanguageInterface for Schala {
schala_codegen::compiler_pass_sequence!(["tok"]); schala_codegen::compiler_pass_sequence!(["tokenize", "parse", "yolo"]);
fn get_language_name(&self) -> String { fn get_language_name(&self) -> String {
"Schala".to_string() "Schala".to_string()