From f25f7cd72ea13ec72376f9808570e1772bfa429b Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 3 Dec 2026 10:13:24 +0100 Subject: [PATCH 1/5] Yeast: Share dump node header formatting The `dump_node` function contained writing logic that was already in `dump_node_inline`. The new `is_leaf(node)` added to `dump_node_header` matches the code removed from `dump_node` and doesn't affect the existing caller which only calls `dump_node_inline` for leaf nodes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cf5e9a9-33db-472c-bb72-e66af26a856f --- shared/yeast/src/dump.rs | 78 ++++++++++------------------------------ 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/shared/yeast/src/dump.rs b/shared/yeast/src/dump.rs index 43f168b352de..3069080d4da0 100644 --- a/shared/yeast/src/dump.rs +++ b/shared/yeast/src/dump.rs @@ -216,47 +216,16 @@ fn dump_node( let prefix = " ".repeat(indent); - // Node kind - write!(out, "{}{}", prefix, node.kind_name()).unwrap(); - - // Location - if options.show_locations { - let start = node.start_position(); - let end = node.end_position(); - write!( - out, - " [{},{}]-[{},{}]", - start.row + 1, - start.column + 1, - end.row + 1, - end.column + 1 - ) - .unwrap(); - } - - // Content for leaf nodes - if options.show_content && node.is_named() && is_leaf(node) { - let content = node_content(node, source); - if !content.is_empty() { - write!(out, " {content:?}").unwrap(); - } - } - - if options.show_abridged_source { - write_source_skeleton(ast, node, source, out); - if external_to_parent { - write!(out, " (external)").unwrap(); - } - } - - if let Some(context) = type_check - && let Some(err) = - type_error_for_node(context.schema, node, context.expected, context.parent_field) - { - write!(out, " <-- ERROR: {err}").unwrap(); - } - - writeln!(out).unwrap(); + write!(out, "{prefix}").unwrap(); + dump_node_header( + ast, + node, + source, + options, + type_check, + external_to_parent, + out, + ); // Named fields first, in the schema's declared order when available // (front-end-independent), else in field-id order. Any present fields not @@ -315,17 +284,11 @@ fn dump_node( // Inline single child let child = ast.get_node(children[0]); let external = child.is_some_and(|child| is_external_child(node, child)); - if child.is_some_and(is_leaf) { + if let Some(child) = child + && is_leaf(child) + { write!(out, " ").unwrap(); - dump_node_inline( - ast, - children[0], - source, - options, - child_type_check, - external, - out, - ); + dump_node_header(ast, child, source, options, child_type_check, external, out); } else { writeln!(out).unwrap(); dump_node( @@ -410,20 +373,16 @@ fn dump_node( } } -/// Dump a leaf node inline (no newline prefix, caller provides context). -fn dump_node_inline( +/// Dump a node header, including its terminating newline but not indentation. +fn dump_node_header( ast: &Ast, - id: Id, + node: &Node, source: &str, options: &DumpOptions, type_check: Option>, external_to_parent: bool, out: &mut String, ) { - let Some(node) = ast.get_node(id) else { - return; - }; - write!(out, "{}", node.kind_name()).unwrap(); if options.show_locations { @@ -440,7 +399,8 @@ fn dump_node_inline( .unwrap(); } - if options.show_content && node.is_named() { + // Content for leaf nodes + if options.show_content && node.is_named() && is_leaf(node) { let content = node_content(node, source); if !content.is_empty() { write!(out, " {content:?}").unwrap(); From 6c806e655b0e69b147c9aa20005cbbeeee3d1b5a Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 3 Dec 2026 10:15:37 +0100 Subject: [PATCH 2/5] Yeast: Reuse atom parsers in pattern and template lists Makes `parse_pattern_list` and `parse_list` reuse existing parsing function. `parse_pattern_list` now uses `parse_pattern_atom` for the bulk of its work and `parse_list` uses `parse_one` Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cf5e9a9-33db-472c-bb72-e66af26a856f --- shared/yeast-macros/src/rule_parse.rs | 33 +++++------------------ shared/yeast-macros/src/template_parse.rs | 33 +++++++---------------- 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/shared/yeast-macros/src/rule_parse.rs b/shared/yeast-macros/src/rule_parse.rs index 203ee12a4e94..bd1990713894 100644 --- a/shared/yeast-macros/src/rule_parse.rs +++ b/shared/yeast-macros/src/rule_parse.rs @@ -213,33 +213,12 @@ fn push_field_pattern(fields: &mut Vec<(String, Pattern)>, name: String, pattern fn parse_pattern_list(tokens: &mut Tokens) -> Result> { let mut patterns = Vec::new(); - while tokens.peek().is_some() { - if peek_is_group(tokens, Delimiter::Parenthesis) { - let group = expect_group(tokens, Delimiter::Parenthesis)?; - let mut inner = group.stream().into_iter().peekable(); - let pattern = parse_parenthesized_pattern(&mut inner, group.span())?; - patterns.push(maybe_repeat(tokens, pattern)?); - continue; - } - - if matches!(tokens.peek(), Some(TokenTree::Literal(_))) { - let literal = expect_string_literal(tokens)?; - patterns.push(maybe_repeat(tokens, Pattern::Unnamed(literal))?); - continue; - } - - if matches!(tokens.peek(), Some(TokenTree::Ident(identifier)) if *identifier == "_") { - tokens.next(); - patterns.push(maybe_repeat( - tokens, - Pattern::Any { - match_unnamed: true, - }, - )?); - continue; - } - - break; + while peek_is_group(tokens, Delimiter::Parenthesis) + || matches!(tokens.peek(), Some(TokenTree::Literal(_))) + || matches!(tokens.peek(), Some(TokenTree::Ident(identifier)) if *identifier == "_") + { + let pattern = parse_pattern_atom(tokens)?; + patterns.push(maybe_repeat(tokens, pattern)?); } Ok(patterns) } diff --git a/shared/yeast-macros/src/template_parse.rs b/shared/yeast-macros/src/template_parse.rs index eb104fe8cdba..f46e1d937943 100644 --- a/shared/yeast-macros/src/template_parse.rs +++ b/shared/yeast-macros/src/template_parse.rs @@ -185,33 +185,18 @@ fn parse_alternatives(group: &proc_macro2::Group) -> Result> { fn parse_list(tokens: &mut Tokens) -> Result> { let mut templates = Vec::new(); - while tokens.peek().is_some() { - if peek_is_group(tokens, Delimiter::Parenthesis) { - let group = expect_group(tokens, Delimiter::Parenthesis)?; - if group.stream().is_empty() { - continue; - } - templates.push(Template::Node(parse_node(&group)?)); - continue; - } - - if peek_is_group(tokens, Delimiter::Brace) { - templates.push(Template::Splice(parse_block(expect_group( - tokens, - Delimiter::Brace, - )?)?)); - continue; + while let Some(TokenTree::Group(group)) = tokens.peek() { + if !matches!( + group.delimiter(), + Delimiter::Parenthesis | Delimiter::Brace | Delimiter::Bracket + ) { + break; } - - if peek_is_group(tokens, Delimiter::Bracket) { - templates.push(Template::Choice(parse_alternatives(&expect_group( - tokens, - Delimiter::Bracket, - )?)?)); + if group.delimiter() == Delimiter::Parenthesis && group.stream().is_empty() { + tokens.next(); continue; } - - break; + templates.push(parse_one(tokens)?); } Ok(templates) } From a21f9549216d4482c87db3e3e1dcf3d32fcfdf81 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 3 Dec 2026 10:12:01 +0100 Subject: [PATCH 3/5] Yeast: Parse query match arms with syn Uses APIs from `syn` that makes parsing more consice. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cf5e9a9-33db-472c-bb72-e66af26a856f --- shared/yeast-macros/src/parse.rs | 69 ++++++++++++-------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/shared/yeast-macros/src/parse.rs b/shared/yeast-macros/src/parse.rs index 435064dba89e..86c0aa6e2553 100644 --- a/shared/yeast-macros/src/parse.rs +++ b/shared/yeast-macros/src/parse.rs @@ -12,65 +12,46 @@ impl Parse for QueryMatch { fn parse(input: ParseStream<'_>) -> syn::Result { let node = input.parse()?; input.parse::()?; - let arm_tokens: TokenStream = input.parse()?; - let mut tokens = arm_tokens.into_iter().peekable(); - let mut arms = Vec::new(); - while tokens.peek().is_some() { - arms.push(QueryMatchArm::parse(&mut tokens)?); - } + let arms = input.parse_terminated(QueryMatchArm::parse, syn::Token![,])?; if arms.is_empty() { return Err(syn::Error::new( Span::call_site(), "query_match! requires at least one query arm", )); } - Ok(QueryMatch { node, arms }) + Ok(QueryMatch { + node, + arms: arms.into_iter().collect(), + }) } } -impl QueryMatchArm { - fn parse(tokens: &mut Tokens) -> Result { - let mut pattern_and_guard = Vec::new(); - loop { - match tokens.next() { - Some(TokenTree::Punct(first)) - if first.as_char() == '=' - && first.spacing() == proc_macro2::Spacing::Joint - && matches!( - tokens.peek(), - Some(TokenTree::Punct(second)) if second.as_char() == '>' - ) => - { - tokens.next(); - break; - } - Some(token) => pattern_and_guard.push(token), - None => { - return Err(syn::Error::new( - Span::call_site(), - "expected `=>` in query_match! arm", - )); - } +impl Parse for QueryMatchArm { + fn parse(input: ParseStream<'_>) -> Result { + let mut pattern_and_guard = TokenStream::new(); + while !input.peek(syn::Token![=>]) { + if input.is_empty() { + return Err(syn::Error::new( + Span::call_site(), + "expected `=>` in query_match! arm", + )); } + pattern_and_guard.extend([input.parse::()?]); } + input.parse::]>()?; - let body = tokens - .next() - .ok_or_else(|| syn::Error::new(Span::call_site(), "expected block after `=>`"))?; + if input.is_empty() { + return Err(syn::Error::new( + Span::call_site(), + "expected block after `=>`", + )); + } + let body: TokenTree = input.parse()?; let body = syn::parse2(TokenStream::from(body))?; - - match tokens.next() { - Some(TokenTree::Punct(comma)) if comma.as_char() == ',' => {} - Some(token) => { - return Err(syn::Error::new_spanned( - token, - "expected `,` after query_match! arm", - )); - } - None => {} + if !input.is_empty() && !input.peek(syn::Token![,]) { + return Err(input.error("expected `,` after query_match! arm")); } - let pattern_and_guard = pattern_and_guard.into_iter().collect(); let (pattern, guard) = crate::rule_parse::split_guard(pattern_and_guard)?; let pattern = crate::rule_parse::parse_pattern(pattern)?; Ok(Self { From 02be51100bda4b7c1e7508f6133f786db200ba49 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 3 Dec 2026 10:11:19 +0100 Subject: [PATCH 4/5] Yeast: Share procedural macro expansion handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cf5e9a9-33db-472c-bb72-e66af26a856f --- shared/yeast-macros/src/lib.rs | 60 +++++++++------------------------- 1 file changed, 15 insertions(+), 45 deletions(-) diff --git a/shared/yeast-macros/src/lib.rs b/shared/yeast-macros/src/lib.rs index a1d3fe2c9920..f224c84fe02e 100644 --- a/shared/yeast-macros/src/lib.rs +++ b/shared/yeast-macros/src/lib.rs @@ -8,6 +8,12 @@ mod rule_parse; mod template_parse; mod tokens; +fn expand(input: TokenStream, parse: fn(TokenStream2) -> syn::Result) -> TokenStream { + parse(input.into()) + .unwrap_or_else(|err| err.to_compile_error()) + .into() +} + /// Proc macro for constructing a tree-sitter-inspired `yeast::query::QueryNode`. /// /// # Syntax @@ -44,31 +50,19 @@ mod tokens; /// ``` #[proc_macro] pub fn query(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_query_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_query_top) } #[doc(hidden)] #[proc_macro] pub fn query_match_with_schema(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_query_match_with_schema_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_query_match_with_schema_top) } #[doc(hidden)] #[proc_macro] pub fn query_match_with_schema_and_context(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_query_match_with_schema_and_context_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_query_match_with_schema_and_context_top) } /// Declare a matcher namespace for one AST schema. @@ -90,11 +84,7 @@ pub fn query_match_with_schema_and_context(input: TokenStream) -> TokenStream { /// ``` #[proc_macro] pub fn query_match_schema(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_query_match_schema_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_query_match_schema_top) } /// Build a single AST node from a template, returning its `OutputId`. @@ -154,21 +144,13 @@ pub fn query_match_schema(input: TokenStream) -> TokenStream { #[doc(hidden)] #[proc_macro] pub fn tree_with_schema(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_tree_with_schema_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_tree_with_schema_top) } #[doc(hidden)] #[proc_macro] pub fn trees_with_schema(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_trees_with_schema_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_trees_with_schema_top) } /// Declare an output-schema namespace with importable `tree!`, `trees!`, @@ -187,11 +169,7 @@ pub fn trees_with_schema(input: TokenStream) -> TokenStream { /// ``` #[proc_macro] pub fn tree_schema(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_tree_schema_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_tree_schema_top) } /// Define a desugaring rule with query and transform in one declaration. @@ -228,11 +206,7 @@ pub fn tree_schema(input: TokenStream) -> TokenStream { /// `ctx` binding inside interpolations. #[proc_macro] pub fn rule(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_rule_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_rule_top) } /// Bundle a list of YEAST rewrite rules with input/output node-types @@ -278,9 +252,5 @@ pub fn rule(input: TokenStream) -> TokenStream { /// unambiguous input node from which to inherit a value. #[proc_macro] pub fn rules(input: TokenStream) -> TokenStream { - let input2: TokenStream2 = input.into(); - match parse::parse_rules_top(input2) { - Ok(output) => output.into(), - Err(err) => err.to_compile_error().into(), - } + expand(input, parse::parse_rules_top) } From 5a7e7c7b6f9e0e8d8c15bc7ea32c89e790cd2b3c Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 3 Dec 2026 10:13:02 +0100 Subject: [PATCH 5/5] Yeast: Share schema parsing and path resolution Factor out common parts into two new function `parse_templates_with_schema` and `parse_schema_declaration`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cf5e9a9-33db-472c-bb72-e66af26a856f --- shared/yeast-macros/src/parse.rs | 143 +++++++++++++------------------ 1 file changed, 61 insertions(+), 82 deletions(-) diff --git a/shared/yeast-macros/src/parse.rs b/shared/yeast-macros/src/parse.rs index 86c0aa6e2553..c59b5fe8cdbb 100644 --- a/shared/yeast-macros/src/parse.rs +++ b/shared/yeast-macros/src/parse.rs @@ -1,5 +1,6 @@ use proc_macro2::{Ident, Span, TokenStream, TokenTree}; use quote::quote; +use std::{env, fs, path::PathBuf}; use syn::Result; use syn::parse::{Parse, ParseStream}; @@ -93,22 +94,7 @@ pub fn parse_query_match_with_schema_and_context_top(input: TokenStream) -> Resu } pub fn parse_query_match_schema_top(input: TokenStream) -> Result { - let mut tokens = input.into_iter().peekable(); - let module = expect_ident(&mut tokens, "expected schema module name")?; - expect_punct(&mut tokens, ',', "expected `,` after schema module name")?; - let schema = parse_string_arg(&mut tokens, "schema")?; - if tokens.peek().is_some() { - expect_punct(&mut tokens, ',', "expected trailing `,`")?; - } - if let Some(token) = tokens.next() { - return Err(syn::Error::new_spanned( - token, - "unexpected token after schema declaration", - )); - } - - let schema_abs = resolve_manifest_path(&schema, "query_match_schema")?; - let schema_lit = proc_macro2::Literal::string(&schema_abs.to_string_lossy()); + let (module, schema_lit) = parse_schema_declaration(input, "query_match_schema", "schema")?; Ok(quote! { pub(crate) mod #module { @@ -140,27 +126,22 @@ pub fn parse_query_match_schema_top(input: TokenStream) -> Result { } pub fn parse_tree_with_schema_top(input: TokenStream) -> Result { - let mut tokens = input.into_iter().peekable(); - let output_path = parse_named_string_arg(&mut tokens, "output")?; - expect_punct(&mut tokens, ',', "expected `,` after output schema path")?; - let explicit_ctx = parse_context_arg(&mut tokens)?; - let template_tokens: TokenStream = tokens.collect(); - let ctx = explicit_ctx.unwrap_or_else(|| { - Ident::new( - "ctx", - first_leaf_span(template_tokens.clone()).unwrap_or_else(Span::call_site), - ) - }); - let template = crate::template_parse::parse_template(template_tokens)?; - let template = template.lower_root(&ctx); - let output_lit = proc_macro2::Literal::string(&output_path.value); - Ok(quote!({ - const _: &::core::primitive::str = ::core::include_str!(#output_lit); - #template - })) + parse_templates_with_schema(input, |tokens, ctx| { + Ok(crate::template_parse::parse_template(tokens)?.lower_root(ctx)) + }) } pub fn parse_trees_with_schema_top(input: TokenStream) -> Result { + parse_templates_with_schema(input, |tokens, ctx| { + let templates = crate::template_parse::parse_templates(tokens)?; + Ok(crate::ast::Template::lower_list(&templates, ctx)) + }) +} + +fn parse_templates_with_schema( + input: TokenStream, + lower: impl FnOnce(TokenStream, &Ident) -> Result, +) -> Result { let mut tokens = input.into_iter().peekable(); let output_path = parse_named_string_arg(&mut tokens, "output")?; expect_punct(&mut tokens, ',', "expected `,` after output schema path")?; @@ -172,8 +153,7 @@ pub fn parse_trees_with_schema_top(input: TokenStream) -> Result { first_leaf_span(template_tokens.clone()).unwrap_or_else(Span::call_site), ) }); - let templates = crate::template_parse::parse_templates(template_tokens)?; - let templates = crate::ast::Template::lower_list(&templates, &ctx); + let templates = lower(template_tokens, &ctx)?; let output_lit = proc_macro2::Literal::string(&output_path.value); Ok(quote!({ const _: &::core::primitive::str = ::core::include_str!(#output_lit); @@ -182,22 +162,7 @@ pub fn parse_trees_with_schema_top(input: TokenStream) -> Result { } pub fn parse_tree_schema_top(input: TokenStream) -> Result { - let mut tokens = input.into_iter().peekable(); - let module = expect_ident(&mut tokens, "expected schema module name")?; - expect_punct(&mut tokens, ',', "expected `,` after schema module name")?; - let output_path = parse_string_arg(&mut tokens, "schema")?; - if tokens.peek().is_some() { - expect_punct(&mut tokens, ',', "expected trailing `,`")?; - } - if let Some(token) = tokens.next() { - return Err(syn::Error::new_spanned( - token, - "unexpected token after tree schema declaration", - )); - } - - let output_abs = resolve_manifest_path(&output_path, "tree_schema")?; - let output_lit = proc_macro2::Literal::string(&output_abs.to_string_lossy()); + let (module, output_lit) = parse_schema_declaration(input, "tree_schema", "tree schema")?; Ok(quote! { pub(crate) mod #module { #[allow(dead_code)] @@ -259,23 +224,10 @@ pub fn parse_rules_top(input: TokenStream) -> Result { let output_path = parse_named_string_arg(&mut tokens, "output")?; expect_punct(&mut tokens, ',', "expected `,` after output path")?; - let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").map_err(|_| { - syn::Error::new( - Span::call_site(), - "rules!: CARGO_MANIFEST_DIR is not set; cannot resolve schema paths", - ) - })?; - let resolve_path = |raw: &str| -> std::path::PathBuf { - let path = std::path::PathBuf::from(raw); - if path.is_absolute() { - path - } else { - std::path::PathBuf::from(&manifest_dir).join(path) - } - }; - let input_abs = resolve_path(&input_path.value); - let output_abs = resolve_path(&output_path.value); - let output_yaml = std::fs::read_to_string(&output_abs).map_err(|error| { + let manifest_dir = manifest_dir("rules", "schema paths")?; + let input_abs = manifest_dir.join(&input_path.value); + let output_abs = manifest_dir.join(&output_path.value); + let output_yaml = fs::read_to_string(&output_abs).map_err(|error| { syn::Error::new( output_path.literal_span, format!( @@ -337,19 +289,46 @@ struct NamedString { literal_span: Span, } -fn resolve_manifest_path(path: &NamedString, macro_name: &str) -> Result { - let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").map_err(|_| { - syn::Error::new( - Span::call_site(), - format!("{macro_name}!: CARGO_MANIFEST_DIR is not set; cannot resolve schema path"), - ) - })?; - let path = std::path::PathBuf::from(&path.value); - Ok(if path.is_absolute() { - path - } else { - std::path::PathBuf::from(manifest_dir).join(path) - }) +fn parse_schema_declaration( + input: TokenStream, + macro_name: &str, + description: &str, +) -> Result<(Ident, proc_macro2::Literal)> { + let mut tokens = input.into_iter().peekable(); + let module = expect_ident(&mut tokens, "expected schema module name")?; + expect_punct(&mut tokens, ',', "expected `,` after schema module name")?; + let path = parse_string_arg(&mut tokens, "schema")?; + if tokens.peek().is_some() { + expect_punct(&mut tokens, ',', "expected trailing `,`")?; + } + if let Some(token) = tokens.next() { + return Err(syn::Error::new_spanned( + token, + format!("unexpected token after {description} declaration"), + )); + } + let path = resolve_manifest_path(&path, macro_name)?; + Ok(( + module, + proc_macro2::Literal::string(&path.to_string_lossy()), + )) +} + +fn resolve_manifest_path(path: &NamedString, macro_name: &str) -> Result { + Ok(manifest_dir(macro_name, "schema path")?.join(&path.value)) +} + +fn manifest_dir(macro_name: &str, description: &str) -> Result { + env::var("CARGO_MANIFEST_DIR") + .map(PathBuf::from) + .map_err(|_| { + syn::Error::new( + Span::call_site(), + format!( + "{macro_name}!: CARGO_MANIFEST_DIR is not set; cannot resolve {description}" + ), + ) + }) } fn first_leaf_span(stream: TokenStream) -> Option {