1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum Concept {
17 Lit,
20 Class,
22 Alt,
24 Group,
26 Seq,
28 Use,
30 Until,
32 Times,
34 Optional,
36 Name,
38 Regex,
40
41 Min,
44 Max,
46
47 Digit,
50 Alpha,
52 Space,
54 Word,
56 Any,
58
59 Eol,
62}
63
64pub trait KeywordTable {
68 fn lookup(&self, word: &str) -> Option<Concept>;
69}
70
71pub struct StaticTable {
73 entries: &'static [(&'static str, Concept)],
74}
75
76impl StaticTable {
77 pub const fn new(entries: &'static [(&'static str, Concept)]) -> Self {
78 Self { entries }
79 }
80}
81
82impl KeywordTable for StaticTable {
83 fn lookup(&self, word: &str) -> Option<Concept> {
84 self.entries
85 .iter()
86 .find(|(w, _)| *w == word)
87 .map(|(_, c)| *c)
88 }
89}
90
91use Concept::*;
92
93pub const CHINESE: StaticTable = StaticTable::new(&[
95 ("字面", Lit),
96 ("类", Class),
97 ("任一", Alt),
98 ("组", Group),
99 ("序列", Seq),
100 ("用", Use),
101 ("直到", Until),
102 ("次", Times),
103 ("可选", Optional),
104 ("名", Name),
105 ("正则", Regex),
106 ("最小", Min),
107 ("最大", Max),
108 ("数字", Digit),
109 ("字母", Alpha),
110 ("空白", Space),
111 ("字", Word),
112 ("任意", Any),
113 ("行尾", Eol),
114 ("末尾", Eol),
115]);
116
117pub const ENGLISH: StaticTable = StaticTable::new(&[
119 ("lit", Lit),
120 ("literal", Lit),
121 ("class", Class),
122 ("alt", Alt),
123 ("any-of", Alt),
124 ("group", Group),
125 ("seq", Seq),
126 ("use", Use),
127 ("until", Until),
128 ("times", Times),
129 ("repeat", Times),
130 ("optional", Optional),
131 ("name", Name),
132 ("regex", Regex),
133 ("re", Regex),
134 ("min", Min),
135 ("max", Max),
136 ("digit", Digit),
137 ("alpha", Alpha),
138 ("space", Space),
139 ("word", Word),
140 ("any", Any),
141 ("eol", Eol),
142 ("end", Eol),
143]);
144
145pub const BILINGUAL: StaticTable = StaticTable::new(&[
150 ("字面", Lit),
152 ("类", Class),
153 ("任一", Alt),
154 ("组", Group),
155 ("序列", Seq),
156 ("用", Use),
157 ("直到", Until),
158 ("次", Times),
159 ("可选", Optional),
160 ("名", Name),
161 ("正则", Regex),
162 ("最小", Min),
163 ("最大", Max),
164 ("数字", Digit),
165 ("字母", Alpha),
166 ("空白", Space),
167 ("字", Word),
168 ("任意", Any),
169 ("行尾", Eol),
170 ("末尾", Eol),
171 ("lit", Lit),
173 ("literal", Lit),
174 ("class", Class),
175 ("alt", Alt),
176 ("any-of", Alt),
177 ("group", Group),
178 ("seq", Seq),
179 ("use", Use),
180 ("until", Until),
181 ("times", Times),
182 ("repeat", Times),
183 ("optional", Optional),
184 ("name", Name),
185 ("regex", Regex),
186 ("re", Regex),
187 ("min", Min),
188 ("max", Max),
189 ("digit", Digit),
190 ("alpha", Alpha),
191 ("space", Space),
192 ("word", Word),
193 ("any", Any),
194 ("eol", Eol),
195 ("end", Eol),
196]);