From 311dbb854536dd526cdbcadc6d270f9a37e4b816 Mon Sep 17 00:00:00 2001 From: Ekaterina Babshukova Date: Sat, 5 Oct 2019 17:48:31 +0300 Subject: remove `visitor` module --- crates/ra_syntax/src/algo/visit.rs | 112 ------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 crates/ra_syntax/src/algo/visit.rs (limited to 'crates/ra_syntax/src/algo/visit.rs') diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs deleted file mode 100644 index 4df275ba4..000000000 --- a/crates/ra_syntax/src/algo/visit.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! FIXME: write short doc here - -use crate::{AstNode, SyntaxNode}; - -use std::marker::PhantomData; - -pub fn visitor<'a, T>() -> impl Visitor<'a, Output = T> { - EmptyVisitor { ph: PhantomData } -} - -pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> { - EmptyVisitorCtx { ph: PhantomData, ctx } -} - -pub trait Visitor<'a>: Sized { - type Output; - fn accept(self, node: &'a SyntaxNode) -> Option; - fn visit(self, f: F) -> Vis - where - N: AstNode + 'a, - F: FnOnce(N) -> Self::Output, - { - Vis { inner: self, f, ph: PhantomData } - } -} - -pub trait VisitorCtx<'a>: Sized { - type Output; - type Ctx; - fn accept(self, node: &'a SyntaxNode) -> Result; - fn visit(self, f: F) -> VisCtx - where - N: AstNode + 'a, - F: FnOnce(N, Self::Ctx) -> Self::Output, - { - VisCtx { inner: self, f, ph: PhantomData } - } -} - -#[derive(Debug)] -struct EmptyVisitor { - ph: PhantomData T>, -} - -impl<'a, T> Visitor<'a> for EmptyVisitor { - type Output = T; - - fn accept(self, _node: &'a SyntaxNode) -> Option { - None - } -} - -#[derive(Debug)] -struct EmptyVisitorCtx { - ctx: C, - ph: PhantomData T>, -} - -impl<'a, T, C> VisitorCtx<'a> for EmptyVisitorCtx { - type Output = T; - type Ctx = C; - - fn accept(self, _node: &'a SyntaxNode) -> Result { - Err(self.ctx) - } -} - -#[derive(Debug)] -pub struct Vis { - inner: V, - f: F, - ph: PhantomData, -} - -impl<'a, V, N, F> Visitor<'a> for Vis -where - V: Visitor<'a>, - N: AstNode + 'a, - F: FnOnce(N) -> >::Output, -{ - type Output = >::Output; - - fn accept(self, node: &'a SyntaxNode) -> Option { - let Vis { inner, f, .. } = self; - inner.accept(node).or_else(|| N::cast(node.clone()).map(f)) - } -} - -#[derive(Debug)] -pub struct VisCtx { - inner: V, - f: F, - ph: PhantomData, -} - -impl<'a, V, N, F> VisitorCtx<'a> for VisCtx -where - V: VisitorCtx<'a>, - N: AstNode + 'a, - F: FnOnce(N, >::Ctx) -> >::Output, -{ - type Output = >::Output; - type Ctx = >::Ctx; - - fn accept(self, node: &'a SyntaxNode) -> Result { - let VisCtx { inner, f, .. } = self; - inner.accept(node).or_else(|ctx| match N::cast(node.clone()) { - None => Err(ctx), - Some(node) => Ok(f(node, ctx)), - }) - } -} -- cgit v1.2.3