Update copyright year.
[m17n/m17n-db.git] / MIM / th-pattachote.mim
1 ;; th-pattachote.mim -- Thai input method with Pattachote keyboard layout
2 ;; Copyright (C) 2006, 2007, 2008, 2009
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 ;; 02110-1301, USA.
23
24 (input-method th pattachote)
25
26 (description "Thai input method simulating the Pattachote keyboard
27 with WTT 2.0 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 (variable
35  (level (_"Acceptance level
36 The level of character sequence acceptance defined in WTT 2.0.
37 0 accepts any key sequence.  2 accepts only orthographic ones.
38 1 is somewhere between.")
39         1 0 1 2))
40
41 (include (th kesmanee) macro)
42
43 (map
44  (map
45   ("!" "+")
46   ("\"" "ฑ")
47   ("#" "/")
48   ("$" ",")
49   ("%" "?")
50   ("&" "_")
51   ("'" "ข")
52   ("(" "(")
53   (")" ")")
54   ("*" ".")
55   ("+" "%")
56   ("," "ะ")
57   ("-" "๑")
58   ("." "จ")
59   ("/" "พ")
60   ("0" "๐")
61   ("1" "=")
62   ("2" "๒")
63   ("3" "๓")
64   ("4" "๔")
65   ("5" "๕")
66   ("6" "ู")
67   ("7" "๗")
68   ("8" "๘")
69   ("9" "๙")
70   (":" "ฆ")
71   (";" "ไ")
72   ("<" "ฟ")
73   ("=" "๖")
74   (">" "ฉ")
75   ("?" "ฬ")
76   ("@" "\"")
77   ("A" "๋")
78   ("B" "ฺ")
79   ("C" "ฐ")
80   ("D" "ำ")
81   ("E" "ๆ")
82   ("F" "ณ")
83   ("G" "์")
84   ("H" "ื")
85   ("I" "ซ")
86   ("J" "ผ")
87   ("K" "ช")
88   ("L" "โ")
89   ("M" "ฮ")
90   ("N" "ศ")
91   ("O" "ถ")
92   ("P" "ฒ")
93   ("Q" "๊")
94   ("R" "ญ")
95   ("S" "ธ")
96   ("T" "ษ")
97   ("U" "ฝ")
98   ("V" "ภ")
99   ("W" "ฤ")
100   ("X" "ฏ")
101   ("Y" "ึ")
102   ("Z" "ฎ")
103   ("[" "ใ")
104   ("\\" "ๅ")
105   ("]" "ฌ")
106   ("^" "ุ")
107   ("_" "-")
108   ("`" "_")
109   ("a" "้")
110   ("b" "ิ")
111   ("c" "ล")
112   ("d" "ง")
113   ("e" "ย")
114   ("f" "ก")
115   ("g" "ั")
116   ("h" "ี")
117   ("i" "ม")
118   ("j" "า")
119   ("k" "น")
120   ("l" "เ")
121   ("m" "ส")
122   ("n" "ค")
123   ("o" "ว")
124   ("p" "แ")
125   ("q" "็")
126   ("r" "อ")
127   ("s" "ท")
128   ("t" "ร")
129   ("u" "ด")
130   ("v" "ห")
131   ("w" "ต")
132   ("x" "ป")
133   ("y" "่")
134   ("z" "บ")
135   ("{" "ฯ")
136   ("|" "ํ")
137   ("}" "ฦ")
138   ("~" "฿")))
139
140 (state
141
142  (init
143   (map
144    (delete @<)
145    (pushback 1)
146    (shift main)))
147  
148  (main
149   (map
150    (set x @-3)
151    (set y @-2)
152    (set z @-1)
153
154    (set arg1 y)
155    (set arg2 z)
156    (cp)
157    (cond
158     ((= ret 1)) ;; CP(y,z) succeeded.
159     (1
160      (ac)
161      (cond
162       ((= ret 1)) ;; AC(y,z) succeeded.
163       (1
164        ;; WTT-based input sequence correction starts here.
165
166        ;; begin
167        ;; if CP(x,z) then
168        (set arg1 x)
169        (set arg2 z)
170        (cp)
171        (cond
172         ((= ret 1)
173
174          ;; if CP(z,y) then
175          (set arg1 z)
176          (set arg2 y)
177          (cp)
178          (cond
179           ((= ret 1)
180
181            ;; reorder(y -> zy)
182            (delete @-2)
183            (insert z)
184            (insert y))
185
186           ;; elif CP(x,y) then
187           (1
188            (set arg1 x)
189            (set arg2 y)
190            (cp)
191            (cond
192             ((= ret 1)
193
194              ;; replace(y -> z)
195              (delete @-2)
196              (insert z))
197
198             ;; elif y is FV1 and z is TONE then
199             ((& (| (= y 0x0E30) (= y 0x0E32) (= y 0x0E33))
200                 (>= z 0x0E48)
201                 (<= z 0x0E4B))
202
203              ;; reorder(y -> zy)
204              (delete @-2)
205              (insert z)
206              (insert y))
207
208             ;; else
209             ;; reject(z)
210             (1
211              (delete @-1))
212
213             ;;endif
214             ))))
215
216         ;; elif AC(x,z) then
217         (1
218          (set arg1 x)
219          (set arg2 z)
220          (ac)
221          (cond
222           ((& (= ret 1)
223               ;; Only Thai characters should be replaced.
224               (& (>= y 0x0E01) (<= y 0x0E5B))
225               (& (>= z 0x0E01) (<= z 0x0E5B)))
226
227            ;; replace(y -> z)
228            (delete @-2)
229            (insert z))
230
231           ;; else
232           ;; reject(z)
233           (1
234            (delete @-1))
235
236           ;; endif
237           )))
238        ;; end
239
240        ))))
241
242    ;; Now we commit the preedit chars that are fixed.
243    (set w @-1)
244    (cond
245     ;; If surrounding text is supported, commit the only char in preedit.
246     ((> @-0 -2)
247      (commit))
248
249     ;; If the last char is CTRL or NON, we can commit everything.
250     ((| (& (>= w 0x0000) (<= w 0x0E00))
251         (= w 0x0E2F)
252         (= w 0x0E3F)
253         (= w 0x0E46)
254         (>= w 0x0E4F))
255      (commit))
256
257     ;; If the last char is CONS, we can commit everything but the last
258     ;; unless the second last is FV3.
259     ((| (& (>= w 0x0E01) (<= w 0x0E23))
260         (= w 0x0E25)
261         (& (>= w 0x0E27) (<= w 0x0E2E)))
262      (cond
263       ((| (= @-2 0x0E24) (= @-2 0x0E26))
264        ; not commit yet
265        )
266       (1
267        (delete @-1)
268        (commit)
269        (insert w))))
270
271     ;; If the last char is LV, FV2 or FV3, we can commit
272     ;; everything but the last.
273     ((| (& (>= w 0x0E40) (<= w 0x0E45))
274         (= w 0x0E24)
275         (= w 0x0E26))
276      (delete @-1)
277      (commit)
278      (insert w))
279
280     ;; If the last char is FV1 (excluding AM) and ...
281     ((| (= w 0x0E30) (= w 0x0E32))
282      (delete @-1)
283      (set v @-1)
284      (cond
285
286       ;; ... the before last is CONS, we can commit other than the
287       ;; last two.
288       ((| (& (>= v 0x0E01) (<= v 0x0E23))
289           (= v 0x0E25)
290           (& (>= v 0x0E27) (<= v 0x0E2E)))
291        (delete @-1)
292        (commit)
293        (insert v)
294        (insert w))
295
296       ;; ... else if the before last is not CONS, we can commit
297       ;; everything but the last.
298       (1
299        (commit)
300        (insert w))))
301     ))))
302
303 ;; Local Variables:
304 ;; coding: utf-8
305 ;; mode: emacs-lisp
306 ;; End: