use core::marker::PhantomData;
use crate::utils::Spanned;
use super::*;
pub struct Silent<T: ?Sized, Lang: ?Sized = ()> {
_marker: PhantomData<T>,
_lang: PhantomData<Lang>,
}
impl<T: ?Sized, Lang: ?Sized> Silent<T, Lang> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new() -> Self {
Self {
_marker: PhantomData,
_lang: PhantomData,
}
}
}
impl<T: ?Sized, Lang: ?Sized> Default for Silent<T, Lang> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn default() -> Self {
Self {
_marker: PhantomData,
_lang: PhantomData,
}
}
}
impl<T: ?Sized, Lang: ?Sized> core::fmt::Debug for Silent<T, Lang> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Silent")
}
}
impl<T: ?Sized, Lang: ?Sized> Clone for Silent<T, Lang> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn clone(&self) -> Self {
*self
}
}
impl<T: ?Sized, Lang: ?Sized> Copy for Silent<T, Lang> {}
impl<'a, L, E, Lang: ?Sized> Emitter<'a, L, Lang> for Silent<E, Lang>
where
L: Lexer<'a>,
{
type Error = E;
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_lexer_error(
&mut self,
_: Spanned<<L::Token as Token<'a>>::Error, L::Span>,
) -> Result<(), Self::Error> {
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_error(&mut self, _: Spanned<Self::Error, L::Span>) -> Result<(), Self::Error> {
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unexpected_token(
&mut self,
_: UnexpectedToken<'a, L::Token, <L::Token as Token<'a>>::Kind, L::Span, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn rewind(&mut self, cursor: &Cursor<'a, '_, L>)
where
L: Lexer<'a>,
{
let _ = cursor;
}
}
impl<'a, O, L, E, Lang: ?Sized> RepeatedEmitter<'a, O, L, Lang> for Silent<E, Lang>
where
O: ?Sized,
L: Lexer<'a>,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_too_few(&mut self, _: TooFew<O, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_too_many(&mut self, _: TooMany<O, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_full_container(&mut self, _: FullContainer<O, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
}
impl<'a, L, Any, E, Lang: ?Sized> BatchEmitter<'a, L, Any, Lang> for Silent<E, Lang>
where
L: Lexer<'a>,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn create_batch(&mut self, _: <L>::Span, _: Message)
where
L: Lexer<'a>,
{
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn create_batch_with_error(
&mut self,
_: Message,
_: Spanned<Any, L::Span>,
) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_to_batch(&mut self, _: &<L>::Span, _: Spanned<Any, L::Span>) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_batch(&mut self, _: &<L>::Span) -> Result<(), Self::Error>
where
L: Lexer<'a>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn drop_batch(&mut self, _: &<L>::Span)
where
L: Lexer<'a>,
{
}
}
impl<'inp, L, O, Sep, E, Lang: ?Sized> SeparatedByEmitter<'inp, O, Sep, L, Lang> for Silent<E, Lang>
where
L: Lexer<'inp>,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_missing_separator(
&mut self,
_: MissingSeparatorOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_missing_element(
&mut self,
_: MissingSyntaxOf<'inp, O, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_missing_leading_separator(
&mut self,
_: MissingLeadingOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_missing_trailing_separator(
&mut self,
_: MissingTrailingOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unexpected_repeated_separator(
&mut self,
_: UnexpectedRepeatedOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unexpected_leading_separator(
&mut self,
_: UnexpectedLeadingOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unexpected_trailing_separator(
&mut self,
_: UnexpectedTrailingOf<'inp, Sep, L, Lang>,
) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
}
impl<'inp, L, E, Delim, Lang: ?Sized> DelimiterEmitter<'inp, Delim, L, Lang> for Silent<E, Lang>
where
L: Lexer<'inp>,
{
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unclosed(&mut self, _: Unclosed<Delim, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_unopened(&mut self, _: Unopened<Delim, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
#[cfg_attr(not(tarpaulin), inline(always))]
fn emit_undelimited(&mut self, _: Undelimited<Delim, L::Span, Lang>) -> Result<(), Self::Error>
where
L: Lexer<'inp>,
{
Ok(())
}
}
#[cfg(test)]
const _: () = {
use crate::lexer::{BlackHole, DummyLexer};
struct DummySep;
const fn assert_noop_batch_emitter<'a, L, Any, Error, E>()
where
L: Lexer<'a>,
E: BatchEmitter<'a, L, Any, Error = Error>,
{
}
const fn assert_noop_repeated_emitter<'a, L, Any, Error, E>()
where
L: Lexer<'a>,
E: RepeatedEmitter<'a, Any, L, Error = Error>,
{
}
const fn assert_noop_separated_by_emitter<'a, L, O, Sep, Error, E>()
where
L: Lexer<'a>,
E: SeparatedByEmitter<'a, O, Sep, L, Error = Error>,
{
}
assert_noop_batch_emitter::<'_, DummyLexer, (), (), Silent<()>>();
assert_noop_batch_emitter::<'_, DummyLexer, (), BlackHole, Silent<BlackHole>>();
assert_noop_repeated_emitter::<'_, DummyLexer, (), (), Silent<()>>();
assert_noop_separated_by_emitter::<'_, DummyLexer, (), DummySep, (), Silent<()>>();
};