aboutsummaryrefslogtreecommitdiff
path: root/vendor/miette-derive/src/severity.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/miette-derive/src/severity.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/miette-derive/src/severity.rs')
-rw-r--r--vendor/miette-derive/src/severity.rs89
1 files changed, 0 insertions, 89 deletions
diff --git a/vendor/miette-derive/src/severity.rs b/vendor/miette-derive/src/severity.rs
deleted file mode 100644
index 4f26e4e..0000000
--- a/vendor/miette-derive/src/severity.rs
+++ /dev/null
@@ -1,89 +0,0 @@
-use proc_macro2::{Span, TokenStream};
-use quote::quote;
-use syn::{
- parenthesized,
- parse::{Parse, ParseStream},
- Token,
-};
-
-use crate::{
- diagnostic::{DiagnosticConcreteArgs, DiagnosticDef},
- forward::WhichFn,
- utils::gen_all_variants_with,
-};
-
-pub struct Severity(pub syn::Ident);
-
-impl Parse for Severity {
- fn parse(input: ParseStream) -> syn::Result<Self> {
- let ident = input.parse::<syn::Ident>()?;
- if ident == "severity" {
- let la = input.lookahead1();
- if la.peek(syn::token::Paren) {
- let content;
- parenthesized!(content in input);
- let la = content.lookahead1();
- if la.peek(syn::LitStr) {
- let str = content.parse::<syn::LitStr>()?;
- let sev = get_severity(&str.value(), str.span())?;
- Ok(Severity(syn::Ident::new(&sev, str.span())))
- } else {
- let ident = content.parse::<syn::Ident>()?;
- let sev = get_severity(&ident.to_string(), ident.span())?;
- Ok(Severity(syn::Ident::new(&sev, ident.span())))
- }
- } else {
- input.parse::<Token![=]>()?;
- let str = input.parse::<syn::LitStr>()?;
- let sev = get_severity(&str.value(), str.span())?;
- Ok(Severity(syn::Ident::new(&sev, str.span())))
- }
- } else {
- Err(syn::Error::new(
- ident.span(),
- "MIETTE BUG: not a severity option",
- ))
- }
- }
-}
-
-fn get_severity(input: &str, span: Span) -> syn::Result<String> {
- match input.to_lowercase().as_ref() {
- "error" | "err" => Ok("Error".into()),
- "warning" | "warn" => Ok("Warning".into()),
- "advice" | "adv" | "info" => Ok("Advice".into()),
- _ => Err(syn::Error::new(
- span,
- "Invalid severity level. Only Error, Warning, and Advice are supported.",
- )),
- }
-}
-
-impl Severity {
- pub(crate) fn gen_enum(variants: &[DiagnosticDef]) -> Option<TokenStream> {
- gen_all_variants_with(
- variants,
- WhichFn::Severity,
- |ident, fields, DiagnosticConcreteArgs { severity, .. }| {
- let severity = &severity.as_ref()?.0;
- let fields = match fields {
- syn::Fields::Named(_) => quote! { { .. } },
- syn::Fields::Unnamed(_) => quote! { (..) },
- syn::Fields::Unit => quote! {},
- };
- Some(
- quote! { Self::#ident #fields => std::option::Option::Some(miette::Severity::#severity), },
- )
- },
- )
- }
-
- pub(crate) fn gen_struct(&self) -> Option<TokenStream> {
- let sev = &self.0;
- Some(quote! {
- fn severity(&self) -> std::option::Option<miette::Severity> {
- Some(miette::Severity::#sev)
- }
- })
- }
-}