num2phrase 0.1.0

Convert long number to a sequence of memorisable phrase with combination of short numbers
Documentation
use proc_macro2::Span;

#[derive(Debug, PartialEq, Clone)]
pub enum RepeatKind {
    Between(Option<usize>, Option<usize>),
}

// #[derive(Debug, PartialEq)]
// pub enum CharSelector {
//     Single(char),
//     Between(char, char),
// }

// #[derive(Debug, PartialEq)]
// pub enum FullCharSelector {
//     Inner(Vec<CharSelector>)
// }

#[derive(Debug, PartialEq, Clone)]
pub enum CustomToken {
    BIP39,
    DIGITS,
}

#[derive(Debug, Clone)]
pub enum CurlyWrapped {
    Repeat(Span, RepeatKind),
    Custom(Span, CustomToken),
}

impl PartialEq for CurlyWrapped {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (CurlyWrapped::Repeat(_, r1), CurlyWrapped::Repeat(_, r2)) => r1 == r2,
            (CurlyWrapped::Custom(_, c1), CurlyWrapped::Custom(_, c2)) => c1 == c2,
            _ => false,
        }
    }
}

#[derive(Debug, Clone)]
pub enum StructureToken {
    Name(Span, String),
    Group(FullStructure),
    // Char(FullCharSelector),
    Curly(Span, CurlyWrapped),
    Repeat(Span, RepeatKind) // Only once to limit ambiguous parsing
}

impl PartialEq for StructureToken {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (StructureToken::Name(_, n1), StructureToken::Name(_, n2)) => n1 == n2,
            (StructureToken::Group(g1), StructureToken::Group(g2)) => g1 == g2,
            // (StructureToken::Char(c1), StructureToken::Char(c2)) => c1 == c2,
            (StructureToken::Curly(_, c1), StructureToken::Curly(_, c2)) => c1 == c2,
            (StructureToken::Repeat(_, r1), StructureToken::Repeat(_, r2)) => r1 == r2,
            _ => false,
        }
    }
}

#[derive(Debug, PartialEq, Clone)]
pub struct FullStructure {
    pub tokens: Vec<StructureToken>,
}

#[derive(Debug, PartialEq, Clone)]
pub struct IntermediateFullStructure {
    pub tokens: Vec<IntermediateToken>,
}

#[derive(Debug, PartialEq, Clone)]
pub enum IntermediateToken {
    Literal(String),
    Group(IntermediateFullStructure),
    Repeat(Box<IntermediateToken>, RepeatKind),
    Custom(CustomToken),
}

#[derive(Debug, PartialEq, Clone)]
pub struct ParseHandler {
    pub prefix: Vec<IntermediateToken>,
    pub repeat: Option<(Vec<IntermediateToken>, RepeatKind)>,
    pub suffix: Vec<IntermediateToken>,
}