214 new Recoder(mapping map { case (x, y) => (y, x) })) |
216 new Recoder(mapping map { case (x, y) => (y, x) })) |
215 } |
217 } |
216 |
218 |
217 def decode(text: String): String = decoder.recode(text) |
219 def decode(text: String): String = decoder.recode(text) |
218 def encode(text: String): String = encoder.recode(text) |
220 def encode(text: String): String = encoder.recode(text) |
|
221 |
|
222 |
|
223 /* classification */ |
|
224 |
|
225 private val raw_letters = Set( |
|
226 "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", |
|
227 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", |
|
228 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", |
|
229 "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", |
|
230 |
|
231 "\\<A>", "\\<B>", "\\<C>", "\\<D>", "\\<E>", "\\<F>", "\\<G>", |
|
232 "\\<H>", "\\<I>", "\\<J>", "\\<K>", "\\<L>", "\\<M>", "\\<N>", |
|
233 "\\<O>", "\\<P>", "\\<Q>", "\\<R>", "\\<S>", "\\<T>", "\\<U>", |
|
234 "\\<V>", "\\<W>", "\\<X>", "\\<Y>", "\\<Z>", "\\<a>", "\\<b>", |
|
235 "\\<c>", "\\<d>", "\\<e>", "\\<f>", "\\<g>", "\\<h>", "\\<i>", |
|
236 "\\<j>", "\\<k>", "\\<l>", "\\<m>", "\\<n>", "\\<o>", "\\<p>", |
|
237 "\\<q>", "\\<r>", "\\<s>", "\\<t>", "\\<u>", "\\<v>", "\\<w>", |
|
238 "\\<x>", "\\<y>", "\\<z>", |
|
239 |
|
240 "\\<AA>", "\\<BB>", "\\<CC>", "\\<DD>", "\\<EE>", "\\<FF>", |
|
241 "\\<GG>", "\\<HH>", "\\<II>", "\\<JJ>", "\\<KK>", "\\<LL>", |
|
242 "\\<MM>", "\\<NN>", "\\<OO>", "\\<PP>", "\\<QQ>", "\\<RR>", |
|
243 "\\<SS>", "\\<TT>", "\\<UU>", "\\<VV>", "\\<WW>", "\\<XX>", |
|
244 "\\<YY>", "\\<ZZ>", "\\<aa>", "\\<bb>", "\\<cc>", "\\<dd>", |
|
245 "\\<ee>", "\\<ff>", "\\<gg>", "\\<hh>", "\\<ii>", "\\<jj>", |
|
246 "\\<kk>", "\\<ll>", "\\<mm>", "\\<nn>", "\\<oo>", "\\<pp>", |
|
247 "\\<qq>", "\\<rr>", "\\<ss>", "\\<tt>", "\\<uu>", "\\<vv>", |
|
248 "\\<ww>", "\\<xx>", "\\<yy>", "\\<zz>", |
|
249 |
|
250 "\\<alpha>", "\\<beta>", "\\<gamma>", "\\<delta>", "\\<epsilon>", |
|
251 "\\<zeta>", "\\<eta>", "\\<theta>", "\\<iota>", "\\<kappa>", |
|
252 "\\<mu>", "\\<nu>", "\\<xi>", "\\<pi>", "\\<rho>", "\\<sigma>", |
|
253 "\\<tau>", "\\<upsilon>", "\\<phi>", "\\<chi>", "\\<psi>", |
|
254 "\\<omega>", "\\<Gamma>", "\\<Delta>", "\\<Theta>", "\\<Lambda>", |
|
255 "\\<Xi>", "\\<Pi>", "\\<Sigma>", "\\<Upsilon>", "\\<Phi>", |
|
256 "\\<Psi>", "\\<Omega>", |
|
257 |
|
258 "\\<^isub>", "\\<^isup>") |
|
259 |
|
260 private val letters = raw_letters ++ raw_letters.map(decode(_)) |
|
261 |
|
262 def is_letter(sym: String): Boolean = letters.contains(sym) |
|
263 |
|
264 def is_digit(sym: String): Boolean = |
|
265 if (sym.length == 1) { |
|
266 val c = sym(0) |
|
267 '0' <= c && c <= '9' |
|
268 } |
|
269 else false |
|
270 |
|
271 def is_quasi(sym: String): Boolean = sym == "_" || sym == "'" |
|
272 |
|
273 |
|
274 private val raw_blanks = |
|
275 Set(" ", "\t", "\n", "\u000B", "\f", "\r", "\\<spacespace>", "\\<^newline>") |
|
276 private val blanks = raw_blanks ++ raw_blanks.map(decode(_)) |
|
277 |
|
278 def is_blank(sym: String): Boolean = blanks.contains(sym) |
219 } |
279 } |
220 } |
280 } |