From 6be61101caeb6c46ac74cb9944106e18727b1e77 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 12 Jun 2021 22:33:07 +0530 Subject: accessor for token text --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index a1e085f..7385d66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,10 +61,17 @@ impl SynNode { (r.start().into(), r.end().into()).into() } - pub fn text(&self) -> String { + pub fn kind(&self) -> String { format!("{:?}", self.node.kind()) } + pub fn text(&self) -> String { + match &self.node { + NodeOrToken::Node(_) => "".into(), + NodeOrToken::Token(t) => format!("{:?}", t.text()), + } + } + pub fn from_str(s: &str) -> Result { FromStr::from_str(s) .map(|p: SynNode| JsValue::from(p)) -- cgit v1.2.3