From c15091291a83789a762b5dfd3307fdb34f41f607 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 16 Mar 2021 11:08:43 +0100 Subject: [PATCH] add Expression::original() My parser is storing an Expression and may have to retrieve the original string later when producing errors. --- src/expr/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/expr/mod.rs b/src/expr/mod.rs index 271056c..e747d8d 100644 --- a/src/expr/mod.rs +++ b/src/expr/mod.rs @@ -519,6 +519,21 @@ impl Expression { result_stack.pop().unwrap() } + + /// The original string which has been parsed to produce this ['Expression`]. + /// + /// ``` + /// use cfg_expr::Expression; + /// + /// assert_eq!( + /// Expression::parse("any()").unwrap().original(), + /// "any()" + /// ); + /// ``` + #[inline] + pub fn original(&self) -> &str { + &self.original + } } /// [`PartialEq`] will do a **syntactical** comparaison, so will just check if both