Skip to main content

oxilean_parse/macro_parser/
macrotoken_traits.rs

1//! # MacroToken - Trait Implementations
2//!
3//! This module contains trait implementations for `MacroToken`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::MacroToken;
12use std::fmt;
13
14impl fmt::Display for MacroToken {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            MacroToken::Literal(tk) => write!(f, "{}", tk),
18            MacroToken::Var(name) => write!(f, "${}", name),
19            MacroToken::Repeat(toks) => {
20                write!(f, "$(")?;
21                for t in toks {
22                    write!(f, "{}", t)?;
23                }
24                write!(f, ")*")
25            }
26            MacroToken::Optional(toks) => {
27                write!(f, "$(")?;
28                for t in toks {
29                    write!(f, "{}", t)?;
30                }
31                write!(f, ")?")
32            }
33            MacroToken::Quote(toks) => {
34                write!(f, "`(")?;
35                for t in toks {
36                    write!(f, "{}", t)?;
37                }
38                write!(f, ")")
39            }
40            MacroToken::Antiquote(name) => write!(f, "${}", name),
41            MacroToken::SpliceArray(name) => write!(f, "$[{}]*", name),
42        }
43    }
44}