From 9c10d31f0170deada74bfd98e549809369272228 Mon Sep 17 00:00:00 2001 From: romamik Date: Thu, 24 Oct 2024 11:36:24 +0300 Subject: [PATCH] Support callbacks returning Result --- src/internal.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/internal.rs b/src/internal.rs index e1a20de3..3a26f7c5 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -117,6 +117,25 @@ impl<'s, T: Logos<'s>> CallbackResult<'s, (), T> for Skip { } } +impl<'s, E, T: Logos<'s>> CallbackResult<'s, (), T> for Result +where + E: Into, +{ + #[inline] + fn construct(self, _: Constructor, lex: &mut Lexer<'s, T>) + where + Constructor: Fn(()) -> T, + { + match self { + Ok(_) => { + lex.trivia(); + T::lex(lex); + } + Err(err) => lex.set(Err(err.into())), + } + } +} + impl<'s, P, T: Logos<'s>> CallbackResult<'s, P, T> for Filter

{ #[inline] fn construct(self, c: Constructor, lex: &mut Lexer<'s, T>)