tamago-current.diff.gz in [tamago:00423] is applied.
[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 (require 'its)
34
35 (eval-when (compile)
36   (defconst its-compaction-enable t))
37
38 (defvar its-aynu-enable-zenkaku-alphabet
39   (if (boundp 'its-enable-fullwidth-alphabet)
40       its-enable-fullwidth-alphabet
41     t)
42   "*Enable Zenkaku alphabet")
43
44 (defvar its-aynu-horizontal      "\e$(O!<\e(B" "*-")      ; "-" "\e$(O!=\e(B"
45 (defvar its-aynu-period          "\e$(O!#\e(B " "*.")     ; "." "\e$(O!#\e(B"
46 (defvar its-aynu-comma           "\e$(O!$\e(B " "*,")     ; "," "\e$(O!$\e(B"
47 (defvar its-aynu-open-bracket    "\e$(O!V\e(B" "*[")      ; "\e$(O!N\e(B"
48 (defvar its-aynu-close-bracket   "\e$(O!W\e(B" "*]")      ; "\e$(O!O\e(B"
49
50 (defvar its-aynu-enable-double-n nil "*Enable \"nn\" input for \"\e$(O%s\e(B\"")
51
52 (defvar its-aynu-kick-conversion-on-space nil "*Start conversion on SPACE")
53
54 (eval-when-compile
55   (defun its-define-state-aynu (input i-tail output o-tail otherwise)
56     "Define following rules:
57 INPUT + I-TAIL            --> OUTPUT + O-TAIL
58 INPUT + I-TAIL + '        --> OUTPUT + O-TAIL
59 INPUT + I-TAIL + vowel    --> (translate INPUT) + I-tail + vowel
60 INPUT + I-TAIL + OTHERWISE  (see `its-defrule-otherwise')."
61     (let ((out (concat output o-tail))
62           state)
63       (setq state (its-defrule (concat input i-tail) out))
64       (its-defrule (concat input i-tail "'") out)
65       (its-defrule-otherwise state nil "[aiueo]" -2)
66       (while otherwise
67         (its-defrule-otherwise state (concat output (caar otherwise))
68                                (nth 1 (car otherwise)) (nth 2 (car otherwise)))
69         (setq otherwise (cdr otherwise)))
70       (setq state (its-defrule (concat input i-tail "y") (concat out "\e$(O%#\e(B")))
71       (its-make-next-state state -1 out -1)
72       (its-defrule-otherwise state out nil -2)
73       (its-defrule-otherwise state nil "[u]" -3)
74 ))
75
76   (defconst its-aynu-tail-alist
77     (let ((common '(("k" "\e$(O&n\e(B" (("\e$(O%C\e(B" "[k]"  -1)))
78                     ("s" "\e$(O&o\e(B" (("\e$(O%C\e(B" "[s]"  -1) (nil "[h]" -2)))
79                     ("p" "\e$(O&x\e(B" (("\e$(O%C\e(B" "[p]"  -1)))
80                     ("m" "\e$(O&y\e(B" (("\e$(O%s\e(B" "[mp]" -1)))
81                     ("t" "\e$(O%C\e(B") ("y" "\e$(O%#\e(B") ("w" "\e$(O%%\e(B"))))
82       `((?a ("h" "\e$(O&s\e(B") ("x" "\e$(O&s\e(B") ("r" "\e$(O&z\e(B") ,@common)
83         (?i ("h" "\e$(O&t\e(B") ("x" "\e$(O&t\e(B") ("r" "\e$(O&{\e(B") ,@common)
84         (?u ("h" "\e$(O&u\e(B") ("x" "\e$(O&u\e(B") ("r" "\e$(O&|\e(B") ,@common)
85         (?e ("h" "\e$(O&v\e(B") ("x" "\e$(O&v\e(B") ("r" "\e$(O&}\e(B") ,@common)
86         (?o ("h" "\e$(O&w\e(B") ("x" "\e$(O&w\e(B") ("r" "\e$(O&~\e(B") ,@common))))
87
88   (defun its-defrule-aynu (conso vowel output)
89     (let ((input (concat conso vowel))
90           (tails (and vowel (cdr (assq (aref vowel 0) its-aynu-tail-alist)))))
91       (its-defrule input output)
92       (while tails
93         (its-define-state-aynu input (caar tails) output (nth 1 (car tails))
94                                (nth 2 (car tails)))
95         (setq tails (cdr tails)))))
96
97   (defmacro its-define-aynu (&rest rules)
98     (let ((defs (list 'progn))
99           conso vowels output)
100       (while rules
101         (setq vowels '(nil "a" "i" "u" "e" "o")
102               conso  (caar rules)
103               output (cdar rules)
104               rules (cdr rules))
105         (while output
106           (when (car output)
107             (setq defs (cons `(its-defrule-aynu ,conso ,(car vowels)
108                                                 ,(car output))
109                              defs)))
110           (setq output (cdr output)
111                 vowels (cdr vowels))))
112       (nreverse defs)))
113
114   (defun its-defrule-aynu-override-yu (conso)
115     (let ((output (its-get-output (its-goto-state conso)))
116           state)
117       (its-defrule (concat conso "yu")
118                    (concat (its-get-output (its-goto-state (concat conso "i")))
119                            "\e$(O%e!<\e(B"))
120       (setq state (its-goto-state (concat conso "y")))
121       (its-set-output state (concat output "\e$(O%#\e(B"))
122       (its-make-next-state state -1 output -1)
123       (its-defrule-otherwise state output nil -2))))
124
125 (define-its-state-machine its-aynu-map
126   "roma-aynu-kata" "\e$(O%"\e(B" Aynu
127   "Map for Romaji-Aynu-Katakana translation. (Japanese)"
128
129   (defconst its-zenkaku-escape "Z")  ;; Escape character to Zenkaku inputs
130   (defconst its-hankaku-escape "~")  ;; Escape character to Hankaku inputs
131
132   (its-defrule-select-mode-temporally "q" downcase)
133   (its-defrule-select-mode-temporally "Q" zenkaku-downcase)
134
135   (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")
136                    ("ka" "\e$(O%u\e(B")             ("ku" "\e$(O&n\e(B") ("ke" "\e$(O%v\e(B")
137                                ("si" "\e$(O&o\e(B") ("su" "\e$(O&p\e(B")
138                                            ("tu" "\e$(O%C\e(B")             ("to" "\e$(O&q\e(B")
139                                            ("nu" "\e$(O&r\e(B")
140                    ("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")
141                                            ("pu" "\e$(O&x\e(B")
142                                            ("mu" "\e$(O&y\e(B")
143                    ("ya" "\e$(O%c\e(B")             ("yu" "\e$(O%e\e(B")             ("yo" "\e$(O%g\e(B")
144                    ("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")
145                    ("wa" "\e$(O%n\e(B")))
146     (its-defrule (concat "x" (car small)) (cadr small)))
147
148   (its-define-aynu
149    (""   nil    "\e$(O%"\e(B"   "\e$(O%$\e(B"   "\e$(O%&\e(B"   "\e$(O%(\e(B"   "\e$(O%*\e(B")
150    ("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")
151    ("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")
152    ("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")
153    ("z"  nil    "\e$(O%6\e(B"   "\e$(O%8\e(B"   "\e$(O%:\e(B"   "\e$(O%<\e(B"   "\e$(O%>\e(B")
154    ("vs" nil    nil    nil    nil    "\e$(O%|\e(B"   nil)
155    ("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")
156    ("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")
157    ("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")
158    ("vt" nil    nil    nil    "\e$(O%}\e(B"   nil    "\e$(O%~\e(B")
159    ("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")
160    ("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")
161    ("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")
162    ("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")
163    ("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")
164    ("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")
165    ("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")
166    ("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")
167    ("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")
168    ("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")
169    ("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"))
170
171   (dolist (yu '("k" "g" "s" "z" "sh" "j" "t" "d"
172                 "c" "ch" "n" "h" "b" "p" "m" "r"))
173     (its-defrule-aynu-override-yu yu))
174
175   (its-defrule "kk" "\e$(O%C\e(B" -1)
176   (its-defrule "ss" "\e$(O%C\e(B" -1)
177   (its-defrule "pp" "\e$(O%C\e(B" -1)
178   (its-defrule "vv" "\e$(O%C\e(B" -1)
179
180 ;; SYMBOL Input
181   (its-defrule   "z1"   "\e$(O!{\e(B")    (its-defrule   "z!"   "\e$(O!|\e(B")
182   (its-defrule   "z2"   "\e$(O"&\e(B")    (its-defrule   "z@"   "\e$(O"'\e(B")
183   (its-defrule   "z3"   "\e$(O"$\e(B")    (its-defrule   "z#"   "\e$(O"%\e(B")
184   (its-defrule   "z4"   "\e$(O""\e(B")    (its-defrule   "z$"   "\e$(O"#\e(B")
185   (its-defrule   "z5"   "\e$(O!~\e(B")    (its-defrule   "z%"   "\e$(O"!\e(B")
186   (its-defrule   "z6"   "\e$(O!y\e(B")    (its-defrule   "z^"   "\e$(O!z\e(B")
187   (its-defrule   "z7"   "\e$(O!}\e(B")    (its-defrule   "z&"   "\e$(O!r\e(B")
188   (its-defrule   "z8"   "\e$(O!q\e(B")    (its-defrule   "z*"   "\e$(O!_\e(B")
189   (its-defrule   "z9"   "\e$(O!i\e(B")    (its-defrule   "z("   "\e$(O!Z\e(B")
190   (its-defrule   "z0"   "\e$(O!j\e(B")    (its-defrule   "z)"   "\e$(O![\e(B")
191   (its-defrule   "z-"   "\e$(O!A\e(B")    (its-defrule   "z_"   "\e$(O!h\e(B")
192   (its-defrule   "z="   "\e$(O!b\e(B")    (its-defrule   "z+"   "\e$(O!^\e(B")
193   (its-defrule   "z\\"  "\e$(O!@\e(B")    (its-defrule   "z|"   "\e$(O!B\e(B")
194   (its-defrule   "z`"   "\e$(O!-\e(B")    (its-defrule   "z~"   "\e$(O!/\e(B")
195
196   (its-defrule   "zq"   "\e$(O!T\e(B")    (its-defrule   "zQ"   "\e$(O!R\e(B")
197   (its-defrule   "zw"   "\e$(O!U\e(B")    (its-defrule   "zW"   "\e$(O!S\e(B")
198                                         ; e
199   (its-defrule   "zr"   "\e$(O!9\e(B")    (its-defrule   "zR"   "\e$(O!8\e(B")
200   (its-defrule   "zt"   "\e$(O!:\e(B")    (its-defrule   "zT"   "\e$(O!x\e(B")
201                                         ; y u i o
202   (its-defrule   "zp"   "\e$(O")\e(B")    (its-defrule   "zP"   "\e$(O",\e(B")
203   (its-defrule   "z["   "\e$(O!X\e(B")    (its-defrule   "z{"   "\e$(O!L\e(B")
204   (its-defrule   "z]"   "\e$(O!Y\e(B")    (its-defrule   "z}"   "\e$(O!M\e(B")
205                                         ; a
206   (its-defrule   "zs"   "\e$(O!3\e(B")    (its-defrule   "zS"   "\e$(O!4\e(B")
207   (its-defrule   "zd"   "\e$(O!5\e(B")    (its-defrule   "zD"   "\e$(O!6\e(B")
208   (its-defrule   "zf"   "\e$(O!7\e(B")    (its-defrule   "zF"   "\e$(O"*\e(B")
209   (its-defrule   "zg"   "\e$(O!>\e(B")    (its-defrule   "zG"   "\e$(O!=\e(B")
210   (its-defrule   "zh"   "\e$(O"+\e(B")
211   (its-defrule   "zj"   "\e$(O"-\e(B")
212   (its-defrule   "zk"   "\e$(O",\e(B")
213   (its-defrule   "zl"   "\e$(O"*\e(B")
214   (its-defrule   "z;"   "\e$(O!+\e(B")    (its-defrule   "z:"   "\e$(O!,\e(B")
215   (its-defrule   "z\'"  "\e$(O!F\e(B")    (its-defrule   "z\""  "\e$(O!H\e(B")
216                                         ; z
217   (its-defrule   "zx"   ":-")   (its-defrule   "zX"   ":-)")
218   (its-defrule   "zc"   "\e$(O!;\e(B")    (its-defrule   "zC"   "\e$(O!n\e(B")
219   (its-defrule   "zv"   "\e$(O"(\e(B")    (its-defrule   "zV"   "\e$(O!`\e(B")
220   (its-defrule   "zb"   "\e$(O!k\e(B")    (its-defrule   "zB"   "\e$(O"+\e(B")
221   (its-defrule   "zn"   "\e$(O!l\e(B")    (its-defrule   "zN"   "\e$(O"-\e(B")
222   (its-defrule   "zm"   "\e$(O!m\e(B")    (its-defrule   "zM"   "\e$(O".\e(B")
223   (its-defrule   "z,"   "\e$(O!E\e(B")    (its-defrule   "z<"   "\e$(O!e\e(B")
224   (its-defrule   "z."   "\e$(O!D\e(B")    (its-defrule   "z>"   "\e$(O!f\e(B")
225   (its-defrule   "z/"   "\e$(O!&\e(B")    (its-defrule   "z?"   "\e$(O!g\e(B")
226   )
227
228 (define-its-state-machine-append its-aynu-map
229   (if its-aynu-enable-double-n
230       (its-defrule "nn" "\e$(O%s\e(B"))
231
232   (its-defrule "-" its-aynu-horizontal)
233   (its-defrule "." its-aynu-period)
234   (its-defrule "," its-aynu-comma)
235   (its-defrule "[" its-aynu-open-bracket)
236   (its-defrule "]" its-aynu-close-bracket)
237
238   (unless its-aynu-kick-conversion-on-space
239     (its-defrule " " " "))
240
241   (if its-aynu-enable-zenkaku-alphabet
242       (progn
243         (its-defrule   "1"   "\e$(O#1\e(B")  (its-defrule   "2"   "\e$(O#2\e(B")
244         (its-defrule   "3"   "\e$(O#3\e(B")  (its-defrule   "4"   "\e$(O#4\e(B")
245         (its-defrule   "5"   "\e$(O#5\e(B")  (its-defrule   "6"   "\e$(O#6\e(B")
246         (its-defrule   "7"   "\e$(O#7\e(B")  (its-defrule   "8"   "\e$(O#8\e(B")
247         (its-defrule   "9"   "\e$(O#9\e(B")  (its-defrule   "0"   "\e$(O#0\e(B")
248         (its-defrule   "!"   "\e$(O!*\e(B")  (its-defrule   "@"   "\e$(O!w\e(B")
249         (its-defrule   "#"   "\e$(O!t\e(B")  (its-defrule   "$"   "\e$(O!p\e(B")
250         (its-defrule   "%"   "\e$(O!s\e(B")  (its-defrule   "^"   "\e$(O!0\e(B")
251         (its-defrule   "&"   "\e$(O!u\e(B")  (its-defrule   "*"   "\e$(O!v\e(B")
252         (its-defrule   "("   "\e$(O!J\e(B")  (its-defrule   ")"   "\e$(O!K\e(B")
253         (its-defrule   "="   "\e$(O!a\e(B")  (its-defrule   "`"   "\e$(O!.\e(B")
254         (its-defrule   "\\"  "\e$(O!o\e(B")  (its-defrule   "|"   "\e$(O!C\e(B")
255         (its-defrule   "_"   "\e$(O!2\e(B")  (its-defrule   "+"   "\e$(O!\\e(B")
256         (its-defrule   "{"   "\e$(O!P\e(B")  (its-defrule   "}"   "\e$(O!Q\e(B")
257         (its-defrule   ":"   "\e$(O!'\e(B")  (its-defrule   ";"   "\e$(O!(\e(B")
258         (its-defrule   "\""  "\e$(O!I\e(B")  (its-defrule   "'"   "\e$(O!G\e(B")
259         (its-defrule   "<"   "\e$(O!c\e(B")  (its-defrule   ">"   "\e$(O!d\e(B")
260         (its-defrule   "?"   "\e$(O!)\e(B")  (its-defrule   "/"   "\e$(O!?\e(B"))
261     (progn
262       (its-defrule   "1"   "1")  (its-defrule   "2"   "2")
263       (its-defrule   "3"   "3")  (its-defrule   "4"   "4")
264       (its-defrule   "5"   "5")  (its-defrule   "6"   "6")
265       (its-defrule   "7"   "7")  (its-defrule   "8"   "8")
266       (its-defrule   "9"   "9")  (its-defrule   "0"   "0")
267       (its-defrule   "!"   "!")  (its-defrule   "@"   "@")
268       (its-defrule   "#"   "#")  (its-defrule   "$"   "$")
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
281 (provide 'its/aynu)
282 ;;; its/aynu.el ends here.