decomment 0.1.0

Remove comments from source text in 13 languages without touching strings, templates, or regex literals.
Documentation
use core::fmt;

/// Which construct was still open at end of input.
#[non_exhaustive]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum UnterminatedKind {
    /// A block comment opener with no matching closer.
    BlockComment,
    /// A multi-line string form with no matching closer. A single-line string
    /// closes at a line terminator or at end of input and is never reported.
    StringLiteral,
}

impl fmt::Display for UnterminatedKind {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            UnterminatedKind::BlockComment => f.write_str("block comment"),
            UnterminatedKind::StringLiteral => f.write_str("string literal"),
        }
    }
}

impl core::error::Error for UnterminatedKind {}

/// A construct that was still open when the input ran out.
///
/// This is a diagnostic and not a failure. Every byte sequence has a defined
/// stripped form, so [`crate::strip`] returns output either way. A caller that
/// treats a truncated chunk as an error can turn this into one, because the
/// type implements [`core::error::Error`].
///
/// # Examples
///
/// ```
/// use decomment::{strip, Language, Options, UnterminatedKind};
///
/// let result = strip("var x = 1; /* cut", Options::new(Language::JavaScript));
/// let open = result.unterminated.ok_or("truncated").unwrap();
/// assert_eq!(open.kind, UnterminatedKind::BlockComment);
/// assert_eq!(open.offset, 11);
/// ```
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Unterminated {
    /// What was left open.
    pub kind: UnterminatedKind,
    /// Byte offset of the opening marker in the input.
    pub offset: usize,
}

impl fmt::Display for Unterminated {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "unterminated {} opened at byte {}",
            self.kind, self.offset
        )
    }
}

impl core::error::Error for Unterminated {}