---
source: crates/bullion/language/syntax/macro/src/ast/tests.rs
expression: "use bullion_syntax_macro::ast::tests::callable"
snapshot_kind: text
---
Source: >
  #[bullion_syntax(AST)]
  pub struct Callable {
      path: NodeId<crate::ty::Path, crate::symbol::Ident>,
      args: Vec<crate::callable::Argument>,
      expr: Option<NodeId<crate::expression::Inline>>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct Callable {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: bullion_syntax_concrete::CstNodeId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) path: crate::NodeId,
      pub(crate) args: Vec<crate::callable::Argument>,
      pub(crate) expr: Option<crate::NodeId>,
  }
  impl Callable {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> bullion_syntax_concrete::CstNodeId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod callable_field {
      #[derive(Debug)]
      pub enum Path<'ast> {
          TyPath(&'ast crate::ty::Path),
          SymbolIdent(&'ast crate::symbol::Ident),
          Error,
      }
      impl<'ast> Path<'ast> {
          pub fn validate(&self, ast: &'ast crate::AST) -> bullion_error::Result<()> {
              match self {
                  Self::Error => Err(bullion_error::BLC2204()),
                  _ => Ok(()),
              }
          }
          pub fn from_node(node: &'ast crate::Node) -> Option<Path<'ast>> {
              Some(Self::from(node))
          }
      }
      impl<'ast> From<&'ast crate::Node> for Path<'ast> {
          fn from(n: &'ast crate::Node) -> Self {
              match n {
                  crate::Node::TyPath(val) => Path::TyPath(val),
                  crate::Node::SymbolIdent(val) => Path::SymbolIdent(val),
                  _ => Path::Error,
              }
          }
      }
      impl<'ast> From<&'ast crate::ty::Path> for Path<'ast> {
          fn from(v: &'ast crate::ty::Path) -> Self {
              Self::TyPath(v)
          }
      }
      impl<'ast> From<&'ast crate::symbol::Ident> for Path<'ast> {
          fn from(v: &'ast crate::symbol::Ident) -> Self {
              Self::SymbolIdent(v)
          }
      }
  }
  #[allow(unused)]
  impl Callable {
      ///Returns the `path` field
      pub fn get_path<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<callable_field::Path<'ast>> {
          {
              let path = &self.path;
              ast.node(*path).and_then(|node| callable_field::Path::from_node(node))
          }
      }
      ///Returns the `args` field
      pub fn get_args<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Vec<crate::callable::Argument> {
          {
              let args = &self.args;
              ast.node(*args)
          }
      }
      ///Returns the NodeIds for the `args` field
      pub fn get_args_ids<'ast>(&self, ast: &'ast crate::AST) -> Vec<crate::NodeId> {
          {
              let args = &self.args;
              args.clone()
          }
      }
      ///Returns the `expr` field
      pub fn get_expr<'ast>(
          &self,
          ast: &'ast crate::AST,
      ) -> Option<&'ast crate::expression::Inline> {
          {
              if let Some(ref expr) = self.expr {
                  ast.node(*expr)
                      .and_then(|node| crate::expression::Inline::from_node(node))
              } else {
                  None
              }
          }
      }
      ///Returns the NodeId for the `expr` field
      pub fn get_expr_id<'ast>(&self, ast: &'ast crate::AST) -> Option<crate::NodeId> {
          { if let Some(ref expr) = self.expr { Some(*expr) } else { None } }
      }
  }
  #[allow(unused)]
  impl<'ast> Callable {
      pub fn validate(&self, ast: &'ast crate::AST) -> bullion_error::Result<()> {
          self.get_path(ast).unwrap().validate(ast).unwrap();
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for Callable {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", & module_path!() .replace("bullion_syntax_abstract::", ""),
                      "Callable"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for Callable {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", & module_path!() .replace("bullion_syntax_abstract::", ""),
                      "Callable"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for Callable {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  &module_path!().replace("bullion_syntax_abstract::", ""),
                  &"Callable",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for Callable {
      fn node_with_state(
          &self,
          b: &mut bluegum::Builder,
          state: &crate::Printer<'tokens>,
      ) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
              &crate::style_title(
                  &module_path!().replace("bullion_syntax_abstract::", ""),
                  &"Callable",
              ),
          );
          if let Some(cst_node) = state.get_syntax(self.syntax) {
              let span = cst_node.span();
              if let Some(span_data) = span.data(state.get_span_cache()) {
                  b.debug(
                      "span",
                      format!("{}..{}", span_data.start, span_data.start + span_data.len),
                  );
              }
          }
          if let Some(meta) = self.meta {
              b.add_node_with_state(state, &"meta".blue().italic().to_string(), &meta);
          }
          {
              {
                  let path = &self.path;
                  b.add_node_with_state(state, stringify!(path), path);
              };
              {
                  let args = &self.args;
                  b.add_nodes_of_builders(
                      stringify!(args),
                      args
                          .iter()
                          .map(|child| bluegum::Builder::render_with_state(child, state))
                          .collect::<Vec<bluegum::Builder>>(),
                  );
              };
              {
                  if let Some(ref expr) = self.expr {
                      b.add_node_with_state(state, stringify!(expr), expr);
                  }
              };
          };
      }
  }
