Skip to content

Commit

Permalink
Feat: parse shuttle::endpoint macro (#490)
Browse files Browse the repository at this point in the history
* feat: parse params

* feat: parse app

* feat: add test for missing endpoint attribute

* test: invalid args, params and syntax

* feat: check for and test no params

* feat: don't emit error for missing annotation

this way users can create separate functions for their endpoint logic

* fix: remove missing attribute error, not param

* refactor: reword comment

Co-authored-by: Pieter <pieter@chesedo.me>

* feat: duplicate param test, address review

* feat: only strip endpoint attributes

* feat: check for extra endpoint attributes

* refactor: clearer error span for extra endpoints

* feat: has_err variable to group param errors

* refactor: remove optional hint

Co-authored-by: Pieter <pieter@chesedo.me>

* docs: add TODO for multiple endpoint attributes

Co-authored-by: Pieter <pieter@chesedo.me>
  • Loading branch information
oddgrd and chesedo authored Dec 4, 2022
1 parent c2b0f63 commit 16abe40
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 4 deletions.
16 changes: 16 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
mod main;
mod next;

use next::App;
use proc_macro::TokenStream;
use proc_macro_error::proc_macro_error;
use syn::{parse_macro_input, File};

#[proc_macro_error]
#[proc_macro_attribute]
pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream {
main::r#impl(attr, item)
}

#[proc_macro_error]
#[proc_macro]
pub fn app(item: TokenStream) -> TokenStream {
let mut file = parse_macro_input!(item as File);

let app = App::from_file(&mut file);

quote::quote!(
#file
#app
)
.into()
}
2 changes: 1 addition & 1 deletion codegen/src/main/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,6 @@ mod tests {
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
t.compile_fail("tests/ui/main/*.rs");
}
}
Loading

0 comments on commit 16abe40

Please sign in to comment.