From 767772fbea40a29fcd4bd7131334bdad818a8034 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 26 Apr 2023 11:36:18 -0600 Subject: [PATCH] Revert into_node and node() changes --- compiler/ast/src/ast_gen.rs | 18 ++++++++++++++++++ compiler/parser/python.lalrpop | 4 ++-- compiler/parser/src/function.rs | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/compiler/ast/src/ast_gen.rs b/compiler/ast/src/ast_gen.rs index d5fd6ece7d0..5370a5ab19f 100644 --- a/compiler/ast/src/ast_gen.rs +++ b/compiler/ast/src/ast_gen.rs @@ -63,6 +63,24 @@ impl Located { } } +impl std::ops::Deref for Located { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.node + } + + pub const fn start(&self) -> Location { + self.location + } + + /// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if + /// [`end_location`](Located::end_location) is `None`. + pub fn end(&self) -> Location { + self.end_location.unwrap_or(self.location) + } +} + impl std::ops::Deref for Located { type Target = T; diff --git a/compiler/parser/python.lalrpop b/compiler/parser/python.lalrpop index 0b18f5c2e37..9f038536613 100644 --- a/compiler/parser/python.lalrpop +++ b/compiler/parser/python.lalrpop @@ -519,7 +519,7 @@ ClosedPattern: ast::Pattern = { SequencePattern: ast::PatternKind = { // A single-item tuple is a special case: it's a group pattern, _not_ a sequence pattern. - "(" ")" => pattern.into_node(), + "(" ")" => pattern.node, "(" ")" => ast::PatternKind::MatchSequence { patterns: vec![], }, @@ -1554,7 +1554,7 @@ Atom: ast::Expr = { }, "(" >> ",")?> )*> ")" =>? { if left.is_none() && right.is_empty() && trailing_comma.is_none() { - if matches!(mid.node(), ast::ExprKind::Starred { .. }) { + if matches!(mid.node, ast::ExprKind::Starred { .. }) { Err(LexicalError{ error: LexicalErrorType::OtherError("cannot use starred expression here".to_string()), location: mid.start(), diff --git a/compiler/parser/src/function.rs b/compiler/parser/src/function.rs index 1bb0016d508..ea66938a7d3 100644 --- a/compiler/parser/src/function.rs +++ b/compiler/parser/src/function.rs @@ -144,7 +144,7 @@ pub(crate) fn parse_args(func_args: Vec) -> Result bool { - matches!(exp.node(), ast::ExprKind::Starred { .. }) + matches!(exp.node, ast::ExprKind::Starred { .. }) } #[cfg(test)]