Skip to content

Don't require semicolon after macro definition #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aochagavia opened this issue Nov 8, 2018 · 9 comments
Closed

Don't require semicolon after macro definition #220

aochagavia opened this issue Nov 8, 2018 · 9 comments

Comments

@aochagavia
Copy link
Contributor

The following code generates a syntax error "expected SEMI" at the position of the cursor

fn test() {
    macro_rules! indent {
        () => {
            for _ in 0..level {
                buf.push_str("  ");
            }
        };
    }<|>
    return;
}
@phansch
Copy link
Member

phansch commented Nov 8, 2018

This looks like a nice starter issue. I would like to see if I can fix it today.

@aochagavia
Copy link
Contributor Author

aochagavia commented Nov 8, 2018

Feel free to ask for help here if you get stuck 😉

@phansch
Copy link
Member

phansch commented Nov 10, 2018

I think I jumped the gun a bit early here. Holiday is coming up next week and I want to finish up a compilers course (this one) so that I start with proper understanding of the basics. I do want to get involved, it may just take a few more weeks =)

If someone else wants to pick this up, feel free!

@aochagavia
Copy link
Contributor Author

It turns out this is not only a problem for macro definitions, but also macro usage. I have created #225 which is more general.

@DJMcNab
Copy link
Contributor

DJMcNab commented Nov 10, 2018

But surely macro definition and usages are different constructs entirely. I would argue that this is should be simpler to fix than #225. It might only require a change to https://github.com/rust-analyzer/rust-analyzer/blob/477de790b0211196256a772befe4f577d1a8ba14/crates/ra_syntax/src/grammar/expressions/mod.rs#L204-L209

@aochagavia
Copy link
Contributor Author

macro_rules! is itself a macro, so macro definition is actually a macro usage, as surprising as it may sound

@DJMcNab
Copy link
Contributor

DJMcNab commented Nov 10, 2018

I thought it has different syntax, i.e. macro_rules! $name: ident {$inner: tt}, which you cannot define with a regular macro. I'm not certain though

@aochagavia
Copy link
Contributor Author

I think it is true that you can't define own macros with that syntax. Still, the parser currently treats macro_rules! as a macro usage (you can test that by displaying the AST in VSCode). We could consider changing that, though I am not sure it is worth it to make a distinction at the parser level.

@CAD97
Copy link
Contributor

CAD97 commented Nov 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants