this post was submitted on 11 Aug 2023
1 points (100.0% liked)

The Rust Programming Language

1 readers
0 users here now

A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and...

founded 1 year ago
MODERATORS
 
This is an automated archive made by the Lemmit Bot.

The original was posted on /r/rust by /u/SaltManager on 2023-08-10 19:35:24.


So I have been messing around with proc macros for the last couple of days with the syn crate yet I cannot get my head around just yet when it comes to the parser functions in syn.

Here is an example of what the macro could be parsing:

macro_name!{
    foo: "Some string",
    bar: "Some other string",
    baz: variable_value,
    some_ident: {
        attr1: "Oh look another string",
        attr2: "Ok now this is getting boring.."
    }
}

The order of the Idents foo, bar, baz and so on should not be important and the value of these could be a string or a variable value but that is not important for now for parsing the TokenStream.

I read the syn documentation about making you own Parse implementation but I could not find anywhere on how to iterate over a TokenStream and parsing it with my custom parsing function.

Does anyone know a resource I could look into?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here