use std::fmt;
use std::sync::Arc;
use regex::Regex;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MatcherId(pub String);
impl fmt::Display for MatcherId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EmitSeverity {
Error,
Warning,
Info,
Hint,
}
impl fmt::Display for EmitSeverity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Error => write!(f, "error"),
Self::Warning => write!(f, "warning"),
Self::Info => write!(f, "info"),
Self::Hint => write!(f, "hint"),
}
}
}
#[derive(Debug, Clone)]
pub struct EmitTemplate {
pub severity: EmitSeverity,
pub message: String,
pub file: Option<String>,
pub line: Option<String>,
pub column: Option<String>,
pub code: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EndCondition {
NextStart,
BlankLine,
}
#[derive(Debug, Clone)]
pub struct BodyRule {
pub pattern: Arc<Regex>,
pub optional: bool,
pub repeat: bool,
}
#[derive(Debug, Clone)]
pub struct CompiledMatcher {
pub id: MatcherId,
pub source: String,
pub priority: u32,
pub schema_version: u32,
pub start: Arc<Regex>,
pub body: Vec<BodyRule>,
pub max_lines: Option<u32>,
pub end: EndCondition,
pub emit: EmitTemplate,
}
fn _assert_send_sync() {
fn require<T: Send + Sync>() {}
require::<CompiledMatcher>();
}