laburnum-syntax-macro 0.1.1

Proc-macros for defining CST and AST node types in language frontends built with the laburnum LSP framework.
Documentation
---
source: crates/laburnum-syntax-macro/src/tests/mod.rs
expression: "use laburnum_syntax_macro::tests::test_macro_hygiene"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST)]
  pub struct HygieneTest {
      my_self: NodeId<crate::Type>,
      ast: NodeId<crate::AST>,
      node: NodeId<crate::Node>,
      field: Field<bool>,
      my_type: NodeId<crate::Type>,
      my_impl: Option<NodeId<crate::Type>>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct HygieneTest {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: crate::SyntaxId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) my_self: crate::NodeId,
      pub(crate) ast: crate::NodeId,
      pub(crate) node: crate::NodeId,
      pub(crate) field: bool,
      pub(crate) my_type: crate::NodeId,
      pub(crate) my_impl: Option<crate::NodeId>,
  }
  impl HygieneTest {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> crate::SyntaxId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod hygiene_test_field {}
  #[allow(unused)]
  impl HygieneTest {
      ///Returns the `my_self` field
      pub fn get_my_self<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              let my_self = &self.my_self;
              ast.node(*my_self).and_then(|node| crate::Type::from_node(node))
          }
      }
      ///Returns the NodeId for the `my_self` field
      pub fn get_my_self_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let my_self = &self.my_self;
              *my_self
          }
      }
      ///Returns the `ast` field
      pub fn get_ast<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::AST> {
          {
              let ast = &self.ast;
              ast.node(*ast).and_then(|node| crate::AST::from_node(node))
          }
      }
      ///Returns the NodeId for the `ast` field
      pub fn get_ast_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let ast = &self.ast;
              *ast
          }
      }
      ///Returns the `node` field
      pub fn get_node<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Node> {
          {
              let node = &self.node;
              ast.node(*node).and_then(|node| crate::Node::from_node(node))
          }
      }
      ///Returns the NodeId for the `node` field
      pub fn get_node_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let node = &self.node;
              *node
          }
      }
      ///Returns the `field` field
      pub fn get_field<'ast>(&self, ast: &'ast crate::AST) -> bool {
          {
              let field = &self.field;
              *field
          }
      }
      ///Returns the `my_type` field
      pub fn get_my_type<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              let my_type = &self.my_type;
              ast.node(*my_type).and_then(|node| crate::Type::from_node(node))
          }
      }
      ///Returns the NodeId for the `my_type` field
      pub fn get_my_type_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let my_type = &self.my_type;
              *my_type
          }
      }
      ///Returns the `my_impl` field
      pub fn get_my_impl<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              if let Some(ref my_impl) = self.my_impl {
                  ast.node(*my_impl).and_then(|node| crate::Type::from_node(node))
              } else {
                  None
              }
          }
      }
      ///Returns the NodeId for the `my_impl` field
      pub fn get_my_impl_id<'ast>(&self, ast: &'ast crate::AST) -> Option<crate::NodeId> {
          { if let Some(ref my_impl) = self.my_impl { Some(*my_impl) } else { None } }
      }
  }
  #[allow(unused)]
  impl<'ast> HygieneTest {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for HygieneTest {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "HygieneTest"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for HygieneTest {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "HygieneTest"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for HygieneTest {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"HygieneTest",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for HygieneTest {
      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(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"HygieneTest",
              ),
          );
          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 my_self = &self.my_self;
                  b.add_node_with_state(state, stringify!(my_self), my_self);
              };
              {
                  let ast = &self.ast;
                  b.add_node_with_state(state, stringify!(ast), ast);
              };
              {
                  let node = &self.node;
                  b.add_node_with_state(state, stringify!(node), node);
              };
              {
                  let field = &self.field;
                  use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
                  b.field(
                      stringify!(field),
                      format!("{:?}", field).purple().italic().to_string(),
                  );
              };
              {
                  let my_type = &self.my_type;
                  b.add_node_with_state(state, stringify!(my_type), my_type);
              };
              {
                  if let Some(ref my_impl) = self.my_impl {
                      b.add_node_with_state(state, stringify!(my_impl), my_impl);
                  }
              };
          };
      }
  }