From 909360a29cae9e87fb464f446bd35f7a290ef8d7 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Fri, 16 Mar 2018 21:23:51 +0100
Subject: [PATCH] wip

---
 examples/app.rs |  4 +++-
 src/lib.rs      | 36 ++++++++++++++++++++----------------
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/examples/app.rs b/examples/app.rs
index a5690dd..c848e54 100644
--- a/examples/app.rs
+++ b/examples/app.rs
@@ -4,7 +4,9 @@ extern crate parsetest;
 use parsetest::app;
 
 app!{
-    id1, id2
+    id1 ,
+    id2 ,
+    id2 ,
 }
 
 fn main() {
diff --git a/src/lib.rs b/src/lib.rs
index b8d51aa..4aea5bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,7 @@
 #![feature(proc_macro)]
 
 extern crate proc_macro;
+extern crate proc_macro2 as pm2;
 #[macro_use]
 extern crate quote;
 #[macro_use]
@@ -24,10 +25,7 @@ pub fn lit(input: TokenStream) -> TokenStream {
     if !(10 <= value && value < 100) {
         v.span()
             .unstable()
-            .error(format!(
-                "expected literal 10 <= x < 100, got {}",
-                value,
-            ))
+            .error(format!("expected literal 10 <= x < 100, got {}", value,))
             .emit();
     }
     From::from(v.into_tokens())
@@ -43,10 +41,7 @@ pub fn lite(input: TokenStream) -> TokenStream {
             if !(10 <= value && value < 100) {
                 v.span()
                     .unstable()
-                    .error(format!(
-                        "expected literal 10 <= x < 100, got {}",
-                        value,
-                    ))
+                    .error(format!("expected literal 10 <= x < 100, got {}", value,))
                     .emit();
             }
             From::from(v.into_tokens())
@@ -61,8 +56,6 @@ pub fn lite(input: TokenStream) -> TokenStream {
     }
 }
 
-use syn::Path;
-
 enum AppKeys {
     Device,
     Resources,
@@ -107,24 +100,35 @@ fn to_app_keys(id: Ident) -> Option<AppKeys> {
 // }
 
 use syn::punctuated::Punctuated;
-struct AppK {}
 
 struct KeyVal {
-    kv: Punctuated<Ident, Token![,]>,
+    key: Ident,
+    val: pm2::TokenStream,
 }
 
 impl Synom for KeyVal {
     named!(parse -> Self, do_parse!(
-        kv: call!(Punctuated::parse_terminated_nonempty) >> 
-        (KeyVal { kv })
+        key: call!(Ident::parse) >> 
+        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]
 pub fn app(input: TokenStream) -> TokenStream {
     println!("-- app --");
-    let k: KeyVal = syn::parse(input).unwrap();
-    for k in k.kv.into_iter() {
+    let k: KeyVals = syn::parse(input).unwrap();
+    for k in k.keyvals.into_iter() {
         println!("{:?}", k.as_ref());
     }
     //  {
-- 
GitLab