Skip to main content

oxilean_parse/macro_parser/
syntaxitem_traits.rs

1//! # SyntaxItem - Trait Implementations
2//!
3//! This module contains trait implementations for `SyntaxItem`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Display`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use std::fmt;
12
13use super::types::SyntaxItem;
14
15impl fmt::Display for SyntaxItem {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            SyntaxItem::Token(tk) => write!(f, "{}", tk),
19            SyntaxItem::Category(cat) => write!(f, "{}", cat),
20            SyntaxItem::Optional(item) => write!(f, "({})?", item),
21            SyntaxItem::Many(item) => write!(f, "({})*", item),
22            SyntaxItem::Group(items) => {
23                write!(f, "(")?;
24                for (i, item) in items.iter().enumerate() {
25                    if i > 0 {
26                        write!(f, " ")?;
27                    }
28                    write!(f, "{}", item)?;
29                }
30                write!(f, ")")
31            }
32        }
33    }
34}