oni_comb_parser_rs/extension/parsers/
element_parsers.rs

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use crate::core::{Element, Parsers};
use crate::utils::Set;
use std::fmt::{Debug, Display};

pub trait ElementParsers: Parsers {
  fn elm_any_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a, {
    Self::elm_pred_ref(|_| true)
  }

  fn elm_any<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_any_ref(), Clone::clone)
  }

  fn elm_ref<'a, I>(element: I) -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a, {
    Self::elm_pred_ref(move |actual| *actual == element)
  }

  fn elm<'a, I>(element: I) -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_ref(element), Clone::clone)
  }

  fn elm_pred_ref<'a, I, F>(f: F) -> Self::P<'a, I, &'a I>
  where
    F: Fn(&I) -> bool + 'a,
    I: Element + PartialEq + 'a;

  fn elm_pred<'a, I, F>(f: F) -> Self::P<'a, I, I>
  where
    F: Fn(&I) -> bool + 'a,
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_pred_ref(f), Clone::clone)
  }

  fn elm_space_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_space<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_space_ref(), Clone::clone)
  }

  fn elm_multi_space_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_multi_space<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_multi_space_ref(), Clone::clone)
  }

  fn elm_alpha_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_alpha<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_alpha_ref(), Clone::clone)
  }

  fn elm_alpha_digit_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_alpha_digit<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_alpha_digit_ref(), Clone::clone)
  }

  fn elm_digit_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_digit<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_digit_ref(), Clone::clone)
  }

  fn elm_hex_digit_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_hex_digit<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_hex_digit_ref(), Clone::clone)
  }

  fn elm_oct_digit_ref<'a, I>() -> Self::P<'a, I, &'a I>
  where
    I: Element + PartialEq + 'a;

  fn elm_oct_digit<'a, I>() -> Self::P<'a, I, I>
  where
    I: Element + Clone + PartialEq + 'a, {
    Self::map(Self::elm_oct_digit_ref(), Clone::clone)
  }

  fn elm_ref_of<'a, I, S>(set: &'a S) -> Self::P<'a, I, &'a I>
  where
    I: PartialEq + Display + Debug + 'a,
    S: Set<I> + ?Sized;

  fn elm_of<'a, I, S>(set: &'a S) -> Self::P<'a, I, I>
  where
    I: PartialEq + Clone + Display + Debug + 'a,
    S: Set<I> + ?Sized, {
    Self::map(Self::elm_ref_of(set), Clone::clone)
  }

  fn elm_ref_in<'a, I>(start: I, end: I) -> Self::P<'a, I, &'a I>
  where
    I: PartialEq + PartialOrd + Display + Debug + Copy + 'a;

  fn elm_in<'a, I>(start: I, end: I) -> Self::P<'a, I, I>
  where
    I: PartialEq + PartialOrd + Display + Debug + Copy + Clone + 'a, {
    Self::map(Self::elm_ref_in(start, end), Clone::clone)
  }

  fn elm_ref_from_until<'a, I>(start: I, end: I) -> Self::P<'a, I, &'a I>
  where
    I: PartialEq + PartialOrd + Display + Debug + Copy + 'a;

  fn elm_from_until<'a, I>(start: I, end: I) -> Self::P<'a, I, I>
  where
    I: PartialEq + PartialOrd + Display + Debug + Copy + Clone + 'a, {
    Self::map(Self::elm_ref_from_until(start, end), Clone::clone)
  }

  fn none_ref_of<'a, I, S>(set: &'a S) -> Self::P<'a, I, &'a I>
  where
    I: PartialEq + Display + Debug + 'a,
    S: Set<I> + ?Sized;

  fn none_of<'a, I, S>(set: &'a S) -> Self::P<'a, I, I>
  where
    I: PartialEq + Display + Clone + Debug + 'a,
    S: Set<I> + ?Sized, {
    Self::map(Self::none_ref_of(set), Clone::clone)
  }
}