Skip to content

Commit

Permalink
highlight: rust: recognise more enum variants
Browse files Browse the repository at this point in the history
Now we recognise any PascalCase::PascalCase.method() as being
Enum::Variant.method(). We recognise PascalCase::PascalCase.field too,
but I don't think that's legal anywhere as the lhs of the dot can only be
a unit enum variant or an associated type, neither of which can have
fields.
  • Loading branch information
rosefromthedead committed Nov 30, 2023
1 parent c7f89ae commit 2f79a26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions runtime/queries/rust/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@
])
(identifier) @type.enum.variant (#match? @type.enum.variant "^[A-Z]")])

; ---
; PascalCase identifiers under a path which is also PascalCase
; are assumed to be enum variants if they have methods or fields.
; ---

(field_expression
value: (scoped_identifier
path: [
(identifier) @type.enum
(scoped_identifier
name: (identifier) @type.enum)
]
name: (identifier) @type.enum.variant
(#match? @type.enum "^[A-Z]")
(#match? @type.enum.variant "^[A-Z]")))

; ---
; Other PascalCase identifiers are assumed to be structs.
; ---
Expand Down

0 comments on commit 2f79a26

Please sign in to comment.