---
source: crates/laburnum-syntax-macro/src/tests/cst_tests.rs
expression: "use laburnum_syntax_macro::tests::cst_tests::test_cst_complex_real_world_example"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(CST)]
  pub struct FunctionCST {
      span: Span,
      visibility_token: Option<NodeId<crate::Token>>,
      fn_keyword: NodeId<crate::Token>,
      name: NodeId<crate::Identifier>,
      generic_params: Option<NodeId<crate::GenericParams>>,
      lparen: NodeId<crate::Token>,
      params: Vec<crate::Param>,
      rparen: NodeId<crate::Token>,
      return_type: Option<NodeId<crate::ReturnType>>,
      body: NodeId<crate::Block>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct FunctionCST {
      pub span: laburnum::Span,
      pub visibility_token: Option<NodeId<crate::Token>>,
      pub fn_keyword: NodeId<crate::Token>,
      pub name: NodeId<crate::Identifier>,
      pub generic_params: Option<NodeId<crate::GenericParams>>,
      pub lparen: NodeId<crate::Token>,
      pub params: Vec<crate::Param>,
      pub rparen: NodeId<crate::Token>,
      pub return_type: Option<NodeId<crate::ReturnType>>,
      pub body: NodeId<crate::Block>,
  }
  impl FunctionCST {
      pub fn span(&self) -> laburnum::Span {
          self.span
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for FunctionCST {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name = stringify!(FunctionCST);
                      let __seg_norm : std::string::String = __last_seg.chars().filter(| c
                      | * c != '_').collect(); let __name_norm : std::string::String =
                      __name.chars().filter(| c | * c != '_').collect(); if __seg_norm
                      .eq_ignore_ascii_case(& __name_norm) { & __stripped[..__last_sep] }
                      else { __stripped } } else { __stripped } }, stringify!(FunctionCST)
                  ),
              )
              .field("span", &self.span)
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for FunctionCST {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name = stringify!(FunctionCST);
                      let __seg_norm : std::string::String = __last_seg.chars().filter(| c
                      | * c != '_').collect(); let __name_norm : std::string::String =
                      __name.chars().filter(| c | * c != '_').collect(); if __seg_norm
                      .eq_ignore_ascii_case(& __name_norm) { & __stripped[..__last_sep] }
                      else { __stripped } } else { __stripped } }, stringify!(FunctionCST)
                  ),
              )
              .field("span", &self.span)
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for FunctionCST {
      fn node(&self, b: &mut bluegum::Builder) {
          use owo_colors::OwoColorize;
          b.name(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name = stringify!(FunctionCST);
                      let __seg_norm : std::string::String = __last_seg.chars().filter(| c
                      | * c != '_').collect(); let __name_norm : std::string::String =
                      __name.chars().filter(| c | * c != '_').collect(); if __seg_norm
                      .eq_ignore_ascii_case(& __name_norm) { & __stripped[..__last_sep] }
                      else { __stripped } } else { __stripped } }, stringify!(FunctionCST)
                  ),
              )
              .debug("span", self.span);
      }
  }
  #[allow(unused)]
  impl bluegum::BluegumWithState<crate::Printer<'_>> for FunctionCST {
      fn node_with_state(&self, b: &mut bluegum::Builder, state: &crate::Printer<'_>) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); let __stripped = __mp
                      .find("::").map(| i | & __mp[i + 2..]).unwrap_or(__mp); if let
                      Some(__last_sep) = __stripped.rfind("::") { let __last_seg = &
                      __stripped[__last_sep + 2..]; let __name = stringify!(FunctionCST);
                      let __seg_norm : std::string::String = __last_seg.chars().filter(| c
                      | * c != '_').collect(); let __name_norm : std::string::String =
                      __name.chars().filter(| c | * c != '_').collect(); if __seg_norm
                      .eq_ignore_ascii_case(& __name_norm) { & __stripped[..__last_sep] }
                      else { __stripped } } else { __stripped } }, stringify!(FunctionCST)
                  ),
              )
              .debug("span", self.span);
          {
              if let Some(ref visibility_token) = self.visibility_token {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", visibility_token);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(visibility_token), t);
              }
              let fn_keyword = &self.fn_keyword;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", fn_keyword);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(fn_keyword), t);
              let name = &self.name;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", name);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(name), t);
              if let Some(ref generic_params) = self.generic_params {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", generic_params);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(generic_params), t);
              }
              let lparen = &self.lparen;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", lparen);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(lparen), t);
              let params = &self.params;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", params);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(params), t);
              let rparen = &self.rparen;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", rparen);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(rparen), t);
              if let Some(ref return_type) = self.return_type {
                  let mut t = bluegum::Builder::new();
                  t.name("Literal");
                  let s = format!("{}", return_type);
                  if s.width() > 80 {
                      t.alt(format!("{:.80}...", s).bright_green());
                  } else {
                      t.alt(format!("{:.80}", s).bright_green());
                  };
                  b.add_named_builder(stringify!(return_type), t);
              }
              let body = &self.body;
              let mut t = bluegum::Builder::new();
              t.name("Literal");
              let s = format!("{}", body);
              if s.width() > 80 {
                  t.alt(format!("{:.80}...", s).bright_green());
              } else {
                  t.alt(format!("{:.80}", s).bright_green());
              };
              b.add_named_builder(stringify!(body), t);
          };
      }
  }
