tree-sitter-swift icon indicating copy to clipboard operation
tree-sitter-swift copied to clipboard

Custom operators are obtuse and restrictive

Open alex-pinkus opened this issue 4 years ago • 5 comments

Currently, a custom operator must match one of five weird regexes that have subtle differences and are each of dubious necessity. There are many legitimate character combinations that should be legal, but are not, including anything using advanced unicode (related: unicode identifiers bug).

What this really points to is that custom operators should just be defined as externals, where we can define the rules in scanner.c and make it look something like what the official grammar says it should be.

alex-pinkus avatar Aug 28 '21 18:08 alex-pinkus

The biggest impact I'm aware of here is that the <*> operator from Commandant isn't legal, which causes a bunch of failures in Carthage.

alex-pinkus avatar Oct 16 '21 20:10 alex-pinkus

So it should follow the "Grammar of operators" from https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html? If so, from what I see, regexes will suffice

resolritter avatar Apr 06 '22 04:04 resolritter

It should end up more or less equivalent to that, but there’s some special casing required for cases like the ones in #41, where an operator ending in a < symbol conflicts with the start of a generic type argument.

alex-pinkus avatar Apr 06 '22 13:04 alex-pinkus

Unfinished PR at https://github.com/alex-pinkus/tree-sitter-swift/pull/151

resolritter avatar Apr 24 '22 18:04 resolritter

For posterity: the top-repo error here currently is at firefox-ios/shared/Functions.swift caused by:

infix operator •

alex-pinkus avatar Aug 28 '22 20:08 alex-pinkus