#![cfg_attr(coverage_nightly, coverage(off))]
use super::{
AgentsMdDocument, Command, DocumentMetadata, Guideline, PathBuf, Priority, QualityRules,
Section, SectionType,
};
use anyhow::Result;
use pulldown_cmark::{Event, HeadingLevel, Parser as MarkdownParser, Tag, TagEnd};
use regex::Regex;
use std::collections::HashMap;
pub struct AgentsMdParser {
validation_rules: ValidationRules,
command_patterns: Vec<Regex>,
}
#[derive(Debug, Clone)]
pub struct ValidationRules {
pub require_overview: bool,
pub require_testing: bool,
pub max_size: usize,
pub allowed_sections: Vec<SectionType>,
}
impl Default for ValidationRules {
fn default() -> Self {
Self {
require_overview: false,
require_testing: false,
max_size: 1024 * 1024, allowed_sections: vec![
SectionType::Overview,
SectionType::DevEnvironment,
SectionType::Testing,
SectionType::CodeStyle,
SectionType::PRGuidelines,
SectionType::Security,
],
}
}
}
#[derive(Debug, Clone)]
pub struct ValidationReport {
pub valid: bool,
pub errors: Vec<ValidationError>,
pub warnings: Vec<ValidationWarning>,
}
#[derive(Debug, Clone)]
pub struct ValidationError {
pub message: String,
pub line: Option<usize>,
pub section: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ValidationWarning {
pub message: String,
pub severity: WarningSeverity,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WarningSeverity {
Low,
Medium,
High,
}
#[derive(Default)]
struct ParseState {
current_section: Option<Section>,
current_heading_level: u8,
in_code_block: bool,
code_block_content: String,
code_block_lang: String,
in_list: bool,
list_item_content: String,
}
impl Default for AgentsMdParser {
fn default() -> Self {
Self::new()
}
}
include!("parser_core.rs");
include!("parser_extraction.rs");
include!("parser_tests.rs");