Some experimentation

This commit is contained in:
greg 2018-04-28 03:31:53 -07:00
parent 2c79984678
commit bf7533cdbe
3 changed files with 65 additions and 6 deletions

View File

@ -4,6 +4,9 @@ version = "0.1.0"
authors = ["greg <greg.shuflin@protonmail.com>"]
[dependencies]
quote = "0.5.2"
syn = { version = "0.13.1", features = ["full"] }
[lib]
proc-macro = true

View File

@ -1,15 +1,71 @@
#![feature(proc_macro)]
extern crate proc_macro;
#[macro_use]
extern crate syn;
#[macro_use]
extern crate quote;
use proc_macro::TokenStream;
use syn::{Expr, Lit, ExprLit};
use syn::punctuated::Punctuated;
use syn::synom::Synom;
fn tok() -> String {
"ONE THING FROM A MACRO|".to_string()
}
fn pars() -> String {
"ANOTHER MACRO THING|".to_string()
}
#[proc_macro]
pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream {
r#"
fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation {
let mut evaluation = UnfinishedComputation::default();
evaluation.output(Err("this comes at ye from the macro".to_string()))
/*
for token_tree in input {
//println!("ITEM: {:?}", token_tree.kind);
match token_tree.kind {
TokenNode::Literal(l) => println!("{:?}", l),
_ => ()
}
}
"#.parse().unwrap()
*/
let mut contained_strings = Vec::new();
let input: Expr = syn::parse(input).unwrap();
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!("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! {
fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation {
let mut evaluation = UnfinishedComputation::default();
evaluation.output(Err(#from_macro.to_string()))
}
};
output.into()
}
/* #[compiler_pass(<name of pass>*/

View File

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