From 081c16c77642a5c86ed72c5fbd11deccc2edd5d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 15:37:17 +0300 Subject: initial mod resolve --- crates/libsyntax2/src/ast/mod.rs | 9 +++++++++ crates/libsyntax2/src/yellow/syntax.rs | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index d53b12ab8..9b9200f99 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs @@ -118,3 +118,12 @@ impl ImplItem { (first, second) } } + +impl Module { + pub fn has_semi(&self) -> bool { + match self.syntax_ref().last_child() { + None => false, + Some(node) => node.kind() == SEMI, + } + } +} diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs index b264e008a..bb390751a 100644 --- a/crates/libsyntax2/src/yellow/syntax.rs +++ b/crates/libsyntax2/src/yellow/syntax.rs @@ -89,7 +89,15 @@ impl SyntaxNode { } pub fn first_child(&self) -> Option> { - self.children().next() + let red = self.red().get_child(0)?; + Some(SyntaxNode { root: self.root.clone(), red }) + } + + pub fn last_child(&self) -> Option> { + let n = self.red().n_children(); + let n = n.checked_sub(1)?; + let red = self.red().get_child(n)?; + Some(SyntaxNode { root: self.root.clone(), red }) } pub fn next_sibling(&self) -> Option> { -- cgit v1.2.3