#![doc(html_root_url = "https://docs.rs/syntect/4.6.0")]
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[macro_use]
mod crash;
pub use crash::*;
#[cfg(any(feature = "dump-load-rs", feature = "dump-load", feature = "dump-create", feature = "dump-create-rs"))]
pub mod dumps;
#[cfg(feature = "parsing")]
pub mod easy;
#[cfg(feature = "html")]
mod escape;
pub mod highlighting;
#[cfg(feature = "html")]
pub mod html;
pub mod parsing;
pub mod util;
use std::io::Error as IoError;
use std::error::Error;
use std::fmt;
#[cfg(feature = "metadata")]
use serde_json::Error as JsonError;
#[cfg(all(feature = "yaml-load", feature = "parsing"))]
use crate::parsing::ParseSyntaxError;
#[cfg(feature = "plist-load")]
use crate::highlighting::{ParseThemeError, SettingsError};
#[derive(Debug)]
pub enum LoadingError {
WalkDir(walkdir::Error),
Io(IoError),
#[cfg(feature = "yaml-load")]
ParseSyntax(ParseSyntaxError, Option<String>),
#[cfg(feature = "metadata")]
ParseMetadata(JsonError),
#[cfg(feature = "plist-load")]
ParseTheme(ParseThemeError),
#[cfg(feature = "plist-load")]
ReadSettings(SettingsError),
BadPath,
}
#[cfg(feature = "plist-load")]
impl From<SettingsError> for LoadingError {
fn from(error: SettingsError) -> LoadingError {
LoadingError::ReadSettings(error)
}
}
impl From<IoError> for LoadingError {
fn from(error: IoError) -> LoadingError {
LoadingError::Io(error)
}
}
#[cfg(feature = "plist-load")]
impl From<ParseThemeError> for LoadingError {
fn from(error: ParseThemeError) -> LoadingError {
LoadingError::ParseTheme(error)
}
}
#[cfg(feature = "metadata")]
impl From<JsonError> for LoadingError {
fn from(src: JsonError) -> LoadingError {
LoadingError::ParseMetadata(src)
}
}
#[cfg(all(feature = "yaml-load", feature = "parsing"))]
impl From<ParseSyntaxError> for LoadingError {
fn from(error: ParseSyntaxError) -> LoadingError {
LoadingError::ParseSyntax(error, None)
}
}
impl fmt::Display for LoadingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::LoadingError::*;
match *self {
WalkDir(ref error) => error.fmt(f),
Io(ref error) => error.fmt(f),
#[cfg(feature = "yaml-load")]
ParseSyntax(ref error, ref filename) => {
if let Some(ref file) = filename {
write!(f, "{}: {}", file, error)
} else {
error.fmt(f)
}
},
#[cfg(feature = "metadata")]
ParseMetadata(_) => write!(f, "Failed to parse JSON"),
#[cfg(feature = "plist-load")]
ParseTheme(_) => write!(f, "Invalid syntax theme"),
#[cfg(feature = "plist-load")]
ReadSettings(_) => write!(f, "Invalid syntax theme settings"),
BadPath => write!(f, "Invalid path"),
}
}
}
impl Error for LoadingError {
fn cause(&self) -> Option<&dyn Error> {
use crate::LoadingError::*;
match *self {
WalkDir(ref error) => Some(error),
Io(ref error) => Some(error),
_ => None,
}
}
}