Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions crates/ruff_python_ast/ast.toml
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,48 @@ InterpolatedStringLiteralElement = { variant = "Literal" }
[Pattern]
doc = "See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern)"

[Pattern.nodes]
PatternMatchValue = {}
PatternMatchSingleton = {}
PatternMatchSequence = {}
PatternMatchMapping = {}
PatternMatchClass = {}
PatternMatchStar = {}
PatternMatchAs = {}
PatternMatchOr = {}
[Pattern.nodes.PatternMatchValue]
doc = "See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue)"
fields = [{ name = "value", type = "Box<Expr>" }]

[Pattern.nodes.PatternMatchSingleton]
doc = "See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton)"
fields = [{ name = "value", type = "Singleton" }]

[Pattern.nodes.PatternMatchSequence]
doc = "See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence)"
fields = [{ name = "patterns", type = "Pattern*" }]

[Pattern.nodes.PatternMatchMapping]
doc = "See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping)"
fields = [
{ name = "keys", type = "Expr*" },
{ name = "patterns", type = "Pattern*" },
{ name = "rest", type = "Identifier?" },
]
custom_source_order = true

[Pattern.nodes.PatternMatchClass]
doc = "See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass)"
fields = [
{ name = "cls", type = "Box<Expr>" },
{ name = "arguments", type = "PatternArguments" },
]

[Pattern.nodes.PatternMatchStar]
doc = "See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar)"
fields = [{ name = "name", type = "Identifier?" }]

[Pattern.nodes.PatternMatchAs]
doc = "See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs)"
fields = [
{ name = "pattern", type = "Box<Pattern>?" },
{ name = "name", type = "Identifier?" },
]

[Pattern.nodes.PatternMatchOr]
doc = "See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr)"
fields = [{ name = "patterns", type = "Pattern*" }]

[TypeParam]
doc = "See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)"
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_python_ast/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"WithItem",
"MatchCase",
"Alias",
"Singleton",
"PatternArguments",
}


Expand Down
193 changes: 193 additions & 0 deletions crates/ruff_python_ast/src/generated.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 0 additions & 114 deletions crates/ruff_python_ast/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,50 +235,6 @@ impl ast::ExceptHandlerExceptHandler {
}
}

impl ast::PatternMatchValue {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchValue {
value,
range: _,
node_index: _,
} = self;
visitor.visit_expr(value);
}
}

impl ast::PatternMatchSingleton {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchSingleton {
value,
range: _,
node_index: _,
} = self;
visitor.visit_singleton(value);
}
}

impl ast::PatternMatchSequence {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchSequence {
patterns,
range: _,
node_index: _,
} = self;
for pattern in patterns {
visitor.visit_pattern(pattern);
}
}
}

impl ast::PatternMatchMapping {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
Expand Down Expand Up @@ -311,76 +267,6 @@ impl ast::PatternMatchMapping {
}
}

impl ast::PatternMatchClass {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchClass {
cls,
arguments: parameters,
range: _,
node_index: _,
} = self;
visitor.visit_expr(cls);
visitor.visit_pattern_arguments(parameters);
}
}

impl ast::PatternMatchStar {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchStar {
range: _,
node_index: _,
name,
} = self;

if let Some(name) = name {
visitor.visit_identifier(name);
}
}
}

impl ast::PatternMatchAs {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchAs {
pattern,
range: _,
node_index: _,
name,
} = self;
if let Some(pattern) = pattern {
visitor.visit_pattern(pattern);
}

if let Some(name) = name {
visitor.visit_identifier(name);
}
}
}

impl ast::PatternMatchOr {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
V: SourceOrderVisitor<'a> + ?Sized,
{
let ast::PatternMatchOr {
patterns,
range: _,
node_index: _,
} = self;
for pattern in patterns {
visitor.visit_pattern(pattern);
}
}
}

impl ast::PatternArguments {
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
where
Expand Down
Loading