"error: non-item in item list" what does this mean? + another question on attributes

I am trying to write a procedural macro.

#[proc_macro_attribute]
pub fn evaluate(args: TokenStream, input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let name = input.ident;

    let stream = proc_macro2::TokenStream::from(args);
    let operator = stream.into_iter().next().unwrap();

    let result = quote! {
        struct #name {}

        impl Eval for #name {
            fn evaluate(obj1: Value, obj2: Value) -> bool {
                if obj1.is_i64() {
                    return obj1.as_i64() #operator obj2.as_i64();
                }

                return false;
            };
        }
    };

    result.into()
}

cargo expand shows that this is what get generated

struct GreaterThan {}
impl Eval for GreaterThan {
    fn evaluate(obj1: Value, obj2: Value) -> bool {
        if obj1.is_i64() {
            return obj1.as_i64() > obj2.as_i64();
        }
        return false;
    }
}

But when I compile I get this strange error

5 | #[evaluate(>)]
  | ^^^^^^^^^^^^^^
  | |
  | item list starts here
  | non-item starts here
  | item list ends here

additionally if I use a double equals

#[evaluate(==)]
struct Equals {}

The code just uses a single equals in the result

return obj1.as_i64() = obj2.as_i64();

that is most probably because i am just using a single item int eh token tree with the .next() code, but how can I cater for single and double operators so this is still valid

return obj1.as_i64() #operator obj2.as_i64();

I know it's a bit of a mixed bag of questions here but I feel like I have lost my way and would greatly appreciate some help getting this macro up and running properly.

Looking at that source, perhaps the semicolon after fn evaluate's body is problematic?

Regarding the equals-signs question, I don't know enough about proc macros and token stream API to be able to answer that.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.