use std::path::PathBuf;
use bitflags::bitflags;
use url::Url;
use xsd_parser_types::misc::{Namespace, NamespacePrefix};
#[derive(Debug, Clone)]
pub struct ParserConfig {
pub resolver: Vec<Resolver>,
pub namespaces: Vec<(NamespacePrefix, Namespace)>,
pub schemas: Vec<Schema>,
pub flags: ParserFlags,
pub debug_output: Option<PathBuf>,
}
impl Default for ParserConfig {
fn default() -> Self {
Self {
resolver: vec![Resolver::File],
schemas: vec![],
namespaces: vec![],
flags: ParserFlags::RESOLVE_INCLUDES
| ParserFlags::GENERATE_PREFIXES
| ParserFlags::DEFAULT_NAMESPACES
| ParserFlags::ALTERNATIVE_PREFIXES,
debug_output: None,
}
}
}
#[derive(Debug, Clone)]
pub enum Resolver {
#[cfg(feature = "web-resolver")]
Web,
File,
}
#[derive(Debug, Clone)]
pub enum Schema {
Url(Url),
File(PathBuf),
Schema(String),
NamedSchema(String, String),
}
impl Schema {
#[inline]
pub fn url<T>(value: T) -> Self
where
T: Into<Url>,
{
Self::Url(value.into())
}
#[inline]
pub fn file<T>(value: T) -> Self
where
T: Into<PathBuf>,
{
Self::File(value.into())
}
#[inline]
#[allow(clippy::self_named_constructors)]
pub fn schema<T>(value: T) -> Self
where
T: Into<String>,
{
Self::Schema(value.into())
}
#[inline]
#[allow(clippy::self_named_constructors)]
pub fn named_schema<S, T>(name: S, value: T) -> Self
where
S: Into<String>,
T: Into<String>,
{
Self::NamedSchema(name.into(), value.into())
}
}
impl From<Url> for Schema {
fn from(value: Url) -> Self {
Self::Url(value)
}
}
impl From<PathBuf> for Schema {
fn from(value: PathBuf) -> Self {
Self::File(value)
}
}
impl From<String> for Schema {
fn from(value: String) -> Self {
Self::Schema(value)
}
}
impl From<(String, String)> for Schema {
fn from((name, schema): (String, String)) -> Self {
Self::NamedSchema(name, schema)
}
}
bitflags! {
#[derive(Debug, Clone)]
pub struct ParserFlags: u32 {
const RESOLVE_INCLUDES = 1 << 0;
const DEFAULT_NAMESPACES = 1 << 1;
const ALTERNATIVE_PREFIXES = 1 << 2;
const GENERATE_PREFIXES = 1 << 3;
}
}