---
source: crates/laburnum-syntax-macro/src/tests/mod.rs
expression: "use laburnum_syntax_macro::tests::test_complex_enum_field"
snapshot_kind: text
---
Input: >
#[laburnum_syntax(AST)]
pub struct ComplexEnum {
visibility: Field<Enum<crate::modifier::Visibility>>,
expr: EnumNodeId<crate::expression::Inline>,
maybe_expr: Option<EnumNodeId<crate::expression::Expression>>,
}
Output: >
#[derive(Clone, PartialEq)]
pub struct ComplexEnum {
/// 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) visibility: crate::modifier::Visibility,
pub(crate) expr: crate::NodeId,
pub(crate) maybe_expr: Option<crate::NodeId>,
}
impl ComplexEnum {
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 complex_enum_field {}
#[allow(unused)]
impl ComplexEnum {
///Returns the `visibility` field
pub fn get_visibility<'ast>(
&self,
ast: &'ast crate::AST,
) -> &crate::modifier::Visibility {
{
let visibility = &self.visibility;
visibility
}
}
///Returns the `expr` field
pub fn get_expr<'ast>(
&self,
ast: &'ast crate::AST,
) -> Option<crate::expression::Inline<'ast>> {
{
let expr = &self.expr;
ast.node(*expr).and_then(|node| crate::expression::Inline::from_node(node))
}
}
///Returns the NodeId for the `expr` field
pub fn get_expr_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
{
let expr = &self.expr;
*expr
}
}
///Returns the `maybe_expr` field
pub fn get_maybe_expr<'ast>(
&self,
ast: &'ast crate::AST,
) -> Option<crate::expression::Expression<'ast>> {
{
if let Some(ref maybe_expr) = self.maybe_expr {
ast.node(*maybe_expr)
.and_then(|node| crate::expression::Expression::from_node(node))
} else {
None
}
}
}
///Returns the NodeId for the `maybe_expr` field
pub fn get_maybe_expr_id<'ast>(
&self,
ast: &'ast crate::AST,
) -> Option<crate::NodeId> {
{
if let Some(ref maybe_expr) = self.maybe_expr {
Some(*maybe_expr)
} else {
None
}
}
}
}
#[allow(unused)]
impl<'ast> ComplexEnum {
pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
self.get_expr(ast).unwrap().validate(ast).unwrap();
self.get_maybe_expr(ast).unwrap().validate(ast).unwrap();
Ok(())
}
}
#[allow(unused)]
impl std::fmt::Display for ComplexEnum {
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) }, "ComplexEnum"
),
)
.finish()
}
}
#[allow(unused)]
impl std::fmt::Debug for ComplexEnum {
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) }, "ComplexEnum"
),
)
.finish()
}
}
#[allow(unused)]
impl bluegum::Bluegum for ComplexEnum {
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)
},
&"ComplexEnum",
),
);
}
}
#[allow(unused)]
impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for ComplexEnum {
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)
},
&"ComplexEnum",
),
);
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 visibility = &self.visibility;
use {owo_colors::OwoColorize, unicode_width::UnicodeWidthStr};
b.field(
stringify!(visibility),
format!("{:?}", visibility).purple().italic().to_string(),
);
};
{
let expr = &self.expr;
match state.get(*expr) {
Some(node) => {
b.add_node_with_state(
state,
stringify!(expr),
&crate::expression::Inline::from(node),
);
}
None => {
b.field(&format!("Node not found: {self}"), "None");
}
}
};
{
if let Some(ref maybe_expr) = self.maybe_expr {
match state.get(*maybe_expr) {
Some(node) => {
b.add_node_with_state(
state,
stringify!(maybe_expr),
&crate::expression::Expression::from(node),
);
}
None => {
b.field(&format!("Node not found: {self}"), "None");
}
}
}
};
};
}
}