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
//! Matching is not limited to character strings. I'm trying to make a game AI.  

//! 文字列に限らないマッチングです。 ゲームAIを作ろうとしています。  


// Publish:

//

// (1) `cargo test`

// (2) `cargo run --example example`

// (3) Open auto-generated log file. I check it.

// (4) Remove the log file.

// (5) Update `README.md`.

// (6) Version up on Cargo.toml.

// (7) `cargo doc --open`

// (8) Comit to Git-hub.

// (9) `cargo publish --dry-run`

// (10) `cargo publish`


pub mod actual_items;
pub mod actual_items_builder;
pub mod any;
pub mod any_builder;
pub mod expected_items;
pub mod expected_items_builder;
pub mod machine;
pub mod range_contains_max;
pub mod range_contains_max_builder;
pub mod repeat;
pub mod repeat_builder;

pub struct Machine {
    actual_index: usize,
    expected_index: usize,
}

pub struct ActualItemsBuilder<T> {
    items: Vec<T>,
}

pub struct ActualItems<T> {
    items: Vec<T>,
}

pub struct ExpectedItemsBuilder<T> {
    items: Vec<Expected<T>>,
}

pub struct ExpectedItems<T> {
    items: Vec<Expected<T>>,
}

/// Expected item.  

#[derive(Clone)]
pub enum Expected<T> {
    Exact(T),
    Any(Any<T>),
    RangeContainsMax(RangeContainsMax<T>),
    Repeat(Repeat<T>),
}

pub struct RangeContainsMaxBuilder<T> {
    min: Option<T>,
    max: Option<T>,
}

/// Specify by range. Includes maximum value.  

/// 範囲で指定。最大値を含みます。  

#[derive(Clone)]
pub struct RangeContainsMax<T> {
    min: Option<T>,
    max: Option<T>,
}

pub struct AnyBuilder<T> {
    items: Vec<T>,
}

#[derive(Clone)]
pub struct Any<T> {
    items: Vec<T>,
}

pub struct RepeatBuilder<T> {
    expected: Option<Box<Expected<T>>>,
    min: usize,
    max: usize,
}

#[derive(Clone)]
pub struct Repeat<T> {
    expected: Box<Expected<T>>,
    min: usize,
    max: usize,
    matched_length: usize,
}

pub enum MatchingResult {
    Ongoing,
    Matched,
    NotMatch,
}