From 2467cd6272c13b618ad53c5dadff5b8c8e7885bf Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 4 Aug 2020 13:48:07 +0200 Subject: =?UTF-8?q?Refactor=20function=20parsing=20=E2=99=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/test.rs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/syntax/test.rs') diff --git a/src/syntax/test.rs b/src/syntax/test.rs index 9faa7f23..7dec20e3 100644 --- a/src/syntax/test.rs +++ b/src/syntax/test.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use crate::func::parse_maybe_body; +use crate::func::prelude::*; use super::decoration::Decoration; use super::expr::{Expr, Ident, NamedTuple, Object, Pair, Tuple}; use super::parsing::{FuncArg, FuncArgs, FuncHeader}; @@ -58,26 +58,26 @@ macro_rules! span_item { }; } -function! { - /// Most functions in the tests are parsed into the debug function for easy - /// inspection of arguments and body. - #[derive(Debug, Clone, PartialEq)] - pub struct DebugFn { - pub header: FuncHeader, - pub body: Option, - } +pub fn debug_func(call: FuncCall, state: &ParseState) -> Pass { + let mut f = Feedback::new(); + let node = DebugNode { + header: call.header, + body: parse_body_maybe(call.body, state, &mut f), + }; + Pass::node(node, f) +} - parse(header, body, state, f) { - let cloned = header.clone(); - header.args.pos.0.clear(); - header.args.key.0.clear(); - Self { - header: cloned, - body: parse_maybe_body(body, state, f), - } - } +#[derive(Debug, Clone, PartialEq)] +pub struct DebugNode { + pub header: FuncHeader, + pub body: Option, +} - layout(self, ctx, f) { vec![] } +#[async_trait(?Send)] +impl Layout for DebugNode { + async fn layout<'a>(&'a self, _: LayoutContext<'_>) -> Pass> { + unimplemented!() + } } /// Compares elements by only looking at values and ignoring spans. @@ -87,8 +87,8 @@ pub trait SpanlessEq { impl SpanlessEq for SyntaxNode { fn spanless_eq(&self, other: &Self) -> bool { - fn downcast<'a>(func: &'a (dyn DynamicNode + 'static)) -> &'a DebugFn { - func.downcast::().expect("not a debug fn") + fn downcast<'a>(func: &'a (dyn DynamicNode + 'static)) -> &'a DebugNode { + func.downcast::().expect("not a debug node") } match (self, other) { @@ -101,7 +101,7 @@ impl SpanlessEq for SyntaxNode { } } -impl SpanlessEq for DebugFn { +impl SpanlessEq for DebugNode { fn spanless_eq(&self, other: &Self) -> bool { self.header.spanless_eq(&other.header) && self.body.spanless_eq(&other.body) -- cgit v1.2.3