From ed2ac1713326df6b926062efcc6109a20cdf7c37 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Aug 2018 14:24:22 +0300 Subject: smol_str to a crate --- crates/libsyntax2/src/yellow/green.rs | 17 ++++++++++++----- crates/libsyntax2/src/yellow/syntax.rs | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2/src/yellow') diff --git a/crates/libsyntax2/src/yellow/green.rs b/crates/libsyntax2/src/yellow/green.rs index f505b26d7..700f2704f 100644 --- a/crates/libsyntax2/src/yellow/green.rs +++ b/crates/libsyntax2/src/yellow/green.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use { - SyntaxKind, TextUnit, - smol_str::SmolStr, -}; + +use smol_str::SmolStr; + +use {SyntaxKind, TextUnit}; #[derive(Clone, Debug)] pub(crate) enum GreenNode { @@ -31,7 +31,7 @@ impl GreenNode { pub fn text_len(&self) -> TextUnit { match self { - GreenNode::Leaf { text, ..} => TextUnit::of_str(text.as_str()), + GreenNode::Leaf { text, .. } => TextUnit::of_str(text.as_str()), GreenNode::Branch(b) => b.text_len(), } } @@ -54,6 +54,13 @@ impl GreenNode { } } } + + pub fn leaf_text(&self) -> Option { + match self { + GreenNode::Leaf { text, .. } => Some(text.clone()), + GreenNode::Branch(_) => None, + } + } } #[derive(Clone, Debug)] diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index 00f76e51c..b264e008a 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs @@ -1,5 +1,7 @@ use std::{fmt, sync::Arc}; +use smol_str::SmolStr; + use { yellow::{RedNode, TreeRoot, SyntaxRoot, RedPtr}, SyntaxKind::{self, *}, @@ -116,6 +118,10 @@ impl SyntaxNode { self.first_child().is_none() } + pub fn leaf_text(&self) -> Option { + self.red().green().leaf_text() + } + fn red(&self) -> &RedNode { unsafe { self.red.get(&self.root) } } -- cgit v1.2.3