Some experimentation
This commit is contained in:
parent
2c79984678
commit
bf7533cdbe
@ -4,6 +4,9 @@ version = "0.1.0"
|
|||||||
authors = ["greg <greg.shuflin@protonmail.com>"]
|
authors = ["greg <greg.shuflin@protonmail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
quote = "0.5.2"
|
||||||
|
syn = { version = "0.13.1", features = ["full"] }
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
@ -1,15 +1,71 @@
|
|||||||
#![feature(proc_macro)]
|
#![feature(proc_macro)]
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate syn;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate quote;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
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]
|
#[proc_macro]
|
||||||
pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream {
|
pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream {
|
||||||
r#"
|
/*
|
||||||
fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation {
|
for token_tree in input {
|
||||||
let mut evaluation = UnfinishedComputation::default();
|
//println!("ITEM: {:?}", token_tree.kind);
|
||||||
evaluation.output(Err("this comes at ye from the macro".to_string()))
|
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>*/
|
/* #[compiler_pass(<name of pass>*/
|
||||||
|
@ -43,7 +43,7 @@ impl Schala {
|
|||||||
|
|
||||||
impl ProgrammingLanguageInterface for 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 {
|
fn get_language_name(&self) -> String {
|
||||||
"Schala".to_string()
|
"Schala".to_string()
|
||||||
|
Loading…
Reference in New Issue
Block a user