From 3355310d9de0e74db3fded5cf61ec7b67e251808 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 21 Oct 2023 17:48:14 -0400 Subject: [PATCH] Implement remove tool; Remove trash tool --- src/abstract_tree/tool.rs | 17 ++++++++--------- tree-sitter-dust/grammar.js | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/abstract_tree/tool.rs b/src/abstract_tree/tool.rs index 0a217e6..b81c8ee 100644 --- a/src/abstract_tree/tool.rs +++ b/src/abstract_tree/tool.rs @@ -26,7 +26,6 @@ pub enum Tool { Move(Vec), Read(Expression), Remove(Expression), - Trash(Expression), Write(Vec), // Format conversion @@ -132,12 +131,6 @@ impl AbstractTree for Tool { Tool::Remove(expression) } - "trash" => { - let expression_node = node.child(2).unwrap(); - let expression = Expression::from_syntax_node(source, expression_node)?; - - Tool::Trash(expression) - } "write" => { let expressions = parse_expressions(source, node)?; @@ -345,8 +338,14 @@ impl AbstractTree for Tool { Ok(content) } - Tool::Remove(_) => todo!(), - Tool::Trash(_) => todo!(), + Tool::Remove(expression) => { + let path_value = expression.run(source, context)?; + let path = PathBuf::from(path_value.as_string()?); + + remove_file(path)?; + + Ok(Value::Empty) + } Tool::Write(_) => todo!(), Tool::FromJson(_) => todo!(), Tool::ToJson(_) => todo!(), diff --git a/tree-sitter-dust/grammar.js b/tree-sitter-dust/grammar.js index a7dc9ed..2b9f406 100644 --- a/tree-sitter-dust/grammar.js +++ b/tree-sitter-dust/grammar.js @@ -276,7 +276,6 @@ module.exports = grammar({ 'move', 'read', 'remove', - 'trash', 'write', // Format conversion