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

checking

parent 73597032
No related branches found
No related tags found
No related merge requests found
......@@ -69,8 +69,33 @@ key!{KeyEnabled, "enabled"}
#[proc_macro]
pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let app = parse_app(input);
//let app = check_app(app);
// let v = kv.value.as_ref().right().unwrap();
// let tokens = quote!(#v);
// panic!("{}", v)
quote!().into()
}
struct App {
device: Option<Path>,
resources: Vec<ResFields>,
init: Option<Path>,
idle: Vec<IdleFields>,
tasks: Vec<(Ident, Vec<EnumTask>)>,
}
fn parse_app(input: proc_macro::TokenStream) -> Option<App> {
let app: Punct<AppFields, Token![,]> = syn::parse(input).unwrap();
let mut device: Option<Path> = None;
let mut resources: Vec<ResFields> = Vec::new();
let mut init: Option<Path> = None;
let mut idle: Vec<IdleFields> = Vec::new();
let mut tasks: Vec<(Ident, Vec<EnumTask>)> = Vec::new();
let mut ok = true;
for AppFields { key, value } in app.data.into_iter() {
//println!("k {:?} v {:?}", key, value)
match key.as_ref() {
......@@ -80,6 +105,12 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Some(path) => {
println!("path");
println!("path {:?}", path);
if device == None {
device = Some(path.clone());
} else {
println!("Field `device` multiple defined.");
ok = false;
}
}
_ => {
println!("device should be a path");
......@@ -89,6 +120,7 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
}
"resources" => {
println!("resources");
if resources.is_empty() {
match value.right() {
Some(ts) => {
println!("ts");
......@@ -99,9 +131,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!("internal error");
}
}
} else {
println!("Field `resource` multiple defined.");
ok = false;
}
}
"init" => {
println!("init");
if init == None {
match value.right() {
Some(ts) => {
println!("ts");
......@@ -112,9 +149,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!("internal error");
}
}
} else {
println!("Field `init` multiple defined.");
ok = false;
}
}
"idle" => {
println!("idle");
if idle.is_empty() {
match value.right() {
Some(ts) => {
println!("ts");
......@@ -132,9 +174,14 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!("internal error");
}
}
} else {
println!("Field `idle` multiple defined.");
ok = false;
}
}
"tasks" => {
println!("tasks");
if tasks.is_empty() {
match value.right() {
Some(ts) => {
println!("ts");
......@@ -144,7 +191,10 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
for Tasks { id, task } in tasks.data.into_iter() {
println!("task {}", id.as_ref());
let task: Punct<EnumTask, Token![,]> = syn::parse2(task).unwrap();
let task: Punct<
EnumTask,
Token![,],
> = syn::parse2(task).unwrap();
for tf in task.data {
match tf {
EnumTask::TaskPrio(prio) => println!("prio"),
......@@ -160,16 +210,30 @@ pub fn app(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
panic!("internal error");
}
}
} else {
println!("Field `tasks` multiple defined.");
ok = false;
}
}
_ => {
println!("Illegal field");
ok = false;
}
_ => (), // unimplemented!(),
}
// println!("k {:?} ", key);
}
// let v = kv.value.as_ref().right().unwrap();
// let tokens = quote!(#v);
// panic!("{}", v)
quote!().into()
if ok {
Some(App {
device,
resources,
init,
idle,
tasks,
})
} else {
None
}
}
// Vec[T] (or perhaps not quite)
......@@ -352,3 +416,20 @@ impl Synom for Tasks {
(Tasks{id, task: task.1})
));
}
fn check_app(app: App) -> Option<App> {
let mut ok = true;
// check device
if app.device == None {
println!("Device field missing");
ok = false;
}
// check idle
if ok {
Some(app)
} else {
None
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment