*** empty log message ***
[elisp/tamago.git] / its / aynu.el
1 ;;; its/aynu.el --- Aynu Katakana Input in Egg Input Method Architecture
2
3 ;; Copyright (C) 1999,2000 PFU LIMITED
4
5 ;; Author: KATAYAMA Yoshio <kate@pfu.co.jp>
6
7 ;; Maintainer: TOMURA Satoru <tomura@etl.go.jp>
8
9 ;; Keywords: mule, multilingual, input method
10
11 ;; This file is part of EGG.
12
13 ;; EGG is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; EGG is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30
31 ;;; Code:
32
33 (eval-when-compile
34   (require 'its)
35   (require 'cl))
36
37 (eval-when (compile)
38   (defconst its-compaction-enable t))
39
40 (defvar its-aynu-enable-zenkaku-alphabet
41   (if (boundp 'its-enable-fullwidth-alphabet)
42       its-enable-fullwidth-alphabet
43     t)
44   "*Enable Zenkaku alphabet")
45
46 (defvar its-aynu-horizontal      "\e$(O!<\e(B" "*-")      ; "-" "\e$(O!=\e(B"
47 (defvar its-aynu-period          "\e$(O!#\e(B " "*.")     ; "." "\e$(O!#\e(B"
48 (defvar its-aynu-comma           "\e$(O!$\e(B " "*,")     ; "," "\e$(O!$\e(B"
49 (defvar its-aynu-open-bracket    "\e$(O!V\e(B" "*[")      ; "\e$(O!N\e(B"
50 (defvar its-aynu-close-bracket   "\e$(O!W\e(B" "*]")      ; "\e$(O!O\e(B"
51
52 (defvar its-aynu-enable-double-n nil "*Enable \"nn\" input for \"\e$(O%s\e(B\"")
53
54 (defvar its-aynu-kick-conversion-on-space nil "*Start conversion on SPACE")
55
56 (eval-when-compile
57   (defun its-define-state-aynu (input i-tail output o-tail otherwise)
58     "Define following rules:
59 INPUT + I-TAIL            --> OUTPUT + O-TAIL
60 INPUT + I-TAIL + '        --> OUTPUT + O-TAIL
61 INPUT + I-TAIL + vowel    --> (translate INPUT) + I-tail + vowel
62 INPUT + I-TAIL + OTHERWISE  (see `its-defrule-otherwise')."
63     (let ((out (concat output o-tail))
64           state)
65       (setq state (its-defrule (concat input i-tail) out))
66       (its-defrule (concat input i-tail "'") out)
67       (its-defrule-otherwise state nil "[aiueo]" -2)
68       (while otherwise
69         (its-defrule-otherwise state (concat output (caar otherwise))
70                                (nth 1 (car otherwise)) (nth 2 (car otherwise)))
71         (setq otherwise (cdr otherwise)))
72       (setq state (its-defrule (concat input i-tail "y") (concat out "\e$(O%#\e(B")))
73       (its-make-next-state state -1 out -1)
74       (its-defrule-otherwise state out nil -2)
75       (its-defrule-otherwise state nil "[u]" -3)
76 ))
77
78   (defconst its-aynu-tail-alist
79     (let ((common '(("k" "\e$(O&n\e(B" (("\e$(O%C\e(B" "[k]"  -1)))
80                     ("s" "\e$(O&o\e(B" (("\e$(O%C\e(B" "[s]"  -1) (nil "[h]" -2)))
81                     ("p" "\e$(O&x\e(B" (("\e$(O%C\e(B" "[p]"  -1)))
82                     ("m" "\e$(O&y\e(B" (("\e$(O%s\e(B" "[mp]" -1)))
83                     ("t" "\e$(O%C\e(B") ("y" "\e$(O%#\e(B") ("w" "\e$(O%%\e(B"))))
84       `((?a ("h" "\e$(O&s\e(B") ("x" "\e$(O&s\e(B") ("r" "\e$(O&z\e(B") ,@common)
85         (?i ("h" "\e$(O&t\e(B") ("x" "\e$(O&t\e(B") ("r" "\e$(O&{\e(B") ,@common)
86         (?u ("h" "\e$(O&u\e(B") ("x" "\e$(O&u\e(B") ("r" "\e$(O&|\e(B") ,@common)
87         (?e ("h" "\e$(O&v\e(B") ("x" "\e$(O&v\e(B") ("r" "\e$(O&}\e(B") ,@common)
88         (?o ("h" "\e$(O&w\e(B") ("x" "\e$(O&w\e(B") ("r" "\e$(O&~\e(B") ,@common))))
89
90   (defun its-defrule-aynu (conso vowel output)
91     (let ((input (concat conso vowel))
92           (tails (and vowel (cdr (assq (aref vowel 0) its-aynu-tail-alist)))))
93       (its-defrule input output)
94       (while tails
95         (its-define-state-aynu input (caar tails) output (nth 1 (car tails))
96                                (nth 2 (car tails)))
97         (setq tails (cdr tails)))))
98
99   (defmacro its-define-aynu (&rest rules)
100     (let ((defs (list 'progn))
101           conso vowels output)
102       (while rules
103         (setq vowels '(nil "a" "i" "u" "e" "o")
104               conso  (caar rules)
105               output (cdar rules)
106               rules (cdr rules))
107         (while output
108           (when (car output)
109             (setq defs (cons `(its-defrule-aynu ,conso ,(car vowels)
110                                                 ,(car output))
111                              defs)))
112           (setq output (cdr output)
113                 vowels (cdr vowels))))
114       (nreverse defs)))
115
116   (defun its-defrule-aynu-override-yu (conso)
117     (let ((output (its-get-output (its-goto-state conso)))
118           state)
119       (its-defrule (concat conso "yu")
120                    (concat (its-get-output (its-goto-state (concat conso "i")))
121                            "\e$(O%e!<\e(B"))
122       (setq state (its-goto-state (concat conso "y")))
123       (its-set-output state (concat output "\e$(O%#\e(B"))
124       (its-make-next-state state -1 output -1)
125       (its-defrule-otherwise state output nil -2))))
126
127 (define-its-state-machine its-aynu-map
128   "roma-aynu-kata" "\e$(O%"\e(B" Aynu
129   "Map for Romaji-Aynu-Katakana translation. (Japanese)"
130
131   (defconst its-zenkaku-escape "Z")  ;; Escape character to Zenkaku inputs
132   (defconst its-hankaku-escape "~")  ;; Escape character to Hankaku inputs
133
134   (its-defrule-select-mode-temporally "q" downcase)
135   (its-defrule-select-mode-temporally "Q" zenkaku-downcase)
136
137   (dolist (small '(("a"  "\e$(O%!\e(B") ("i"  "\e$(O%#\e(B") ("u"  "\e$(O%%\e(B") ("e"  "\e$(O%'\e(B") ("o"  "\e$(O%)\e(B")
138                    ("ka" "\e$(O%u\e(B")             ("ku" "\e$(O&n\e(B") ("ke" "\e$(O%v\e(B")
139                                ("si" "\e$(O&o\e(B") ("su" "\e$(O&p\e(B")
140                                            ("tu" "\e$(O%C\e(B")             ("to" "\e$(O&q\e(B")
141                                            ("nu" "\e$(O&r\e(B")
142                    ("ha" "\e$(O&s\e(B") ("hi" "\e$(O&t\e(B") ("hu" "\e$(O&u\e(B") ("he" "\e$(O&v\e(B") ("ho" "\e$(O&w\e(B")
143                                            ("pu" "\e$(O&x\e(B")
144                                            ("mu" "\e$(O&y\e(B")
145                    ("ya" "\e$(O%c\e(B")             ("yu" "\e$(O%e\e(B")             ("yo" "\e$(O%g\e(B")
146                    ("ra" "\e$(O&z\e(B") ("ri" "\e$(O&{\e(B") ("ru" "\e$(O&|\e(B") ("re" "\e$(O&}\e(B") ("ro" "\e$(O&~\e(B")
147                    ("wa" "\e$(O%n\e(B")))
148     (its-defrule (concat "x" (car small)) (cadr small)))
149
150   (its-define-aynu
151    (""   nil    "\e$(O%"\e(B"   "\e$(O%$\e(B"   "\e$(O%&\e(B"   "\e$(O%(\e(B"   "\e$(O%*\e(B")
152    ("k"  "\e$(O&n\e(B"            "\e$(O%+\e(B"   "\e$(O%-\e(B"   "\e$(O%/\e(B"   "\e$(O%1\e(B"   "\e$(O%3\e(B")
153    ("g"  "\e$(O%0\e(B"   "\e$(O%,\e(B"   "\e$(O%.\e(B"   "\e$(O%0\e(B"   "\e$(O%2\e(B"   "\e$(O%4\e(B")
154    ("s"  "\e$(O&p\e(B"            "\e$(O%5\e(B"   "\e$(O%7\e(B"   "\e$(O%9\e(B"   "\e$(O%;\e(B"   "\e$(O%=\e(B")
155    ("z"  nil    "\e$(O%6\e(B"   "\e$(O%8\e(B"   "\e$(O%:\e(B"   "\e$(O%<\e(B"   "\e$(O%>\e(B")
156    ("vs" nil    nil    nil    nil    "\e$(O%|\e(B"   nil)
157    ("sh" "\e$(O%7%c\e(B" "\e$(O%7%c\e(B" "\e$(O%7\e(B"   "\e$(O%7%e\e(B" "\e$(O%7%'\e(B" "\e$(O%7%g\e(B")
158    ("j"  nil    "\e$(O%8%c\e(B" "\e$(O%8\e(B"   "\e$(O%8%e\e(B" "\e$(O%8%'\e(B" "\e$(O%8%g\e(B")
159    ("t"  "\e$(O%C\e(B"   "\e$(O%?\e(B"   "\e$(O%A\e(B"   "\e$(O%H%%\e(B" "\e$(O%F\e(B"   "\e$(O%H\e(B")
160    ("vt" nil    nil    nil    "\e$(O%}\e(B"   nil    "\e$(O%~\e(B")
161    ("d"  nil    "\e$(O%@\e(B"   "\e$(O%B\e(B"   "\e$(O%E\e(B"   "\e$(O%G\e(B"   "\e$(O%I\e(B")
162    ("c"  "\e$(O%C\e(B"   "\e$(O%A%c\e(B" "\e$(O%A\e(B"   "\e$(O%A%e\e(B" "\e$(O%A%'\e(B" "\e$(O%A%g\e(B")
163    ("ch" "\e$(O%C\e(B"   "\e$(O%A%c\e(B" "\e$(O%A\e(B"   "\e$(O%A%e\e(B" "\e$(O%A%'\e(B" "\e$(O%A%g\e(B")
164    ("n"  "\e$(O%s\e(B"   "\e$(O%J\e(B"   "\e$(O%K\e(B"   "\e$(O%L\e(B"   "\e$(O%M\e(B"   "\e$(O%N\e(B")
165    ("h"  "\e$(O&s\e(B"   "\e$(O%O\e(B"   "\e$(O%R\e(B"   "\e$(O%U\e(B"   "\e$(O%X\e(B"   "\e$(O%[\e(B")
166    ("b"  nil    "\e$(O%P\e(B"   "\e$(O%S\e(B"   "\e$(O%V\e(B"   "\e$(O%Y\e(B"   "\e$(O%\\e(B")
167    ("p"  "\e$(O&x\e(B"   "\e$(O%Q\e(B"   "\e$(O%T\e(B"   "\e$(O%W\e(B"   "\e$(O%Z\e(B"   "\e$(O%]\e(B")
168    ("m"  "\e$(O&y\e(B"   "\e$(O%^\e(B"   "\e$(O%_\e(B"   "\e$(O%`\e(B"   "\e$(O%a\e(B"   "\e$(O%b\e(B")
169    ("y"  "\e$(O%#\e(B"   "\e$(O%d\e(B"   "\e$(O%#\e(B"   "\e$(O%f\e(B"   "\e$(O%$%'\e(B" "\e$(O%h\e(B")
170    ("r"  "\e$(O&|\e(B"   "\e$(O%i\e(B"   "\e$(O%j\e(B"   "\e$(O%k\e(B"   "\e$(O%l\e(B"   "\e$(O%m\e(B")
171    ("w"  "\e$(O%%\e(B"   "\e$(O%o\e(B"   "\e$(O%&%#\e(B" "\e$(O%%\e(B"   "\e$(O%&%'\e(B" "\e$(O%&%)\e(B"))
172
173   (dolist (yu '("k" "g" "s" "z" "sh" "j" "t" "d"
174                 "c" "ch" "n" "h" "b" "p" "m" "r"))
175     (its-defrule-aynu-override-yu yu))
176
177   (its-defrule "kk" "\e$(O%C\e(B" -1)
178   (its-defrule "ss" "\e$(O%C\e(B" -1)
179   (its-defrule "pp" "\e$(O%C\e(B" -1)
180   (its-defrule "vv" "\e$(O%C\e(B" -1)
181
182 ;; SYMBOL Input
183   (its-defrule   "z1"   "\e$(O!{\e(B")    (its-defrule   "z!"   "\e$(O!|\e(B")
184   (its-defrule   "z2"   "\e$(O"&\e(B")    (its-defrule   "z@"   "\e$(O"'\e(B")
185   (its-defrule   "z3"   "\e$(O"$\e(B")    (its-defrule   "z#"   "\e$(O"%\e(B")
186   (its-defrule   "z4"   "\e$(O""\e(B")    (its-defrule   "z$"   "\e$(O"#\e(B")
187   (its-defrule   "z5"   "\e$(O!~\e(B")    (its-defrule   "z%"   "\e$(O"!\e(B")
188   (its-defrule   "z6"   "\e$(O!y\e(B")    (its-defrule   "z^"   "\e$(O!z\e(B")
189   (its-defrule   "z7"   "\e$(O!}\e(B")    (its-defrule   "z&"   "\e$(O!r\e(B")
190   (its-defrule   "z8"   "\e$(O!q\e(B")    (its-defrule   "z*"   "\e$(O!_\e(B")
191   (its-defrule   "z9"   "\e$(O!i\e(B")    (its-defrule   "z("   "\e$(O!Z\e(B")
192   (its-defrule   "z0"   "\e$(O!j\e(B")    (its-defrule   "z)"   "\e$(O![\e(B")
193   (its-defrule   "z-"   "\e$(O!A\e(B")    (its-defrule   "z_"   "\e$(O!h\e(B")
194   (its-defrule   "z="   "\e$(O!b\e(B")    (its-defrule   "z+"   "\e$(O!^\e(B")
195   (its-defrule   "z\\"  "\e$(O!@\e(B")    (its-defrule   "z|"   "\e$(O!B\e(B")
196   (its-defrule   "z`"   "\e$(O!-\e(B")    (its-defrule   "z~"   "\e$(O!/\e(B")
197
198   (its-defrule   "zq"   "\e$(O!T\e(B")    (its-defrule   "zQ"   "\e$(O!R\e(B")
199   (its-defrule   "zw"   "\e$(O!U\e(B")    (its-defrule   "zW"   "\e$(O!S\e(B")
200                                         ; e
201   (its-defrule   "zr"   "\e$(O!9\e(B")    (its-defrule   "zR"   "\e$(O!8\e(B")
202   (its-defrule   "zt"   "\e$(O!:\e(B")    (its-defrule   "zT"   "\e$(O!x\e(B")
203                                         ; y u i o
204   (its-defrule   "zp"   "\e$(O")\e(B")    (its-defrule   "zP"   "\e$(O",\e(B")
205   (its-defrule   "z["   "\e$(O!X\e(B")    (its-defrule   "z{"   "\e$(O!L\e(B")
206   (its-defrule   "z]"   "\e$(O!Y\e(B")    (its-defrule   "z}"   "\e$(O!M\e(B")
207                                         ; a
208   (its-defrule   "zs"   "\e$(O!3\e(B")    (its-defrule   "zS"   "\e$(O!4\e(B")
209   (its-defrule   "zd"   "\e$(O!5\e(B")    (its-defrule   "zD"   "\e$(O!6\e(B")
210   (its-defrule   "zf"   "\e$(O!7\e(B")    (its-defrule   "zF"   "\e$(O"*\e(B")
211   (its-defrule   "zg"   "\e$(O!>\e(B")    (its-defrule   "zG"   "\e$(O!=\e(B")
212   (its-defrule   "zh"   "\e$(O"+\e(B")
213   (its-defrule   "zj"   "\e$(O"-\e(B")
214   (its-defrule   "zk"   "\e$(O",\e(B")
215   (its-defrule   "zl"   "\e$(O"*\e(B")
216   (its-defrule   "z;"   "\e$(O!+\e(B")    (its-defrule   "z:"   "\e$(O!,\e(B")
217   (its-defrule   "z\'"  "\e$(O!F\e(B")    (its-defrule   "z\""  "\e$(O!H\e(B")
218                                         ; z
219   (its-defrule   "zx"   ":-")   (its-defrule   "zX"   ":-)")
220   (its-defrule   "zc"   "\e$(O!;\e(B")    (its-defrule   "zC"   "\e$(O!n\e(B")
221   (its-defrule   "zv"   "\e$(O"(\e(B")    (its-defrule   "zV"   "\e$(O!`\e(B")
222   (its-defrule   "zb"   "\e$(O!k\e(B")    (its-defrule   "zB"   "\e$(O"+\e(B")
223   (its-defrule   "zn"   "\e$(O!l\e(B")    (its-defrule   "zN"   "\e$(O"-\e(B")
224   (its-defrule   "zm"   "\e$(O!m\e(B")    (its-defrule   "zM"   "\e$(O".\e(B")
225   (its-defrule   "z,"   "\e$(O!E\e(B")    (its-defrule   "z<"   "\e$(O!e\e(B")
226   (its-defrule   "z."   "\e$(O!D\e(B")    (its-defrule   "z>"   "\e$(O!f\e(B")
227   (its-defrule   "z/"   "\e$(O!&\e(B")    (its-defrule   "z?"   "\e$(O!g\e(B")
228   )
229
230 (define-its-state-machine-append its-aynu-map
231   (if its-aynu-enable-double-n
232       (its-defrule "nn" "\e$(O%s\e(B"))
233
234   (its-defrule "-" its-aynu-horizontal)
235   (its-defrule "." its-aynu-period)
236   (its-defrule "," its-aynu-comma)
237   (its-defrule "[" its-aynu-open-bracket)
238   (its-defrule "]" its-aynu-close-bracket)
239
240   (unless its-aynu-kick-conversion-on-space
241     (its-defrule " " " "))
242
243   (if its-aynu-enable-zenkaku-alphabet
244       (progn
245         (its-defrule   "1"   "\e$(O#1\e(B")  (its-defrule   "2"   "\e$(O#2\e(B")
246         (its-defrule   "3"   "\e$(O#3\e(B")  (its-defrule   "4"   "\e$(O#4\e(B")
247         (its-defrule   "5"   "\e$(O#5\e(B")  (its-defrule   "6"   "\e$(O#6\e(B")
248         (its-defrule   "7"   "\e$(O#7\e(B")  (its-defrule   "8"   "\e$(O#8\e(B")
249         (its-defrule   "9"   "\e$(O#9\e(B")  (its-defrule   "0"   "\e$(O#0\e(B")
250         (its-defrule   "!"   "\e$(O!*\e(B")  (its-defrule   "@"   "\e$(O!w\e(B")
251         (its-defrule   "#"   "\e$(O!t\e(B")  (its-defrule   "$"   "\e$(O!p\e(B")
252         (its-defrule   "%"   "\e$(O!s\e(B")  (its-defrule   "^"   "\e$(O!0\e(B")
253         (its-defrule   "&"   "\e$(O!u\e(B")  (its-defrule   "*"   "\e$(O!v\e(B")
254         (its-defrule   "("   "\e$(O!J\e(B")  (its-defrule   ")"   "\e$(O!K\e(B")
255         (its-defrule   "="   "\e$(O!a\e(B")  (its-defrule   "`"   "\e$(O!.\e(B")
256         (its-defrule   "\\"  "\e$(O!o\e(B")  (its-defrule   "|"   "\e$(O!C\e(B")
257         (its-defrule   "_"   "\e$(O!2\e(B")  (its-defrule   "+"   "\e$(O!\\e(B")
258         (its-defrule   "{"   "\e$(O!P\e(B")  (its-defrule   "}"   "\e$(O!Q\e(B")
259         (its-defrule   ":"   "\e$(O!'\e(B")  (its-defrule   ";"   "\e$(O!(\e(B")
260         (its-defrule   "\""  "\e$(O!I\e(B")  (its-defrule   "'"   "\e$(O!G\e(B")
261         (its-defrule   "<"   "\e$(O!c\e(B")  (its-defrule   ">"   "\e$(O!d\e(B")
262         (its-defrule   "?"   "\e$(O!)\e(B")  (its-defrule   "/"   "\e$(O!?\e(B"))
263     (progn
264       (its-defrule   "1"   "1")  (its-defrule   "2"   "2")
265       (its-defrule   "3"   "3")  (its-defrule   "4"   "4")
266       (its-defrule   "5"   "5")  (its-defrule   "6"   "6")
267       (its-defrule   "7"   "7")  (its-defrule   "8"   "8")
268       (its-defrule   "9"   "9")  (its-defrule   "0"   "0")
269       (its-defrule   "!"   "!")  (its-defrule   "@"   "@")
270       (its-defrule   "#"   "#")  (its-defrule   "$"   "$")
271       (its-defrule   "%"   "%")  (its-defrule   "^"   "^")
272       (its-defrule   "&"   "&")  (its-defrule   "*"   "*")
273       (its-defrule   "("   "(")  (its-defrule   ")"   ")")
274       (its-defrule   "="   "=")  (its-defrule   "`"   "`")
275       (its-defrule   "\\"  "\\") (its-defrule   "|"   "|")
276       (its-defrule   "_"   "_")  (its-defrule   "+"   "+")
277       (its-defrule   "{"   "{")  (its-defrule   "}"   "}")
278       (its-defrule   ":"   ":")  (its-defrule   ";"   ";")
279       (its-defrule   "\""  "\"") (its-defrule   "'"   "'")
280       (its-defrule   "<"   "<")  (its-defrule   ">"   ">")
281       (its-defrule   "?"   "?")  (its-defrule   "/"   "/"))))
282
283 (provide 'its/aynu)
284
285 ;;; its/aynu.el ends here