Big changes; tripple-vowel handling, escape
[m17n/m17n-db.git] / MIM / vi-telex.mim
1 ;; vi-telex.mim -- Input method for Vietnames with TELEX key sequence
2 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007
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 Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 (input-method vi telex)
25
26 (description "Vietnames input method using the TELEX key sequence.
27 ")
28
29 (title "Ắ")
30
31 (variable
32  (tone-mark-on-last
33   "Flag to control tone mark position.
34 If this variable is 0 (the default), put tone mark on the first vowel
35 in such equivocal cases as \"oa\", \"oe\", \"uy\".
36 Otherwise, put tone mark on the last vowel."
37   0 0 1))
38
39 (macro
40  (handle-mark
41   (delete @-)
42   (cond (T
43          ;; We have already decided on which vowel to put a tone mark.
44          (move T))
45         (V-3
46          ;; Tripple-vowel
47          ;; Put a tone mark on the last vowel if it is e, ê, or ơ.
48          ;; Otherwise put a tone mark on the second vowel.
49          (move M)
50          (cond ((| (= V-3 ?e) (= V-3 ?ê) (= V-3 ?ơ)
51                    (= V-3 ?E) (= V-3 ?Ê) (= V-3 ?Ơ)))
52                (1 (move @-))))
53         (V-2
54          ;; Double-vowel
55          ;; Put a tone mark on the last vowel in the following cases:
56          ;;  * The last vowel is  â, ă, ê, ô, ơ, ư, or ư.
57          ;;  * The initial consonant and the first vowel is "gi" or "qu".
58          ;;  * tone-mark-on-last is customized to 1 in a equivocal case.
59          ;; Otherwise put a tone mark on the first vowel.
60          (move M)
61          (cond ((| SPECIAL
62                    (& (| (= C ?g) (= C ?G)) (| (= V-1 ?i) (= V-1 ?I)))
63                    (& (| (= C ?q) (= C ?Q)) (| (= V-1 ?u) (= V-1 ?U)))
64                    (& (| tone-mark-on-last C-AFTER-V)
65                       (| (& (| (= V-1 ?o) (= V-1 ?O))
66                             (| (= V-2 ?a) (= V-2 ?A) (= V-2 ?e) (= V-2 ?E)))
67                          (& (| (= V-1 ?u) (= V-1 ?U))
68                             (| (= V-2 ?y) (= V-2 ?Y)))))))
69                (1 (move @-))))
70         (V-1
71          (move M)))
72   (select SELECT)
73   (mark T)
74   (move @>)))
75
76 (map
77  (vowel1 ; sfrxj
78   ("a"  ("aáàảãạ")) ("A"  ("AÁÀẢÃẠ"))
79   ("e"  ("eéèẻẽẹ")) ("E"  ("EÉÈẺẼẸ"))
80   ("i"  ("iíìỉĩị")) ("I"  ("IÍÌỈĨỊ"))
81   ("o"  ("oóòỏõọ")) ("O"  ("OÓÒỎÕỌ"))
82   ("u"  ("uúùủũụ")) ("U"  ("UÚÙỦŨỤ"))
83   ("y"  ("yýỳỷỹỵ")) ("Y"  ("YÝỲỶỸỴ")))
84
85  (vowel2 ; sfrxj   -- put mark on them if they are the last vowel
86   ("aa" ("âấầẩẫậ")) ("AA" ("ÂẤẦẨẪẬ")) ("Aa" ("ÂẤẦẨẪẬ"))
87   ("aw" ("ăắằẳẵặ")) ("AW" ("ĂẮẰẲẴẶ")) ("Aw" ("ĂẮẰẲẴẶ"))
88   ("ee" ("êếềểễệ")) ("EE" ("ÊẾỀỂỄỆ")) ("Ee" ("ÊẾỀỂỄỆ"))
89   ("oo" ("ôốồổỗộ")) ("OO" ("ÔỐỒỔỖỘ")) ("Oo" ("ÔỐỒỔỖỘ"))
90   ("ow" ("ơớờởỡợ")) ("OW" ("ƠỚỜỞỠỢ")) ("Ow" ("ƠỚỜỞỠỢ"))
91   ("uw" ("ưứừửữự")) ("UW" ("ƯỨỪỬỮỰ")) ("Uw" ("ƯỨỪỬỮỰ"))
92   ("w"  ("ưứừửữự")) ("W"  ("ƯỨỪỬỮỰ")))
93
94  (vowel3
95   ("aaa" ("aáàảãạ") ("aáàảãạ"))
96   ("AAA" ("ÂẤẦẨẪẬ") ("ÂẤẦẨẪẬ")) ("Aaa" ("ÂẤẦẨẪẬ") ("âấầẩẫậ"))
97   ("eee" ("eéèẻẽẹ") ("eéèẻẽẹ"))
98   ("EEE" ("EÉÈẺẼẸ") ("EÉÈẺẼẸ")) ("Eee" ("EÉÈẺẼẸ") ("eéèẻẽẹ"))
99   ("ooo" ("oóòỏõọ") ("oóòỏõọ"))
100   ("OOO" ("OÓÒỎÕỌ") ("OÓÒỎÕỌ")) ("Ooo" ("OÓÒỎÕỌ") ("oóòỏõọ")))
101
102  (vowelw
103   ("aww" ("aáàảãạ") "w") ("AWW" ("AÁÀẢÃẠ") "W") ("Aww" ("AÁÀẢÃẠ") "w")
104   ("oww" ("oóòỏõọ") "w") ("OWW" ("OÓÒỎÕỌ") "W") ("Oww" ("OÓÒỎÕỌ") "w")
105   ("uww" ("uúùủũụ") "w") ("UWW" ("UÚÙỦŨỤ") "W") ("Uww" ("UÚÙỦŨỤ") "w"))
106
107  (tone-mark
108   ("z" (set SELECT 0) ?z (handle-mark)) ("Z" (set SELECT 0) ?Z (handle-mark))
109   ("s" (set SELECT 1) ?s (handle-mark)) ("S" (set SELECT 1) ?S (handle-mark))
110   ("f" (set SELECT 2) ?f (handle-mark)) ("F" (set SELECT 2) ?F (handle-mark))
111   ("r" (set SELECT 3) ?r (handle-mark)) ("R" (set SELECT 3) ?R (handle-mark))
112   ("x" (set SELECT 4) ?x (handle-mark)) ("X" (set SELECT 4) ?X (handle-mark))
113   ("j" (set SELECT 5) ?j (handle-mark)) ("J" (set SELECT 5) ?J (handle-mark)))
114
115  (consonant-or-tone-mark
116   ("z" ?z) ("s" ?s) ("f" ?f) ("r" ?r) ("x" ?x) ("j" ?j)
117   ("Z" ?Z) ("S" ?S) ("F" ?F) ("R" ?R) ("X" ?X) ("J" ?J))
118
119  (cancel-tone-mark
120   ("zz" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?z)
121   ("ss" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?s)
122   ("ff" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?f)
123   ("rr" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?r)
124   ("xx" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?x)
125   ("jj" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?j)
126   ("ZZ" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?Z)
127   ("SS" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?S)
128   ("FF" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?F)
129   ("RR" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?R)
130   ("XX" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?X)
131   ("JJ" (cond ((> V-1 0) (move M) (select 0) (move @>))) ?J))
132
133  (consonant
134   ("b" ?b) ("c" ?c) ("d" ?d) ("g" ?g) ("h" ?h) ("k" ?k) ("l" ?l) ("m" ?m)
135   ("n" ?n) ("p" ?p) ("q" ?q) ("t" ?t) ("v" ?v)
136   ("dd" ?đ) ("ddd" "dd") ("ww" "w")
137   ("B" ?B) ("C" ?C) ("D" ?D) ("G" ?G) ("H" ?H) ("K" ?K) ("L" ?L) ("M" ?M)
138   ("N" ?N) ("P" ?P) ("Q" ?Q) ("T" ?T) ("V" ?V)
139   ("DD" ?Đ) ("Dd" ?Đ) ("DDD" "DD") ("Ddd" "Dd") ("WW" "W") ("Ww" "W"))
140
141  (escape
142   ("\\"))
143
144  (backspace
145   ((BackSpace) (set KK (- K 1)) (undo KK))))
146
147 (state
148  (init
149   ;; Initialize variables.  C is the initial consonant.  V-N is the
150   ;; Nth vowel.  C-AFTER-V is a flag set when a consonant is typed
151   ;; after vowel.  T is a mark positioning after a tone-marked
152   ;; character.
153   (t (set C @-1) (set V-1 0) (set V-2 0) (set V-3 0) (set C-AFTER-V 0)
154      (set T 0) (cond (ESCAPE (shift escape))))
155
156   (consonant (set K @@) (set C @-1))
157   (consonant-or-tone-mark (set K @@) (set C @-1))
158
159   ;; Mark M remembers the preedit position after the last vowel.
160   (vowel1 (set SPECIAL 0) (mark M) (set V-1 @-1) (set K @@) (shift after-v))
161   (vowel2 (set SPECIAL 1) (mark M) (set V-1 @-1) (set K @@) (shift after-v))
162   (vowel3 (set SPECIAL 0) (mark M) (set V-1 @-2) (set V-2 @-)
163           (set K @@) (shift after-vv))
164   (vowelw (set SPECIAL 0) (move @-) (mark M) (move @>) (set V-1 @-2)
165           (set K @@) (shift after-vc))
166
167   (escape (shift escape)))
168
169  ;; The state shifted to when the first vowel is typed.
170  (after-v
171   (consonant (set K @@) (shift after-vc))
172   (vowel1 (set SPECIAL 0) (mark M) (set V-2 @-1) (set K @@) (shift after-vv))
173   (vowel2 (set SPECIAL 1) (mark M) (set V-2 @-1) (set K @@) (shift after-vv))
174   (vowel3 (set SPECIAL 0) (mark M) (set V-1 V-2) (set V-2 @-2) (set V-3 @-1)
175           (set K @@) (shift after-vvv))
176   (vowelw (set SPECIAL 0) (move @-) (mark M) (move @>) (set V-2 @-2)
177           (set K @@) (shift after-vc))
178
179   (consonant-or-tone-mark (delete @-) (pushback 1) (shift after-t))
180   (backspace))
181
182  ;; The state shifted to when the second vowel is typed.
183  (after-vv
184   (consonant (set K @@) (shift after-vc))
185   (vowel1 (set SPECIAL 0) (mark M) (set V-3 @-1) (set K @@) (shift after-vvv))
186   (vowel2 (set SPECIAL 1) (mark M) (set V-3 @-1) (set K @@) (shift after-vvv))
187   (vowel3 (set SPECIAL 0) (mark M) (set V-1 V-3) (set V-2 @-2) (set V-3 @-1)
188           (set K @@) (shift after-vvv))
189   (vowelw (set SPECIAL 0) (move @-) (mark M) (move @>) (set V-3 @-2)
190           (set K @@) (shift after-vc))
191
192   (consonant-or-tone-mark (delete @-) (pushback 1) (shift after-t))
193   (backspace))
194
195  ;; The state shifted to when the third vowel is typed.
196  (after-vvv
197   (consonant (set K @@) (shift after-vc))
198   (vowel1 (set SPECIAL 0) (mark M) (set V-1 V-2) (set V-2 V-3) (set V-3 @-1)
199           (set K @@))
200   (vowel2 (set SPECIAL 0) (mark M) (set V-1 V-2) (set V-2 V-3) (set V-3 @-1)
201           (set K @@))
202   (vowel3 (set SPECIAL 0) (mark M) (set V-1 V-3) (set V-2 @-2) (set V-3 @-1)
203           (set K @@))
204   (vowelw (set SPECIAL 0) (move @-) (mark M) (move @>)
205           (set V-1 V-2) (set V-2 V-3) (set V-3 @-2) (shift after-vc) (set K @@))
206   (consonant-or-tone-mark (delete @-) (pushback 1) (shift after-t))
207   (backspace))
208
209  ;; The state shifted to when vowels and consonants are typed.
210  (after-vc
211   (t (set C-AFTER-V 1))
212   (consonant (set K @@))
213   (consonant-or-tone-mark (set K @@) (delete @-) (pushback 1) (shift after-t))
214   (backspace))
215
216  ;; The state shifted to when a tone-mark is typed.
217  (after-t
218   (tone-mark)
219   (cancel-tone-mark (cond (C-AFTER-V (shift after-vc))
220                           (V-3 (set C-AFTER-V 1) (shift after-vvv))
221                           (V-2 (set C-AFTER-V 1) (shift after-vv))
222                           (V-1 (set C-AFTER-V 1) (shift after-v))
223                           (1 (shift init))))
224   (backspace)
225   (nil (shift init)))
226
227  (escape
228   "E"
229   (t (set ESCAPE 0))
230   (escape (cond ((= ESCAPE 0) (insert "\\") (shift init))
231                 ((= ESCAPE 1) (insert "\\") (commit) (set ESCAPE 2))
232                 (1 (set ESCAPE 1))))
233   ;; Unhandle any characters.
234   (nil (cond ((= ESCAPE 1) (set ESCAPE 0) (shift init))
235              (1 (set ESCAPE 2) (unhandle))))
236
237 ;; Local Variables:
238 ;; coding: utf-8
239 ;; mode: emacs-lisp
240 ;; End: