Skip to content
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

Error handling for macros #916

Merged
merged 5 commits into from Mar 4, 2019
Merged

Conversation

detrumi
Copy link
Member

@detrumi detrumi commented Mar 2, 2019

Part of #720

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, lgtm, but let's try to separate parsing & expansion errors. And perhaps it would be a good idea to write some unit-tests for parsing and exapnsion of erroneous macros.

crates/ra_mbe/src/lib.rs Show resolved Hide resolved
@detrumi
Copy link
Member Author

detrumi commented Mar 3, 2019

I've added some simple tests for error cases. The test organization could be better, but I didn't want to dump all tests in lib.rs.

There's also some weirdness with Var.kind, which is kinda best-effort while other parts aren't.

@matklad
Copy link
Member

matklad commented Mar 4, 2019

Excellent, bors r+

@matklad
Copy link
Member

matklad commented Mar 4, 2019

bors r+

bors bot added a commit that referenced this pull request Mar 4, 2019
916: Error handling for macros r=matklad a=detrumi

Part of #720 

Co-authored-by: Wilco Kusee <wilcokusee@gmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 4, 2019

Build succeeded

@bors bors bot merged commit c9d6efc into rust-lang:master Mar 4, 2019
@matklad
Copy link
Member

matklad commented Mar 4, 2019

A next step would be to fix

            while let Ok(t) = expand_subtree(&repeat.subtree, bindings, nesting) {
                let idx = nesting.pop().unwrap();
                nesting.push(idx + 1);
                token_trees.push(t.into())
            }

logic. This is for handling repeates: if $($name:ident)* matched foo bar baz in the input, than $(struct $name)* should be expanded three times in the result. The current logic is basically "repeat until any error occurs", while it should be more like "repeat the n times", where n is figured out somehow... That is, there are two problems with the current impl:

  • it may mask legitimate errors
  • I don't really understand why it works in the first place :)

It would be cool to dig into the rustc implementation and figure out to handle this properly. The useful bits of rustc are:

  • NamedMatch which is analagous to our Bindings struct
  • transcribe whihc handles the actual expansion.

@detrumi detrumi deleted the macro-error-handling branch March 4, 2019 11:14
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

Successfully merging this pull request may close these issues.

None yet

2 participants