render_regex 0.0.0

SVG visualization of regex DFAs.
Documentation
//! Intermediate representation (IR) for visualizing regex structures like AST, NFA, DFA.

use std::collections::HashMap;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NodeType {
    Ast,
    Nfa,
    Dfa,
    Generic
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShapeHint {
    Circle,
    Box,
    Diamond,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeStyle {
    Solid,
    Dashed,
    Dotted,
}

#[derive(Debug, Clone)]
pub struct VisualNode {
    pub id: usize,
    pub label: String,
    pub shape: ShapeHint,
    pub is_accept: bool,
    pub node_type: NodeType,
}

#[derive(Debug, Clone)]
pub struct VisualEdge {
    pub from: usize,
    pub to: usize,
    pub label: String,
    pub bend_offset: f32,
    pub style: EdgeStyle,
}

#[derive(Debug, Clone)]
pub struct VisualGraph {
    pub nodes: Vec<VisualNode>,
    pub edges: Vec<VisualEdge>,
}

impl VisualGraph {
    pub fn new() -> Self {
        Self { nodes: vec![], edges: vec![] }
    }

    pub fn with_capacity(n: usize, e: usize) -> Self {
        Self {
            nodes: Vec::with_capacity(n),
            edges: Vec::with_capacity(e),
        }
    }

    pub fn node_map(&self) -> HashMap<usize, &VisualNode> {
        self.nodes.iter().map(|n| (n.id, n)).collect()
    }
}