feat: relative style paths & component crate example
This commit is contained in:
parent
fd751082b5
commit
336852a74d
1 changed files with 376 additions and 89 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use std::{fs, io, path::Path};
|
||||
use std::{
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use sabry_procmacro_impl::impls::styly;
|
||||
|
|
@ -6,7 +9,7 @@ use syn::{spanned::Spanned, visit::Visit};
|
|||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum FileVisitError {
|
||||
#[error("Could not read file")]
|
||||
#[error("tt read file")]
|
||||
Read(#[from] io::Error),
|
||||
#[error("styly! macro found, yet invalid")]
|
||||
Styly(#[from] syn::Error),
|
||||
|
|
@ -19,6 +22,7 @@ pub fn visit_file(path: &Path) -> Result<StylyVisitor, FileVisitError> {
|
|||
|
||||
let mut styly_visitor = StylyVisitor {
|
||||
found_stylys: vec![],
|
||||
path: path.to_owned(),
|
||||
};
|
||||
styly_visitor.visit_file(&code_file);
|
||||
|
||||
|
|
@ -34,17 +38,26 @@ pub fn visit_file(path: &Path) -> Result<StylyVisitor, FileVisitError> {
|
|||
#[derive(Debug)]
|
||||
pub struct StylyVisitor {
|
||||
pub found_stylys: Vec<styly::MacroSyntax>,
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
impl<'ast> Visit<'ast> for StylyVisitor {
|
||||
fn visit_item_macro(&mut self, node: &'ast syn::ItemMacro) {
|
||||
if node.mac.path.get_ident().is_some_and(|i| i == "styly") {
|
||||
let body = node.mac.parse_body::<TokenStream>().unwrap_or_else(|_| {
|
||||
panic!("could not parse `styly!` macro at {:?}", node.mac.span())
|
||||
});
|
||||
let macro_data = styly::parse_macro_syntax(body).unwrap_or_else(|_| {
|
||||
panic!("could not parse `styly!` macro at {:?}", node.mac.span())
|
||||
let body = node.mac.parse_body::<TokenStream>().unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"could not parse `styly!` macro at {:?}: {e:?}",
|
||||
node.mac.span()
|
||||
)
|
||||
});
|
||||
let macro_data =
|
||||
styly::parse_macro_syntax(body, self.path.parent().map(|p| p.to_owned()))
|
||||
.unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"could not parse `styly!` macro at {:?}: {e:?}",
|
||||
node.mac.span()
|
||||
)
|
||||
});
|
||||
self.found_stylys.push(macro_data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue