Refactor unary expression parsing (#11088)

## Summary

This PR refactors unary expression parsing with the following changes:
* Ability to get `OperatorPrecedence` from a unary operator (`UnaryOp`)
* Implement methods on `TokenKind`
	* Add `as_unary_operator` which returns an `Option<UnaryOp>`
* Add `as_unary_arithmetic_operator` which returns an `Option<UnaryOp>`
(used for pattern parsing)
* Rename `is_unary` to `is_unary_arithmetic_operator` (used in the
linter)

resolves: #10752 

## Test Plan

Verify that the existing test cases pass, no ecosystem changes, run the
Python based fuzzer on 3000 random inputs and run it on dozens of
open-source repositories.
This commit is contained in:
Dhruv Manilawala 2024-04-23 10:25:02 +05:30 committed by GitHub
parent 7eba967e16
commit 38d2562f41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 125 additions and 85 deletions

View file

@ -186,7 +186,9 @@ pub(crate) fn missing_whitespace_around_operator(
);
NeedsSpace::from(!slash_in_func)
} else if kind.is_unary() || matches!(kind, TokenKind::Star | TokenKind::DoubleStar) {
} else if kind.is_unary_arithmetic_operator()
|| matches!(kind, TokenKind::Star | TokenKind::DoubleStar)
{
let is_binary = {
let prev_kind = prev_token.kind();