Skip to content
Snippets Groups Projects
Commit 909360a2 authored by Per Lindgren's avatar Per Lindgren
Browse files

wip

parent 3a52eec7
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,9 @@ extern crate parsetest; ...@@ -4,7 +4,9 @@ extern crate parsetest;
use parsetest::app; use parsetest::app;
app!{ app!{
id1, id2 id1 ,
id2 ,
id2 ,
} }
fn main() { fn main() {
......
#![feature(proc_macro)] #![feature(proc_macro)]
extern crate proc_macro; extern crate proc_macro;
extern crate proc_macro2 as pm2;
#[macro_use] #[macro_use]
extern crate quote; extern crate quote;
#[macro_use] #[macro_use]
...@@ -24,10 +25,7 @@ pub fn lit(input: TokenStream) -> TokenStream { ...@@ -24,10 +25,7 @@ pub fn lit(input: TokenStream) -> TokenStream {
if !(10 <= value && value < 100) { if !(10 <= value && value < 100) {
v.span() v.span()
.unstable() .unstable()
.error(format!( .error(format!("expected literal 10 <= x < 100, got {}", value,))
"expected literal 10 <= x < 100, got {}",
value,
))
.emit(); .emit();
} }
From::from(v.into_tokens()) From::from(v.into_tokens())
...@@ -43,10 +41,7 @@ pub fn lite(input: TokenStream) -> TokenStream { ...@@ -43,10 +41,7 @@ pub fn lite(input: TokenStream) -> TokenStream {
if !(10 <= value && value < 100) { if !(10 <= value && value < 100) {
v.span() v.span()
.unstable() .unstable()
.error(format!( .error(format!("expected literal 10 <= x < 100, got {}", value,))
"expected literal 10 <= x < 100, got {}",
value,
))
.emit(); .emit();
} }
From::from(v.into_tokens()) From::from(v.into_tokens())
...@@ -61,8 +56,6 @@ pub fn lite(input: TokenStream) -> TokenStream { ...@@ -61,8 +56,6 @@ pub fn lite(input: TokenStream) -> TokenStream {
} }
} }
use syn::Path;
enum AppKeys { enum AppKeys {
Device, Device,
Resources, Resources,
...@@ -107,24 +100,35 @@ fn to_app_keys(id: Ident) -> Option<AppKeys> { ...@@ -107,24 +100,35 @@ fn to_app_keys(id: Ident) -> Option<AppKeys> {
// } // }
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
struct AppK {}
struct KeyVal { struct KeyVal {
kv: Punctuated<Ident, Token![,]>, key: Ident,
val: pm2::TokenStream,
} }
impl Synom for KeyVal { impl Synom for KeyVal {
named!(parse -> Self, do_parse!( named!(parse -> Self, do_parse!(
kv: call!(Punctuated::parse_terminated_nonempty) >> key: call!(Ident::parse) >>
(KeyVal { kv }) val: call!(pm2::TokenStream::parse) >> (KeyVal { key, val })
));
}
struct KeyVals {
keyvals: Punctuated<Ident, Token![,]>,
}
impl Synom for KeyVals {
named!(parse -> Self, do_parse!(
keyvals: call!(Punctuated::parse_terminated_nonempty) >>
(KeyVals { keyvals })
)); ));
} }
#[proc_macro] #[proc_macro]
pub fn app(input: TokenStream) -> TokenStream { pub fn app(input: TokenStream) -> TokenStream {
println!("-- app --"); println!("-- app --");
let k: KeyVal = syn::parse(input).unwrap(); let k: KeyVals = syn::parse(input).unwrap();
for k in k.kv.into_iter() { for k in k.keyvals.into_iter() {
println!("{:?}", k.as_ref()); println!("{:?}", k.as_ref());
} }
// { // {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment