mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Add definitions for match statement (#13147)
## Summary This PR adds definition for match patterns. ## Test Plan Update the existing test case for match statement symbols to verify that the definitions are added as well.
This commit is contained in:
parent
9986397d56
commit
17eb65b26f
6 changed files with 189 additions and 16 deletions
|
@ -1,12 +1,18 @@
|
|||
use ruff_python_ast::{AnyNodeRef, NodeKind};
|
||||
use ruff_python_ast::{AnyNodeRef, Identifier, NodeKind};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(super) enum Kind {
|
||||
Node(NodeKind),
|
||||
Identifier,
|
||||
}
|
||||
|
||||
/// Compact key for a node for use in a hash map.
|
||||
///
|
||||
/// Compares two nodes by their kind and text range.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(super) struct NodeKey {
|
||||
kind: NodeKind,
|
||||
kind: Kind,
|
||||
range: TextRange,
|
||||
}
|
||||
|
||||
|
@ -17,8 +23,15 @@ impl NodeKey {
|
|||
{
|
||||
let node = node.into();
|
||||
NodeKey {
|
||||
kind: node.kind(),
|
||||
kind: Kind::Node(node.kind()),
|
||||
range: node.range(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn from_identifier(identifier: &Identifier) -> Self {
|
||||
NodeKey {
|
||||
kind: Kind::Identifier,
|
||||
range: identifier.range(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue