*** empty log message ***
[m17n/m17n-db.git] / th-tis820.mim
1 ;; th-tis820.mim -- Thai input method with TIS-820.2538 keyboard layout
2 ;; Copyright (C) 2006
3 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
4 ;;   Registration Number H15PRO112
5
6 ;; This file is part of the m17n database; a sub-part of the m17n
7 ;; library.
8
9 ;; The m17n library is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU Lesser General Public License
11 ;; as published by the Free Software Foundation; either version 2.1 of
12 ;; the License, or (at your option) any later version.
13
14 ;; The m17n library is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; Lesser General Public License for more details.
18
19 ;; You should have received a copy of the GNU Lesser General Public
20 ;; License along with the m17n library; if not, write to the Free
21 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 ;; Boston, MA 02110-1301, USA.
23
24 (input-method th tis820)
25
26 (description "Thai input method simulating the TIS-820.2538 keyboard
27 with WTT 2.0 level 1 input sequence correction.
28 The correction algorithm follows the one shown in the following 
29   <http://linux.thai.net/~thep/th-xim/>
30 ")
31
32 (title "ท")
33
34 (map
35  (map
36   ("!" "ๅ")
37   ("\"" ".")
38   ("#" "๒")
39   ("$" "๓")
40   ("%" "๔")
41   ("&" "๎")
42   ("'" "ง")
43   ("(" "๖")
44   (")" "๗")
45   ("*" "๕")
46   ("+" "๙")
47   ("," "ม")
48   ("-" "ข")
49   ("." "ใ")
50   ("/" "ฝ")
51   ("0" "จ")
52   ("1" "฿")
53   ("2" "/")
54   ("3" "-")
55   ("4" "ภ")
56   ("5" "ถ")
57   ("6" "ุ")
58   ("7" "ึ")
59   ("8" "ค")
60   ("9" "ต")
61   (":" "ซ")
62   (";" "ว")
63   ("<" "ฒ")
64   ("=" "ช")
65   (">" "ฬ")
66   ("?" "ฦ")
67   ("@" "๑")
68   ("A" "ฤ")
69   ("B" "ฺ")
70   ("C" "ฉ")
71   ("D" "ฏ")
72   ("E" "ฎ")
73   ("F" "โ")
74   ("G" "ฌ")
75   ("H" "็")
76   ("I" "ณ")
77   ("J" "๋")
78   ("K" "ษ")
79   ("L" "ศ")
80   ("M" "?")
81   ("N" "์")
82   ("O" "ฯ")
83   ("P" "ญ")
84   ("Q" "๐")
85   ("R" "ฑ")
86   ("S" "ฆ")
87   ("T" "ธ")
88   ("U" "๊")
89   ("V" "ฮ")
90   ("W" "\"")
91   ("X" ")")
92   ("Y" "ํ")
93   ("Z" "(")
94   ("[" "บ")
95   ("\\" "ฅ")
96   ("]" "ล")
97   ("^" "ู")
98   ("_" "๘")
99   ("`" "๏")
100   ("a" "ฟ")
101   ("b" "ิ")
102   ("c" "แ")
103   ("d" "ก")
104   ("e" "ำ")
105   ("f" "ด")
106   ("g" "เ")
107   ("h" "้")
108   ("i" "ร")
109   ("j" "่")
110   ("k" "า")
111   ("l" "ส")
112   ("m" "ท")
113   ("n" "ื")
114   ("o" "น")
115   ("p" "ย")
116   ("q" "ๆ")
117   ("r" "พ")
118   ("s" "ห")
119   ("t" "ะ")
120   ("u" "ี")
121   ("v" "อ")
122   ("w" "ไ")
123   ("x" "ป")
124   ("y" "ั")
125   ("z" "ผ")
126   ("{" "ฐ")
127   ("|" "ฃ")
128   ("}" ",")
129   ("~" "๛")))
130
131 (include (th kesmanee) macro)
132
133 (state
134
135  (init
136   (map
137    (delete @<)
138    (pushback 1)
139    (cond
140     ((= @-1 -2) (shift nst))
141     (1 (shift st)))))
142  
143  ;; no surrounding text
144  (nst
145   (t
146    (set x -1)
147    (set y -1))
148
149   (map
150    (set z @-)
151    (set arg1 y)
152    (set arg2 z)
153    (cp)
154    (cond
155     ((= ret 1) ;; CP(y,z) succeeded.
156      (set x y)
157      (set y z))
158     (1
159      (ac)
160      (cond
161       ((= ret 1) ;; AC(y,z) succeeded.
162        (set x y)
163        (set y z))
164       (1
165        ;; WTT-based input sequence correction starts here.
166
167        ;; begin
168        ;; if CP(x,z) then
169        (set arg1 x)
170        (set arg2 z)
171        (cp)
172        (cond
173         ((= ret 1)
174
175          ;; if CP(z,y) then
176          (set arg1 z)
177          (set arg2 y)
178          (cp)
179          (cond
180           ((= ret 1)
181
182            ;; reorder(y -> zy)
183            (delete @-)
184            (delete @-)
185            (insert z)
186            (insert y)
187            (set x z))
188
189           ;; elif CP(x,y) then
190           (1
191            (set arg1 x)
192            (set arg2 y)
193            (cp)
194            (cond
195             ((= ret 1)
196
197              ;; replace(y -> z)
198              (delete @-)
199              (delete @-)
200              (insert z)
201              (set y z))
202
203             ;; elif y is FV1 and z is TONE then
204             ((& (| (= y 0x0E30) (= y 0x0E32) (= y 0x0E33))
205                 (>= z 0x0E48)
206                 (<= z 0x0E4B))
207
208              ;; reorder(y -> zy)
209              (delete @-)
210              (delete @-)
211              (insert z)
212              (insert y)
213              (set x z))
214
215             ;; else
216             ;; reject(z)
217             (1
218              (delete @-))
219
220             ;;endif
221             ))))
222
223         ;; elif AC(x,z) then
224         (1
225          (set arg1 x)
226          (set arg2 z)
227          (ac)
228          (cond
229           ((& (= ret 1)
230               ;; CTRL, NON and CONS should not be replaced.
231               (| (= y 0x0E24)
232                  (= y 0x0E26)
233                  (& (>= y 0x0E30) (<= y 0x0E3A))
234                  (& (>= y 0x0E40) (<= y 0x0E45))
235                  (& (>= y 0x0E47) (<= y 0x0E4E)))
236               (| (= z 0x0E24)
237                  (= z 0x0E26)
238                  (& (>= z 0x0E30) (<= z 0x0E3A))
239                  (& (>= z 0x0E40) (<= z 0x0E45))
240                  (& (>= z 0x0E47) (<= z 0x0E4E))))
241
242            ;; replace(y -> z)
243            (delete @-)
244            (delete @-)
245            (insert z)
246            (set y z))
247
248           ;; else
249           ;; reject(z)
250           (1
251            (delete @-))
252
253           ;; endif
254           )))
255        ;; end
256
257        ))))
258
259    ;; Commit the preedit chars as soon as fixed.
260    (set w @-)
261    (cond
262     ;; If the last char is CTRL or NON, we can commit everything.
263     ((| (& (>= w 0x0000) (<= w 0x0E00))
264         (= w 0x0E2F)
265         (= w 0x0E3F)
266         (= w 0x0E46)
267         (>= w 0x0E4F))
268      (commit))
269
270     ;; If the last char is CONS, LV, FV2 or FV3, we can commit
271     ;; everything but the last.
272     ((| (& (>= w 0x0E01) (<= w 0x0E2E))
273         (& (>= w 0x0E40) (<= w 0x0E45)))
274      (delete @-)
275      (commit)
276      (insert w))
277
278     ;; If the last char is FV1 (excluding AM) and ...
279     ((| (= w 0x0E30) (= w 0x0E32))
280      (delete @-)
281      (set v @-)
282      (cond
283
284       ;; ... the before last is CONS, we can commit other than the
285       ;; last two.
286       ((| (& (>= v 0x0E01) (<= v 0x0E23))
287           (= v 0x0E25)
288           (& (>= v 0x0E27) (<= v 0x0E2E)))
289        (delete @-)
290        (commit)
291        (insert v)
292        (insert w))
293
294       ;; ... else if the before last is not CONS, we can commit
295       ;; everything but the last.
296       (1
297        (commit)
298        (insert w))))
299     )))
300
301  ;; with surrounding text
302  (st
303   (map
304    ;; z = next character
305    (set z @-)
306    ;; y = previous character
307    (set y @-1)
308    ;; x = character previous to y
309    (set x @-2)
310
311    (set arg1 y)
312    (set arg2 z)
313    (cp)
314    (cond
315     ((= ret 1)) ;; CP(y,z) succeeded.
316     (1
317      (ac)
318      (cond
319       ((= ret 1)) ;; AC(y,z) succeeded.
320       (1
321        ;; WTT-based input sequence correction starts here.
322
323        ;; begin
324        ;; if CP(x,z) then
325        (set arg1 x)
326        (set arg2 z)
327        (cp)
328        (cond
329         ((= ret 1)
330
331          ;; if CP(z,y) then
332          (set arg1 z)
333          (set arg2 y)
334          (cp)
335          (cond
336           ((= ret 1)
337
338            ;; reorder(y -> zy)
339            (delete @-)
340            (delete @-1)
341            (insert z)
342            (insert y))
343
344           ;; elif CP(x,y) then
345           (1
346            (set arg1 x)
347            (set arg2 y)
348            (cp)
349            (cond
350             ((= ret 1)
351
352              ;; replace(y -> z)
353              (delete @-)
354              (delete @-1)
355              (insert z))
356
357             ;; elif y is FV1 and z is TONE then
358             ((& (| (= y 0x0E30) (= y 0x0E32) (= y 0x0E33))
359                 (>= z 0x0E48)
360                 (<= z 0x0E4B))
361
362              ;; reorder(y -> zy)
363              (delete @-)
364              (delete @-1)
365              (insert z)
366              (insert y))
367
368             ;; else
369             ;; reject(z)
370             (1
371              (delete @-))
372
373             ;;endif
374             ))))
375
376         ;; elif AC(x,z) then
377         (1
378          (set arg1 x)
379          (set arg2 z)
380          (ac)
381          (cond
382           ((& (= ret 1)
383               ;; CTRL, NON and CONS should not be replaced.
384               (| (= y 0x0E24)
385                  (= y 0x0E26)
386                  (& (>= y 0x0E30) (<= y 0x0E3A))
387                  (& (>= y 0x0E40) (<= y 0x0E45))
388                  (& (>= y 0x0E47) (<= y 0x0E4E)))
389               (| (= z 0x0E24)
390                  (= z 0x0E26)
391                  (& (>= z 0x0E30) (<= z 0x0E3A))
392                  (& (>= z 0x0E40) (<= z 0x0E45))
393                  (& (>= z 0x0E47) (<= z 0x0E4E))))
394
395            ;; replace(y -> z)
396            (delete @-)
397            (delete @-1)
398            (insert z))
399
400           ;; else
401           ;; reject(z)
402           (1
403            (delete @-))
404
405           ;; endif
406           )))
407        ;; end
408
409        ))))
410    (commit)
411    )))
412
413 ;; Local Variables:
414 ;; mode: emacs-lisp
415 ;; End: