syncdoc_core/
omnibus.rs

1use proc_macro2::TokenStream;
2use quote::quote;
3use unsynn::*;
4
5use crate::parse::{DocStubArg, DocStubInner};
6use crate::token_processors::TokenProcessor;
7
8pub fn inject_all_docs_impl(args: TokenStream, input: TokenStream) -> core::result::Result<TokenStream, TokenStream> {
9    // Parse the path argument
10    let base_path = match parse_path_from_args(args) {
11        Ok(path) => path,
12        Err(e) => {
13            let error_msg = e.to_string();
14            return Err(quote! { compile_error!(#error_msg) });
15        }
16    };
17
18    // Process the input with the base path
19    Ok(TokenProcessor::new(input, base_path).process())
20}
21
22fn parse_path_from_args(args: TokenStream) -> core::result::Result<String, String> {
23    if args.is_empty() {
24        return Err("omnidoc requires a path argument".to_string());
25    }
26
27    let mut args_iter = args.into_token_iter();
28    match args_iter.parse::<DocStubInner>() {
29        Ok(parsed) => {
30            if let Some(arg_list) = parsed.args {
31                for arg in arg_list.0 {
32                    if let DocStubArg::Path(path_arg) = arg.value {
33                        return Ok(path_arg.value.as_str().to_string());
34                    }
35                }
36            }
37            Err("path argument not found".to_string())
38        }
39        Err(_e) => Err("Failed to parse arguments".to_string()),
40    }
41}