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

Using parse_parens, parse_braces, parse_brackets instead of macros. #1519

Closed
wants to merge 2 commits into from

Conversation

rrupy
Copy link

@rrupy rrupy commented Oct 10, 2023

I don't understand why we have macros parenthesized, braced and bracketed.
You cannot use '?' with them, because these macros return the ParseBuffer from expression, and in case of an error, they return it from the current function.
Simple functions are better, than macros.

let content;
if let Ok(_) = (|| Ok(bracketed!(content in input)))() { }

or

if let Ok(_) = parse_braces(&input) { }

In first variant we have uninitialized variable.
Example from syn crate:

let content;
let (paren_token, content) = if input.peek(token::Paren) {
    (Some(parenthesized!(content in input)), &content)
} else {
    (None, input)
};

Perhaps we should remove these macros and make the listed functions and the values returned by them public?

rproger and others added 2 commits October 10, 2023 16:55
@mohe2015
Copy link

mohe2015 commented Jan 23, 2024

I don't know whether that would be accepted but what about just making these function public API (so remove #[doc(hidden)]) but don't change anything else? I'm currently parsing code where I also want to return (unstable) diagnostics when parsing partially fails/succeeds and there I have a different return type so can't easily use the macros

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.

2 participants