alex-pinkus / tree-sitter-swift

A tree-sitter grammar for the Swift programming language.
MIT License
137 stars 34 forks source link

Add parsing support for freestanding macros #438

Open ketchupfriend opened 2 weeks ago

ketchupfriend commented 2 weeks ago

Macros were added in Swift 5.9 https://www.swift.org/blog/swift-5.9-released/#language-and-standard-library, and include:

Attached macros look the same as attributes, so they already get some highlighting. Freestanding macros don't seem to be supported yet, though. For example, on this sample file:

import Testing

#expect(true)

Has the following tree with InspectTree:

(source_file ; [0, 0] - [3, 0]
  (import_declaration ; [0, 0] - [0, 14]
    (identifier ; [0, 7] - [0, 14]
      (simple_identifier))) ; [0, 7] - [0, 14]
  (ERROR ; [2, 0] - [2, 7]
    (ERROR)) ; [2, 0] - [2, 7]
  (tuple_expression ; [2, 7] - [2, 13]
    value: (boolean_literal))) ; [2, 8] - [2, 12]

Expected result is that expect should be identified as a macro. This example comes from swift-testing

alex-pinkus commented 2 weeks ago

Thanks for the heads up!