Skip to content

Commit

Permalink
Minorly improve custom operator handling
Browse files Browse the repository at this point in the history
We still need to move the custom operator logic to the scanner, but
that's a lot of complexity, and it's still unclear how to do that
without a lot of breakage. Instead of doing that now, we just special
case handling of `<` (which is what was tripping up a lot of Carthage
files).

With this change, #5 will no longer be a top-repos-error, even though it
will still be a valid bug.
  • Loading branch information
alex-pinkus committed Nov 7, 2021
1 parent cb72dbe commit 0e9146f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 18 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ module.exports = grammar({
// After a `{` in a function or switch context, it's ambigous whether we're starting a set of local statements or
// applying some modifiers to a capture or pattern.
[$.modifiers],

// Custom operators get weird special handling for `<` characters in silly stuff like `func =<<<<T>(...)`
[$.custom_operator],
[$._prefix_unary_operator, $._referenceable_operator],
],

extras: ($) => [
Expand Down Expand Up @@ -500,7 +504,7 @@ module.exports = grammar({
bitwise_operation: ($) =>
prec.left(seq($._expression, $._bitwise_binary_operator, $._expression)),

custom_operator: ($) => CUSTOM_OPERATORS,
custom_operator: ($) => seq(CUSTOM_OPERATORS, optional("<")),

// Suffixes

Expand Down Expand Up @@ -797,7 +801,19 @@ module.exports = grammar({
_as_operator: ($) => choice("as", "as?", "as!"),

_prefix_unary_operator: ($) =>
prec.right(choice("++", "--", "-", "+", "!", "&", "~", $._dot_operator)),
prec.right(
choice(
"++",
"--",
"-",
"+",
"!",
"&",
"~",
$._dot_operator,
$.custom_operator
)
),

_bitwise_binary_operator: ($) => choice("&", "|", "^", "<<", ">>"),

Expand Down
6 changes: 0 additions & 6 deletions script-data/known_failures.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
Carthage/Source/carthage/Outdated.swift
Carthage/Source/carthage/Archive.swift
Carthage/Source/carthage/Update.swift
Carthage/Source/carthage/Extensions.swift
Carthage/Source/carthage/Fetch.swift
Carthage/Source/carthage/Build.swift
Carthage/Source/carthage/Checkout.swift
Carthage/Source/carthage/Formatting.swift
Carthage/Source/CarthageKit/Archive.swift
Carthage/Source/CarthageKit/Project.swift
Carthage/Source/CarthageKit/GitURL.swift
Expand Down

0 comments on commit 0e9146f

Please sign in to comment.