use crate::error::TapeResult; use crate::input_reader::InputReader; use std::any::{Any, TypeId}; use std::future::Future; use std::pin::Pin; use std::sync::Arc; pub type TokenCheckerFn = Arc< dyn for<'a> Fn( &'a mut InputReader, ) -> Pin>> + Send + 'a>> + Send + Sync, >; pub struct Token { inner: Box, } impl Token { /// Constructs a new token pub fn new(inner: A) -> Self { Self { inner: Box::new(inner), } } /// Tries downcasting the value to a concrete type pub fn try_as(&self) -> Option<&T> { self.inner.downcast_ref::() } pub fn try_into(self) -> Option { match self.inner.downcast() { Ok(value) => Some(*value), Err(_) => None, } } /// Checks if the inner value is of a given concrete type pub fn is(&self) -> bool { self.inner.as_ref().type_id() == TypeId::of::() } } /// Parsed when no other matching token was found for the character pub struct UnknownToken(pub char); /// End Of File Token pub struct EOFToken;