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

Parse error for some valid procedural attribute macros, derive macro helper attributes #92

Closed
ninevra opened this issue Nov 14, 2020 · 0 comments · Fixed by #93
Closed

Comments

@ninevra
Copy link
Contributor

ninevra commented Nov 14, 2020

tree-sitter-rust parses attributes using the meta-item syntax, which is the syntax used by most of rust's built-in attributes. The meta-item syntax is a subset of the attr syntax. Procedural attribute macros, however, use a larger subset of the attr syntax allowing arbitrary DelimTokenTrees. Derive macro helper attributes use the full attr syntax. As a result, tree-sitter-rust incorrectly parses many valid attributes.

As an example, the following is one of the usage examples for the thiserror crate. thiserror defines a derive macro helper attribute, error:

#[derive(Error, Debug)]
pub enum Error {
    #[error("first letter must be lowercase but was {:?}", first_char(.0))]
    WrongCase(String),
    #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)]
    OutOfBounds { idx: usize, limits: Limits },
} 

The phrases .limits.lo, .limits.hi, and first_char(.0) are legal under the attr syntax but not under meta-item, and so these attributes are parsed incorrectly.

This is likely the cause of atom/atom#20897. Any attribute not conforming to meta-item currently breaks atom's rust syntax highlighting.

Attributes should instead be parsed using the more permissive attr syntax.

@ninevra ninevra changed the title Incorrect parse for procedural attribute macros, derive macro helper attributes Parse error for some valid procedural attribute macros, derive macro helper attributes Nov 15, 2020
@aryx aryx closed this as completed in #93 Mar 9, 2022
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 a pull request may close this issue.

1 participant