You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)]pubenumError{#[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.
The text was updated successfully, but these errors were encountered:
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
tree-sitter-rust
parses attributes using themeta-item
syntax, which is the syntax used by most of rust's built-in attributes. Themeta-item
syntax is a subset of theattr
syntax. Procedural attribute macros, however, use a larger subset of theattr
syntax allowing arbitraryDelimTokenTree
s. Derive macro helper attributes use the fullattr
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
:The phrases
.limits.lo
,.limits.hi
, andfirst_char(.0)
are legal under theattr
syntax but not undermeta-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 breaksatom
's rust syntax highlighting.Attributes should instead be parsed using the more permissive
attr
syntax.The text was updated successfully, but these errors were encountered: