aboutsummaryrefslogtreecommitdiff
path: root/macros/src/syntax
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-06 17:51:34 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-06 17:51:34 -0500
commit4b0c3bff871eb6125835fd911891bf503c61c820 (patch)
tree7110c0bdd1f87c9cd04092bffb1dad61bb6d5fdb /macros/src/syntax
parent86a360a3964ecb04a37c0424c76d7b43a9fd40fe (diff)
downloadrtic-4b0c3bff871eb6125835fd911891bf503c61c820.tar.gz
rtic-4b0c3bff871eb6125835fd911891bf503c61c820.tar.zst
rtic-4b0c3bff871eb6125835fd911891bf503c61c820.zip
rtfm!: remove init.resources and make idle.local optional
Diffstat (limited to 'macros/src/syntax')
-rw-r--r--macros/src/syntax/mod.rs1
-rw-r--r--macros/src/syntax/parse.rs66
2 files changed, 44 insertions, 23 deletions
diff --git a/macros/src/syntax/mod.rs b/macros/src/syntax/mod.rs
index c856617e..53c17a82 100644
--- a/macros/src/syntax/mod.rs
+++ b/macros/src/syntax/mod.rs
@@ -17,7 +17,6 @@ pub struct App {
#[derive(Debug)]
pub struct Init {
pub path: Tokens,
- pub resources: HashSet<Ident>,
}
#[derive(Debug)]
diff --git a/macros/src/syntax/parse.rs b/macros/src/syntax/parse.rs
index e6d3f461..9cfbd78b 100644
--- a/macros/src/syntax/parse.rs
+++ b/macros/src/syntax/parse.rs
@@ -1,7 +1,6 @@
use std::collections::{HashMap, HashSet};
use syn::{self, DelimToken, Ident, IntTy, Lit, Token, TokenTree};
-use quote::Tokens;
use syntax::{App, Idle, Init, Kind, Resource, Resources, Task, Tasks};
@@ -136,10 +135,7 @@ pub fn app(input: &str) -> App {
}
}
-fn idle_init(
- tts: Vec<TokenTree>,
- allows_locals: bool,
-) -> (Option<Resources>, Tokens, HashSet<Ident>) {
+pub fn idle(tts: Vec<TokenTree>) -> Idle {
let mut tts = tts.into_iter();
let mut local = None;
@@ -161,7 +157,7 @@ fn idle_init(
);
match id.as_ref() {
- "local" if allows_locals => {
+ "local" => {
assert!(local.is_none(), "duplicated local field");
let tt = tts.next();
@@ -183,7 +179,8 @@ fn idle_init(
let mut pieces = vec![];
loop {
- let tt = tts.next().expect("expected comma, found EOM");
+ let tt = tts.next()
+ .expect("expected comma, found end of macro");
if tt == TokenTree::Token(Token::Comma) {
path = Some(quote!(#(#pieces)*));
@@ -225,27 +222,52 @@ fn idle_init(
);
}
- (
- local,
- path.expect("path field is missing"),
- resources.unwrap_or(HashSet::new()),
- )
-}
-
-pub fn idle(tts: Vec<TokenTree>) -> Idle {
- let (locals, path, resources) = idle_init(tts, true);
-
Idle {
- local: locals.expect("local field is missing"),
- path,
- resources,
+ local: local.unwrap_or(HashMap::new()),
+ path: path.expect("path field is missing"),
+ resources: resources.unwrap_or(HashSet::new()),
}
}
pub fn init(tts: Vec<TokenTree>) -> Init {
- let (_, path, resources) = idle_init(tts, false);
+ let mut tts = tts.into_iter();
+
+ let mut path = None;
+ while let Some(tt) = tts.next() {
+ let id = if let TokenTree::Token(Token::Ident(id)) = tt {
+ id
+ } else {
+ panic!("expected ident, found {:?}", tt);
+ };
+
+ let tt = tts.next();
+ assert_eq!(
+ tt,
+ Some(TokenTree::Token(Token::Colon)),
+ "expected colon, found {:?}",
+ tt
+ );
+
+ match id.as_ref() {
+ "path" => {
+ let mut pieces = vec![];
+ loop {
+ let tt = tts.next()
+ .expect("expected comma, found end of macro");
+
+ if tt == TokenTree::Token(Token::Comma) {
+ path = Some(quote!(#(#pieces)*));
+ break;
+ } else {
+ pieces.push(tt);
+ }
+ }
+ }
+ id => panic!("unexpected field {}", id),
+ }
+ }
- Init { path, resources }
+ Init { path: path.expect("path field is missing") }
}
fn idents(tts: Vec<TokenTree>) -> HashSet<Ident> {