1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Phonetic regular expression support.
//!
//! This module provides a parser and AST for phonetic regex patterns,
//! supporting both standard regex constructs and phonetic rewrite rules.
//!
//! # Syntax
//!
//! ## Standard Regex
//!
//! | Syntax | Description | Example |
//! |--------|-------------|---------|
//! | `abc` | Literal characters | `phone` |
//! | `a\|b` | Alternation | `ph\|f` |
//! | `(...)` | Grouping | `(ph\|f)one` |
//! | `[abc]` | Character class | `[aeiou]` |
//! | `[^abc]` | Negated class | `[^aeiou]` |
//! | `[a-z]` | Character range | `[a-z]` |
//! | `.` | Any character | `a.b` |
//! | `*` | Zero or more | `a*` |
//! | `+` | One or more | `a+` |
//! | `?` | Zero or one | `a?` |
//! | `{n}` | Exactly n | `a{3}` |
//! | `{n,}` | At least n | `a{2,}` |
//! | `{,m}` | At most m | `a{,3}` |
//! | `{n,m}` | Between n and m | `a{2,4}` |
//!
//! ## Phonetic Extensions
//!
//! | Syntax | Description | Example |
//! |--------|-------------|---------|
//! | `a -> b` | Rewrite rule | `ph -> f` |
//! | `/ _X` | Right context (lookahead) | `c -> s / _[ei]` |
//! | `/ X_` | Left context (lookbehind) | `s -> z / [aeiou]_` |
//! | `#` | Word boundary | `e -> / _#` |
//! | `[w]` | Weight/cost | `th -> t [0.15]` |
//!
//! # Examples
//!
//! ## Parsing a simple pattern
//!
//! ```ignore
//! use liblevenshtein::phonetic::regex::parse;
//!
//! let pattern = parse("(ph|f)one").unwrap();
//! assert_eq!(pattern.to_string(), "((ph|f))one");
//! ```
//!
//! ## Parsing a rewrite rule
//!
//! ```ignore
//! use liblevenshtein::phonetic::regex::parse_rule;
//!
//! // ph -> f (phone -> fone)
//! let rule = parse_rule("ph -> f").unwrap();
//! assert!(rule.is_rewrite_rule());
//!
//! // c -> s before e or i (city -> sity)
//! let rule = parse_rule("c -> s / _[ei]").unwrap();
//!
//! // Silent e at word end (phone -> phon)
//! let rule = parse_rule("e -> / _#").unwrap();
//! ```
//!
//! ## Parsing multiple rules
//!
//! ```ignore
//! use liblevenshtein::phonetic::regex::parse_rules;
//!
//! let rules = parse_rules(r#"
//! ph -> f
//! c -> s / _[ei]
//! e -> / _#
//! "#).unwrap();
//! assert_eq!(rules.len(), 3);
//! ```
//!
//! # Design
//!
//! The parser is a recursive descent parser that produces an AST representation.
//! The AST can then be compiled to an NFA using the `nfa::compiler` module.
//!
//! Following the codebase pattern, both character-level (`Regex`, `Parser`) and
//! byte-level (`RegexByte`, `ParserByte`) implementations are provided.
// Re-export main types (character-level)
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export byte-level types
pub use ;
pub use ;
pub use ;