From d23b8af60d2ed8b27858f3d47040bbcb9fe4a674 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 3 May 2025 17:42:56 -0700 Subject: [PATCH] ast: More migration from type to kind --- src/builtins/fish_indent.rs | 14 +++++++------- src/tests/parser.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index 2a722ee1a..6f56f44b8 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -15,7 +15,7 @@ use libc::LC_ALL; use super::prelude::*; -use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal, Type}; +use crate::ast::{self, Ast, Kind, Leaf, Node, NodeVisitor, SourceRangeList, Traversal}; use crate::common::{ str2wcstring, unescape_string, wcs2string, UnescapeFlags, UnescapeStringStyle, PROGRAM_NAME, }; @@ -381,14 +381,14 @@ fn indent(&self, index: usize) -> usize { // Return gap text flags for the gap text that comes *before* a given node type. fn gap_text_flags_before_node(&self, node: &dyn Node) -> GapFlags { let mut result = GapFlags::default(); - match node.typ() { + match node.kind() { // Allow escaped newlines before leaf nodes that can be part of a long command. - Type::argument | Type::redirection | Type::variable_assignment => { + Kind::Argument(_) | Kind::Redirection(_) | Kind::VariableAssignment(_) => { result.allow_escaped_newlines = true } - Type::token_base => { + Kind::Token(token) => { // Allow escaped newlines before && and ||, and also pipes. - match node.as_token().unwrap().token_type() { + match token.token_type() { ParseTokenType::andand | ParseTokenType::oror | ParseTokenType::pipe => { result.allow_escaped_newlines = true; } @@ -396,11 +396,11 @@ fn gap_text_flags_before_node(&self, node: &dyn Node) -> GapFlags { // Allow escaped newlines before commands that follow a variable assignment // since both can be long (#7955). let p = self.traversal.parent(node); - if p.typ() != Type::decorated_statement { + if !matches!(p.kind(), Kind::DecoratedStatement(_)) { return result; } let p = self.traversal.parent(p); - assert_eq!(p.typ(), Type::statement); + assert!(matches!(p.kind(), Kind::Statement(_))); let p = self.traversal.parent(p); if let Kind::JobPipeline(job) = p.kind() { if !job.variables.is_empty() { diff --git a/src/tests/parser.rs b/src/tests/parser.rs index 94efe8cb7..981b01144 100644 --- a/src/tests/parser.rs +++ b/src/tests/parser.rs @@ -956,7 +956,7 @@ fn test_traversal_skip_children_panics() { let ast = ast::parse(L!("true;"), ParseTreeFlags::empty(), None); let mut traversal = ast.walk(); while let Some(node) = traversal.next() { - if node.typ() == ast::Type::decorated_statement { + if matches!(node.kind(), ast::Kind::DecoratedStatement(_)) { // Should panic as we can only skip the current node. traversal.skip_children(ast.top()); }