// © 2023 John Breaux //! A [Directive] issues commands directly to the [Tokenizer](crate::Tokenizer) and //! [Linker](crate::Linker) use super::*; use crate::hash::FromHash; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Directive(pub Hash, pub String); impl Directive { fn str(mut self, s: S) -> Self { self.1 = s.to_string(); self } } impl From for Directive { fn from(value: Hash) -> Self { Self(value, String::new()) } } impl Parsable for Directive { fn parse<'text, T>(_p: &Parser, stream: &mut T) -> Result where T: TokenStream<'text> { // expect a directive let d = stream.expect(Type::Directive)?; // send the directive to the listener Ok(Self::from_hash(d.lexeme()).str(d.lexeme())) } } impl Display for Directive { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.1) } }