Skip to content

Commit

Permalink
Add feature gated Cow module paths (#900)
Browse files Browse the repository at this point in the history
The generator currently wraps tags in an instance of alloc::borrow::Cow. This PR changes that to std::borrow::Cow conditional on the std feature flag being active.

Closes #899.
  • Loading branch information
veeenu authored Jul 24, 2023
1 parent 4d51b5b commit da0feb0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,14 @@ fn generate_expr(expr: OptimizedExpr) -> TokenStream {
#[cfg(feature = "grammar-extras")]
OptimizedExpr::NodeTag(expr, tag) => {
let expr = generate_expr(*expr);
let tag_cow = {
#[cfg(feature = "std")]
quote! { ::std::borrow::Cow::Borrowed(#tag) }
#[cfg(not(feature = "std"))]
quote! { ::alloc::borrow::Cow::Borrowed(#tag) }
};
quote! {
#expr.and_then(|state| state.tag_node(alloc::borrow::Cow::Borrowed(#tag)))
#expr.and_then(|state| state.tag_node(#tag_cow))
}
}
}
Expand Down Expand Up @@ -695,8 +701,14 @@ fn generate_expr_atomic(expr: OptimizedExpr) -> TokenStream {
#[cfg(feature = "grammar-extras")]
OptimizedExpr::NodeTag(expr, tag) => {
let expr = generate_expr_atomic(*expr);
let tag_cow = {
#[cfg(feature = "std")]
quote! { ::std::borrow::Cow::Borrowed(#tag) }
#[cfg(not(feature = "std"))]
quote! { ::alloc::borrow::Cow::Borrowed(#tag) }
};
quote! {
#expr.and_then(|state| state.tag_node(alloc::borrow::Cow::Borrowed(#tag)))
#expr.and_then(|state| state.tag_node(#tag_cow))
}
}
}
Expand Down

0 comments on commit da0feb0

Please sign in to comment.