Merge the surrounding text version and the preedit version.
[m17n/m17n-db.git] / th-kesmanee.mim
1 ;; th-kesmanee.mim -- Thai input method with Kesmanee keyboard layout
2 ;; Copyright (C) 2003, 2004, 2005, 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., 59 Temple Place, Suite 330, Boston, MA
22 ;; 02111-1307, USA.
23
24 (input-method th kesmanee)
25
26 (description "Thai input method simulating the Kesmanee 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 (macro
132
133  ;; input global variable : arg1, arg2
134  ;; output global variable : ret
135  (cp
136   (set ret 0)
137   (cond
138
139    ;; next = BV1|BV2|BD|AD3|AV1|AV2|AV3, previous = CONS
140    ((| (= arg2 0x0E31)
141        (& (>= arg2 0x0E34) (<= arg2 0x0E3A))
142        (= arg2 0x0E4E))
143     (cond
144      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
145          (= arg1 0x0E25)
146          (& (>= arg1 0x0E27) (<= arg1 0x0E2E)))
147       (set ret 1))))
148
149    ;; next = TONE, previous = CONS|BV1|BV2|AV1|AV2|AV3
150    ((& (>= arg2 0x0E48) (<= arg2 0x0E4B))
151     (cond
152      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
153          (= arg1 0x0E25)
154          (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
155          (= arg1 0x0E31)
156          (& (>= arg1 0x0E34) (<= arg1 0x0E39)))
157       (set ret 1))))
158
159    ;; next = AD1, previous = CONS|BV1|AV1
160    ((& (>= arg2 0x0E4C) (<= arg2 0x0E4D))
161     (cond
162      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
163          (= arg1 0x0E25)
164          (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
165          (= arg1 0x0E38)
166          (= arg1 0x0E34))
167       (set ret 1))))
168
169    ;; next = AD2, previous = TONE| AV3
170    ((= arg2 0x0E47)
171     (cond
172      ((| (& (>= arg1 0x0E01) (<= arg1 0x0E23))
173          (= arg1 0x0E25)
174          (& (>= arg1 0x0E27) (<= arg1 0x0E2E))
175          (= arg1 0x0E35)
176          (= arg1 0x0E37))
177       (set ret 1))))))
178
179  ;; input global variable : arg1, arg2
180  ;; output global variable : ret
181  ;; This is Level 1 acceptance.
182  (ac
183   (set ret 1)
184   (cond
185    ((| (= arg2 0x0E31)
186        (& (>= arg2 0x0E34) (<= arg2 0x0E3A))
187        (& (>= arg2 0x0E47) (<= arg2 0x0E4E)))
188     (set ret 0)))))   
189
190 (state
191
192  (init
193   (map
194    (delete @<)
195    (pushback 1)
196    (shift main)))
197  
198  (main
199   (map
200    (set x @-3)
201    (set y @-2)
202    (set z @-1)
203
204    (set arg1 y)
205    (set arg2 z)
206    (cp)
207    (cond
208     ((= ret 1)) ;; CP(y,z) succeeded.
209     (1
210      (ac)
211      (cond
212       ((= ret 1)) ;; AC(y,z) succeeded.
213       (1
214        ;; WTT-based input sequence correction starts here.
215
216        ;; begin
217        ;; if CP(x,z) then
218        (set arg1 x)
219        (set arg2 z)
220        (cp)
221        (cond
222         ((= ret 1)
223
224          ;; if CP(z,y) then
225          (set arg1 z)
226          (set arg2 y)
227          (cp)
228          (cond
229           ((= ret 1)
230
231            ;; reorder(y -> zy)
232            (delete @-2)
233            (insert z)
234            (insert y))
235
236           ;; elif CP(x,y) then
237           (1
238            (set arg1 x)
239            (set arg2 y)
240            (cp)
241            (cond
242             ((= ret 1)
243
244              ;; replace(y -> z)
245              (delete @-2)
246              (insert z))
247
248             ;; elif y is FV1 and z is TONE then
249             ((& (| (= y 0x0E30) (= y 0x0E32) (= y 0x0E33))
250                 (>= z 0x0E48)
251                 (<= z 0x0E4B))
252
253              ;; reorder(y -> zy)
254              (delete @-2)
255              (insert z)
256              (insert y))
257
258             ;; else
259             ;; reject(z)
260             (1
261              (delete @-1))
262
263             ;;endif
264             ))))
265
266         ;; elif AC(x,z) then
267         (1
268          (set arg1 x)
269          (set arg2 z)
270          (ac)
271          (cond
272           ((& (= ret 1)
273               ;; Only Thai characters should be replaced.
274               (& (>= y 0x0E01) (<= y 0x0E5B))
275               (& (>= z 0x0E01) (<= z 0x0E5B)))
276
277            ;; replace(y -> z)
278            (delete @-2)
279            (insert z))
280
281           ;; else
282           ;; reject(z)
283           (1
284            (delete @-1))
285
286           ;; endif
287           )))
288        ;; end
289
290        ))))
291
292    ;; Commit the preedit chars that are fixed.
293    (set w @-1)
294    (cond
295     ;; If surrounding text is supported, commit the only char in preedit.
296     ((> @-0 -2)
297      (commit))
298
299     ;; If the last char is CTRL or NON, we can commit everything.
300     ((| (& (>= w 0x0000) (<= w 0x0E00))
301         (= w 0x0E2F)
302         (= w 0x0E3F)
303         (= w 0x0E46)
304         (>= w 0x0E4F))
305      (commit))
306
307     ;; If the last char is CONS, LV, FV2 or FV3, we can commit
308     ;; everything but the last.
309     ((| (& (>= w 0x0E01) (<= w 0x0E2E))
310         (& (>= w 0x0E40) (<= w 0x0E45)))
311      (delete @-1)
312      (commit)
313      (insert w))
314
315     ;; If the last char is FV1 (excluding AM) and ...
316     ((| (= w 0x0E30) (= w 0x0E32))
317      (delete @-1)
318      (set v @-1)
319      (cond
320
321       ;; ... the before last is CONS, we can commit other than the
322       ;; last two.
323       ((| (& (>= v 0x0E01) (<= v 0x0E23))
324           (= v 0x0E25)
325           (& (>= v 0x0E27) (<= v 0x0E2E)))
326        (delete @-1)
327        (commit)
328        (insert v)
329        (insert w))
330
331       ;; ... else if the before last is not CONS, we can commit
332       ;; everything but the last.
333       (1
334        (commit)
335        (insert w))))
336     ))))
337
338 ;; Local Variables:
339 ;; coding: utf-8
340 ;; mode: emacs-lisp
341 ;; End: