egg-980304.
[elisp/egg.git] / its / hankata.el
1 ;;; its/hankata.el --- Hnakaku Katakana Input in Egg Input Method Architecture
2
3 ;; Copyright (C) 1997, 1998 Mule Project,
4 ;; Powered by Electrotechnical Laboratory, JAPAN.
5 ;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
6
7 ;; Author: Satoru Tomura <tomura@etl.go.jp>
8
9 ;; This file will be part of GNU Emacs (in future).
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27 ;;
28 ;; Symbol input is desined by jiro@math.keio.ac.jp (TANAKA Jiro)
29 ;; This file is based on the rules of its/kata.el in Mule-2.3 distribution.
30 ;;
31
32 ;;; Code:
33
34 (eval-when-compile
35   (require 'its)
36   (require 'cl))
37
38 (defvar its-kata-enable-double-n nil "*Enable \"nn\" input for \"\e$B%s\e(B\" ")
39 (defvar its-kata-enable-zenkaku-alphabet t "*Enable Zenkaku alphabet")
40 (defvar its-kata-period "\e(I!\e(B" "*\e$B%T%j%*%I\e(B")  ; ". " "\e$B!%\e(B"
41 (defvar its-kata-comma  "\e(I$\e(B" "*\e$B%3%s%^\e(B")    ; ", " "\e$B!$\e(B"
42 (defvar its-kata-open-bracket  "\e(I"\e(B" "*[")  ; "\e$B!N\e(B"
43 (defvar its-kata-close-bracket  "\e(I#\e(B" "*]") ; "\e$B!O\e(B"
44 (defvar its-kata-horizontal  "\e(I0\e(B" "*-")    ; "\e$B!]\e(B"
45
46 (define-its-state-machine its-han-kata-map
47   "roma-han-kata" "\e(I11\e(B" "Japanese" nil
48   "Map for Romaji-Hankaku-Katakana translation. (Japanese)"
49
50   (defconst its-hankaku-escape "~")  ;; Escape character to Hankaku inputs
51
52   (its-defrule-select-mode-temporally "q" downcase)
53
54 ;;; k      k
55 ;;; kk     \e$B%C\e(Bk
56 ;;; kka    \e$B%C%+\e(B
57 ;;;
58 ;;; kkk    \e$B%C\e(Bk DING!
59
60   (its-defrule "tch"  "\e(I/\e(B" -2)
61
62 ;;; \e$B!V%s!W$NF~NO\e(B
63
64   (dolist (q1 '("b" "m" "p"))
65     (its-defrule (concat "m" q1) "\e(I]\e(B" -1))
66
67   (its-defrule "N" "\e(I]\e(B")
68
69   (let ((state (its-goto-state "n" nil t)))
70     (its-make-next-state state -1 "n" "\e(I]\e(B")
71     (its-make-next-state state ?' "n" "\e(I]\e(B")
72     (its-defrule-otherwise state "\e(I]\e(B"))
73
74   (let ((small '"x" ))
75     (its-defrule (concat small "a") "\e(I'\e(B")
76     (its-defrule (concat small "i") "\e(I(\e(B")
77     (its-defrule (concat small "u") "\e(I)\e(B")
78     (its-defrule (concat small "e") "\e(I*\e(B")
79     (its-defrule (concat small "o") "\e(I+\e(B")
80     (its-defrule (concat small "ya") "\e(I,\e(B")
81     (its-defrule (concat small "yu") "\e(I-\e(B")
82     (its-defrule (concat small "yo") "\e(I.\e(B")
83     (its-defrule (concat small "tu") "\e(I/\e(B")
84     (its-defrule (concat small "tsu") "\e(I/\e(B")
85     (its-defrule (concat small "wa") "\e(I\\e(B")
86     )
87
88   (its-defrule   "a"    "\e(I1\e(B")
89   (its-defrule   "i"    "\e(I2\e(B")
90   (its-defrule   "u"    "\e(I3\e(B")
91   (its-defrule   "e"    "\e(I4\e(B")
92   (its-defrule   "o"    "\e(I5\e(B")
93
94   (dolist (k '(("ka"  "\e(I6\e(B") ("ki"  "\e(I7\e(B") ("ku"  "\e(I8\e(B") ("ke"  "\e(I9\e(B") ("ko"  "\e(I:\e(B")
95                ("kya" "\e(I7,\e(B") ("kyu"  "\e(I7-\e(B") ("kye"  "\e(I7*\e(B") ("kyo"  "\e(I7.\e(B")))
96     (its-defrule (car k) (cadr k))
97     (its-defrule (concat "k" (car k)) (concat "\e(I/\e(B" (cadr k))))
98   (its-defoutput "kk" "\e(I/\e(Bk")
99   (its-defoutput "kky" "\e(I/\e(Bky")
100
101   (dolist (s '(("sa"  "\e(I;\e(B") ("si"  "\e(I<\e(B") ("su"  "\e(I=\e(B") ("se"  "\e(I>\e(B") ("so"  "\e(I?\e(B")
102                ("sya"  "\e(I<,\e(B") ("syu"  "\e(I<-\e(B") ("sye"  "\e(I<*\e(B") ("syo"  "\e(I<.\e(B")
103                ("sha"  "\e(I<,\e(B") ("shi"  "\e(I<\e(B") ("shu"  "\e(I<-\e(B") ("she"  "\e(I<*\e(B")
104                ("sho"  "\e(I<.\e(B")))
105     (its-defrule (car s) (cadr s))
106     (its-defrule (concat "s" (car s)) (concat "\e(I/\e(B" (cadr s))))
107   (its-defoutput "ss" "\e(I/\e(Bs")
108   (its-defoutput "ssy" "\e(I/\e(Bsy")
109   (its-defoutput "ssh" "\e(I/\e(Bsh")
110
111   (dolist (T '(("ta"  "\e(I@\e(B") ("ti"  "\e(IA\e(B") ("tu"  "\e(IB\e(B") ("te"  "\e(IC\e(B") ("to"  "\e(ID\e(B")
112                ("tya"  "\e(IA,\e(B") ("tyi"  "\e(IC(\e(B") ("tyu"  "\e(IA-\e(B") ("tye"  "\e(IA*\e(B")
113                ("tyo"  "\e(IA.\e(B") ("tsu"  "\e(IB\e(B")))
114     (its-defrule (car T) (cadr T))
115     (its-defrule (concat "t" (car T)) (concat "\e(I/\e(B" (cadr T))))
116   (its-defoutput "tt" "\e(I/\e(Bt")
117   (its-defoutput "tty" "\e(I/\e(Bty")
118   (its-defoutput "tts" "\e(I/\e(Bts")
119
120   (dolist (c '(("cha"  "\e(IA,\e(B") ("chi"  "\e(IA\e(B") ("chu"  "\e(IA-\e(B")
121                ("che"  "\e(IA*\e(B") ("cho"  "\e(IA.\e(B")))
122     (its-defrule (car c) (cadr c))
123     (its-defrule (concat "c" (car c)) (concat "\e(I/\e(B" (cadr c))))
124   (its-defoutput "cc" "\e(I/\e(Bc")
125   (its-defoutput "cch" "\e(I/\e(Bch")
126
127   (dolist (h '(("ha"  "\e(IJ\e(B") ("hi"  "\e(IK\e(B") ("hu"  "\e(IL\e(B") ("he"  "\e(IM\e(B") ("ho"  "\e(IN\e(B")
128                ("hya"  "\e(IK,\e(B") ("hyu"  "\e(IK-\e(B") ("hye"  "\e(IK*\e(B") ("hyo"  "\e(IK.\e(B")))
129     (its-defrule (car h) (cadr h))
130     (its-defrule (concat "h" (car h)) (concat "\e(I/\e(B" (cadr h))))
131   (its-defoutput "hh" "\e(I/\e(Bh")
132   (its-defoutput "hhy" "\e(I/\e(Bhy")
133
134   (dolist (f '(("fa"  "\e(IL'\e(B") ("fi"  "\e(IL(\e(B") ("fu"  "\e(IL\e(B") ("fe"  "\e(IL*\e(B")
135                ("fo"  "\e(IL+\e(B")))
136     (its-defrule (car f) (cadr f))
137     (its-defrule (concat "f" (car f)) (concat "\e(I/\e(B" (cadr f))))
138   (its-defoutput "ff" "\e(I/\e(Bf")
139
140   (dolist (r '(("ra"  "\e(IW\e(B") ("ri"  "\e(IX\e(B") ("ru"  "\e(IY\e(B") ("re"  "\e(IZ\e(B") ("ro"  "\e(I[\e(B")
141                ("rya"  "\e(IX,\e(B") ("ryu"  "\e(IX-\e(B") ("rye"  "\e(IX*\e(B") ("ryo"  "\e(IX.\e(B")))
142     (its-defrule (car r) (cadr r))
143     (its-defrule (concat "r" (car r)) (concat "\e(I/\e(B" (cadr r))))
144   (its-defoutput "rr" "\e(I/\e(Br")
145   (its-defoutput "rry" "\e(I/\e(Bry")
146
147   (dolist (l '(("la"  "\e(IW\e(B") ("li"  "\e(IX\e(B") ("lu"  "\e(IY\e(B") ("le"  "\e(IZ\e(B") ("lo"  "\e(I[\e(B")
148                ("lya"  "\e(IX,\e(B") ("lyu"  "\e(IX-\e(B") ("lye"  "\e(IX*\e(B") ("lyo"  "\e(IX.\e(B")))
149     (its-defrule (car l) (cadr l))
150     (its-defrule (concat "l" (car l)) (concat "\e(I/\e(B" (cadr l))))
151   (its-defoutput "ll" "\e(I/\e(Bl")
152   (its-defoutput "lly" "\e(I/\e(Bly")
153
154   (dolist (g '(("ga"  "\e(I6^\e(B") ("gi"  "\e(I7^\e(B") ("gu"  "\e(I8^\e(B") ("ge"  "\e(I9^\e(B") ("go"  "\e(I:^\e(B")
155                ("gya"  "\e(I7^,\e(B") ("gyu"  "\e(I7^-\e(B") ("gye"  "\e(I7^*\e(B") ("gyo"  "\e(I7^.\e(B")))
156     (its-defrule (car g) (cadr g))
157     (its-defrule (concat "g" (car g)) (concat "\e(I/\e(B" (cadr g))))
158   (its-defoutput "gg" "\e(I/\e(Bg")
159   (its-defoutput "ggy" "\e(I/\e(Bgy")
160
161   (dolist (z '(("za"  "\e(I;^\e(B") ("zi"  "\e(I<^\e(B") ("zu"  "\e(I=^\e(B") ("ze"  "\e(I>^\e(B") ("zo"  "\e(I?^\e(B")
162                ("zya"  "\e(I<^,\e(B") ("zyu"  "\e(I<^-\e(B") ("zye"  "\e(I<^*\e(B") ("zyo"  "\e(I<^.\e(B")))
163     (its-defrule (car z) (cadr z))
164     (its-defrule (concat "z" (car z)) (concat "\e(I/\e(B" (cadr z))))
165   (its-defoutput "zz" "\e(I/\e(Bz")
166   (its-defoutput "zzy" "\e(I/\e(Bzy")
167
168   (dolist (j '(("ja"  "\e(I<^,\e(B") ("ji"  "\e(I<^\e(B") ("ju"  "\e(I<^-\e(B") ("je"  "\e(I<^*\e(B")
169                ("jo"  "\e(I<^.\e(B") ("jya"  "\e(I<^,\e(B") ("jyu"  "\e(I<^-\e(B") ("jye"  "\e(I<^*\e(B")
170                ("jyo"  "\e(I<^.\e(B")))
171     (its-defrule (car j) (cadr j))
172     (its-defrule (concat "j" (car j)) (concat "\e(I/\e(B" (cadr j))))
173   (its-defoutput "jj" "\e(I/\e(Bj")
174   (its-defoutput "jjy" "\e(I/\e(Bjy")
175
176   (dolist (d '(("da"  "\e(I@^\e(B") ("di"  "\e(IA^\e(B") ("du"  "\e(IB^\e(B") ("de"  "\e(IC^\e(B") ("do"  "\e(ID^\e(B")
177                ("dya"  "\e(IA^,\e(B") ("dyi"  "\e(IC^(\e(B") ("dyu"  "\e(IA^-\e(B") ("dye"  "\e(IA^*\e(B")
178                ("dyo"  "\e(IA^.\e(B")))
179     (its-defrule (car d) (cadr d))
180     (its-defrule (concat "d" (car d)) (concat "\e(I/\e(B" (cadr d))))
181   (its-defoutput "dd" "\e(I/\e(Bd")
182   (its-defoutput "ddy" "\e(I/\e(Bdy")
183
184   (dolist (b '(("ba"  "\e(IJ^\e(B") ("bi"  "\e(IK^\e(B") ("bu"  "\e(IL^\e(B") ("be"  "\e(IM^\e(B") ("bo"  "\e(IN^\e(B")
185                ("bya"  "\e(IK^,\e(B") ("byu"  "\e(IK^-\e(B") ("bye"  "\e(IK^*\e(B") ("byo"  "\e(IK^.\e(B")))
186     (its-defrule (car b) (cadr b))
187     (its-defrule (concat "b" (car b)) (concat "\e(I/\e(B" (cadr b))))
188   (its-defoutput "bb" "\e(I/\e(Bb")
189   (its-defoutput "bby" "\e(I/\e(Bby")
190
191   (dolist (p '(("pa"  "\e(IJ_\e(B") ("pi"  "\e(IK_\e(B") ("pu"  "\e(IL_\e(B") ("pe"  "\e(IM_\e(B") ("po"   "\e(IN_\e(B")
192                ("pya"  "\e(IK_,\e(B") ("pyu"  "\e(IK_-\e(B") ("pye"  "\e(IK_*\e(B") ("pyo"  "\e(IK_.\e(B")))
193     (its-defrule (car p) (cadr p))
194     (its-defrule (concat "p" (car p)) (concat "\e(I/\e(B" (cadr p))))
195   (its-defoutput "pp" "\e(I/\e(Bp")
196   (its-defoutput "ppy" "\e(I/\e(Bpy")
197
198   (dolist (v '(("va" "\e(I3^'\e(B") ("vi" "\e(I3^(\e(B") ("vu" "\e(I3^\e(B") ("ve" "\e(I3^*\e(B")
199                ("vo" "\e(I3^+\e(B")))
200     (its-defrule (car v) (cadr v))
201     (its-defrule (concat "v" (car v)) (concat "\e(I/\e(B" (cadr v))))
202   (its-defoutput "vv" "\e(I/\e(Bv")
203
204   (its-defrule   "ma"   "\e(IO\e(B")
205   (its-defrule   "mi"   "\e(IP\e(B")
206   (its-defrule   "mu"   "\e(IQ\e(B")
207   (its-defrule   "me"   "\e(IR\e(B")
208   (its-defrule   "mo"   "\e(IS\e(B")
209   (its-defrule   "mya"  "\e(IP,\e(B")
210   (its-defrule   "myu"  "\e(IP-\e(B")
211   (its-defrule   "mye"  "\e(IP*\e(B")
212   (its-defrule   "myo"  "\e(IP.\e(B")
213   (its-defrule   "ya"   "\e(IT\e(B")
214   (its-defrule   "yi"   "\e(I2\e(B")
215   (its-defrule   "yu"   "\e(IU\e(B")
216   (its-defrule   "yo"   "\e(IV\e(B")
217   (its-defrule   "ye"   "\e(I2*\e(B")
218   (its-defrule   "wa"   "\e(I\\e(B")
219   (its-defrule   "wi"   "\e(I(\e(B")
220   (its-defrule   "wu"   "\e(I3\e(B")
221   (its-defrule   "we"   "\e(I*\e(B")
222   (its-defrule   "wo"   "\e(I&\e(B")
223
224   (its-defrule   "kwa"  "\e(I8\\e(B")
225   (its-defrule   "kwi"  "\e(I8(\e(B")
226   (its-defrule   "kwu"  "\e(I8\e(B")
227   (its-defrule   "kwe"  "\e(I8*\e(B")
228   (its-defrule   "kwo"  "\e(I8+\e(B")
229   (its-defrule   "gwa"  "\e(I8^\\e(B")
230   (its-defrule   "gwi"  "\e(I8^(\e(B")
231   (its-defrule   "gwu"  "\e(I8^\e(B")
232   (its-defrule   "gwe"  "\e(I8^*\e(B")
233   (its-defrule   "gwo"  "\e(I8^+\e(B")
234   (its-defrule   "tsa"  "\e(IB'\e(B")
235   (its-defrule   "tsi"  "\e(IB(\e(B")
236   (its-defrule   "tse"  "\e(IB*\e(B")
237   (its-defrule   "tso"  "\e(IB+\e(B")
238
239   (its-defrule   "na"   "\e(IE\e(B")
240   (its-defrule   "ni"   "\e(IF\e(B")
241   (its-defrule   "nu"   "\e(IG\e(B")
242   (its-defrule   "ne"   "\e(IH\e(B")
243   (its-defrule   "no"   "\e(II\e(B")
244   (its-defrule   "nya"  "\e(IF,\e(B")
245   (its-defrule   "nyu"  "\e(IF-\e(B")
246   (its-defrule   "nye"  "\e(IF*\e(B")
247   (its-defrule   "nyo"  "\e(IF.\e(B")
248
249   (its-defrule   "xti"  "\e(IC(\e(B")
250   (its-defrule   "xdi"  "\e(IC^(\e(B")
251   (its-defrule   "xdu"  "\e(ID^)\e(B")
252   (its-defrule   "xde"  "\e(IC^*\e(B")
253   (its-defrule   "xdo"  "\e(ID^+\e(B")
254   (its-defrule   "xwi"  "\e(I3(\e(B")
255   (its-defrule   "xwe"  "\e(I3*\e(B")
256   (its-defrule   "xwo"  "\e(I3+\e(B")
257
258 ;;;
259 ;;; Symbol inputs
260 ;;;
261
262   (dolist (digit '( "1"  "2"  "3"  "4" "5"  "6"  "7"  "8"  "9"  "0" ))
263     (its-defrule (concat its-hankaku-escape digit)  digit))
264
265   (dolist (symbol '( " "  "!"  "@"  "#"  "$"  "%"  "^"  "&"  "*"  "("  ")"
266                      "-"  "="  "`"  "\\" "|"  "_"  "+"  "~" "["  "]"  "{"  "}"
267                      ":"  ";"  "\"" "'"  "<"  ">"  "?"  "/"  ","  "." ))
268     (its-defrule (concat its-hankaku-escape symbol) symbol))
269
270   (dolist (downcase '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
271                       "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))
272     (its-defrule (concat its-hankaku-escape downcase) downcase))
273
274   (dolist (upcase    '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N"
275                        "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
276     (its-defrule (concat its-hankaku-escape upcase) upcase)))
277
278 (define-its-state-machine-append its-han-kata-map
279   (if its-kata-enable-double-n
280       (its-defrule "nn" "\e(I]\e(B")
281     (its-defrule "nn" "\e(I]\e(B" -1))
282
283   (its-defrule "-" its-kata-horizontal)
284   (its-defrule "[" its-kata-open-bracket)
285   (its-defrule "]" its-kata-close-bracket)
286   (its-defrule "." its-kata-period)
287   (its-defrule "," its-kata-comma)
288   )
289
290 (provide 'its/hankata)
291 ;;; its/kata.el ends here.