Giter Club home page Giter Club logo

Comments (2)

taiki-e avatar taiki-e commented on July 17, 2024 1

I added the two dbg to the following code:

// `=> <expr>`
input.parse::<Token![=>]>()?;
let expr = input.parse::<Expr>()?;

 fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
 
             // `=> <expr>`
             input.parse::<Token![=>]>()?;
+            dbg!(&input);
             let expr = input.parse::<Expr>()?;
+            dbg!(&input);
 
             // Commas after the expression are only optional if it's a `Block`
             // or it is the last branch in the `match`.

And the output is:

[futures-macro/src/select.rs:62:13] &input = TokenStream [
    Group {
        delimiter: Brace,
        stream: TokenStream [],
        span: #0 bytes(10909..10911),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: #0 bytes(10924..10926),
    },
    Punct {
        ch: '=',
        spacing: Alone,
        span: #0 bytes(10927..10928),
    },
    Ident {
        ident: "pending",
        span: #0 bytes(10929..10936),
    },
    Punct {
        ch: ':',
        spacing: Joint,
        span: #0 bytes(10936..10937),
    },
    Punct {
        ch: ':',
        spacing: Joint,
        span: #0 bytes(10937..10938),
    },
    Punct {
        ch: '<',
        spacing: Alone,
        span: #0 bytes(10938..10939),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: #0 bytes(10939..10941),
    },
    Punct {
        ch: '>',
        spacing: Alone,
        span: #0 bytes(10941..10942),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: #0 bytes(10942..10944),
    },
    Punct {
        ch: '.',
        spacing: Alone,
        span: #0 bytes(10944..10945),
    },
    Ident {
        ident: "fuse",
        span: #0 bytes(10945..10949),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: #0 bytes(10949..10951),
    },
    Punct {
        ch: '=',
        spacing: Joint,
        span: #0 bytes(10952..10953),
    },
    Punct {
        ch: '>',
        spacing: Alone,
        span: #0 bytes(10953..10954),
    },
    Group {
        delimiter: Brace,
        stream: TokenStream [],
        span: #0 bytes(10955..10957),
    },
]
[futures-macro/src/select.rs:64:13] &input = TokenStream [
    Punct {
        ch: '=',
        spacing: Joint,
        span: #0 bytes(10952..10953),
    },
    Punct {
        ch: '>',
        spacing: Alone,
        span: #0 bytes(10953..10954),
    },
    Group {
        delimiter: Brace,
        stream: TokenStream [],
        span: #0 bytes(10955..10957),
    },
]
error: expected `,`
   --> futures/tests/async_await_macros.rs:402:41
    |
402 |             () = pending::<()>().fuse() => {}
    |                                         ^

It seems syn treats {} () = pending::<()>().fuse() as a single expr.
cc @dtolnay

from futures-rs.

dtolnay avatar dtolnay commented on July 17, 2024 1

{} () = pending::<()>().fuse() is a single expr.

macro_rules! expr {
    ($e:expr) => {};
}

expr!({} () = pending::<()>().fuse());

To parse this in a way that uses the expression termination rules of match arms, what you could do is: after parsing your =>, collect all the rest of the tokens into a TokenStream prefixed with _ =>, then parse syn::Arm from that, and keep just the body from that. Then repeat on whatever tokens are left.

from futures-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.