From 5e06d8e7ca9f2585c1b75ee664fcb66ea99d544d Mon Sep 17 00:00:00 2001 From: mgros Date: Tue, 11 Aug 2026 03:24:51 +0200 Subject: [PATCH] use strum_macros::Display for Token --- src/infer_intent.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/infer_intent.rs b/src/infer_intent.rs index 3c15a787..4be82c60 100644 --- a/src/infer_intent.rs +++ b/src/infer_intent.rs @@ -17,6 +17,7 @@ use crate::pretty_print::mml_to_string; use crate::xpath_functions::is_leaf; use regex::Regex; use phf::phf_set; +use strum_macros::Display; #[allow(unused_imports)] use log::{debug, error, warn}; @@ -284,31 +285,21 @@ static TERMINALS_AS_U8: [u8; 3] = *b"(,)"; // static TERMINALS: [char; 3] = ['(', ',',')']; // 'i -- "i" for the lifetime of the INTENT_ATTR string -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Display)] enum Token<'i> { + #[strum(to_string = "Terminal('{0}')")] Terminal(&'i str), // "(", ",", ")" + #[strum(to_string = "Property({0})")] Property(&'i str), + #[strum(to_string = "ArgRef({0})")] ArgRef(&'i str), + #[strum(to_string = "Literal({0})")] ConceptOrLiteral(&'i str), + #[strum(to_string = "Number({0})")] Number(&'i str), None, // out of characters } -impl fmt::Display for Token<'_> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - return write!(f, "{}", - match self { - Token::Terminal(str) => format!("Terminal('{str}')"), - Token::Property(str) => format!("Property({str})"), - Token::ArgRef(str) => format!("ArgRef({str})"), - Token::ConceptOrLiteral(str) => format!("Literal({str})"), - Token::Number(str) => format!("Number({str})"), - Token::None => "None".to_string(), - } - ); - } -} - impl Token<'_> { fn is_terminal(&self, terminal: &str) -> bool { if let Token::Terminal(value) = *self {