anyxml_automata/
lib.rs

1//! Provides implementation of finite automata.
2//!
3//! One goal is to provide content models in DTD element type declarations
4//! and regular expression implementations that conform to the XML Schema specification.  
5//!
6//! In addition, we provide an AST that expresses such regular expressions and a library
7//! that constructs finite automata from the AST.  
8//! Users of the library can use these features to implement their own regular expression parsers.
9
10pub mod ast;
11pub mod content_model;
12pub mod fa;
13pub mod unicode;
14pub mod util;
15pub mod xsregexp;
16
17pub trait Atom: Clone + Copy + PartialOrd + Ord + PartialEq + Eq + Default {
18    const MIN: Self;
19    const MAX: Self;
20    const EPSILON: Self;
21
22    fn previous(&self) -> Option<Self>;
23    fn next(&self) -> Option<Self>;
24}
25
26impl Atom for char {
27    const MIN: Self = '\x01';
28    const MAX: Self = char::MAX;
29    // Since NULL characters are not used in XML, it should be fine for internal use...
30    const EPSILON: Self = char::MIN;
31
32    fn previous(&self) -> Option<Self> {
33        (char::MIN..*self).next_back()
34    }
35
36    fn next(&self) -> Option<Self> {
37        let mut range = *self..;
38        range.next(); // current char
39        range.next()
40    }
41}