egg-980315.
[elisp/egg.git] / its / pinyin.el
index 9d3505d..6a32775 100644 (file)
@@ -1,17 +1,46 @@
+;;; its/pinyin.el --- Pinyin Input in Egg Input Method Architecture
+
+;; Copyright (C) 1997, 1998 Mule Project,
+;; Powered by Electrotechnical Laboratory, JAPAN.
+;; Project Leader: Satoru Tomura <tomura@etl.go.jp>
+
+;; Author: KATAYAMA Yoshio <kate@pfu.co.jp>
+
+;; This file will be part of GNU Emacs (in future).
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+
+;;; Code:
+
 (eval-when-compile
   (require 'its)
   (require 'cl))
 
+(defvar its-pinyin-cn-enable-quanjioao-alphabet t "*Enable Quanjiao alphabet")
 (defvar its-pinyin-cn-open-braket  "\e$A!8\e(B" "*[") ; "\e$A#[\e(B"
 (defvar its-pinyin-cn-close-braket "\e$A!9\e(B" "*]") ; "\e$A#]\e(B"
 
+(defvar its-pinyin-tw-enable-quanjioao-alphabet t "*Enable Quanjiao alphabet")
 (defvar its-pinyin-tw-open-braket  "\e$(G!V\e(B" "*[") ; "\e$(G!b\e(B "
 (defvar its-pinyin-tw-close-braket "\e$(G!W\e(B" "*]") ; "\e$(G!c\e(B"
 
 (eval-when-compile
-  (defvar its-quanjiao-escape "Z")
-  (defvar its-banjiao-escape  "X")
-
   (defconst its-pinyin-term
     (char-to-string (make-char 'chinese-sisheng ?@)))
 
       state))
 
   (defmacro its-do-sisheng-table (list)
-    `(progn ,@(mapcar (lambda (syl)
-                       `(its-define-sisheng ,(car syl) ,(cdr syl)))
-                     list)))
+    `(progn
+       ,@(mapcar (lambda (syl)
+                  `(its-define-sisheng ,@syl))
+                list)))
 
   (defmacro its-define-sisheng (shengmu yunmu)
     `(let ((qing (nth 5 ,yunmu)) (y (car ,yunmu))
           (UO   '("uo"   "u\e(0-\e(B"   "u\e(0.\e(B"   "u\e(0/\e(B"   "u\e(00\e(B"   "uo"  )))
 
        (its-do-sisheng-table
-       (((- B C D F G H   K L M N P     S T W   Y Z CH SH ZH ) . A)
-        ((- B C D   G H   K L M N P     S T W     Z CH SH ZH ) . AI)
-        ((- B C D F G H   K L M N P   R S T W   Y Z CH SH ZH ) . AN)
-        ((- B C D F G H   K L M N P   R S T W   Y Z CH SH ZH ) . ANG)
-        ((- B C D   G H   K L M N P   R S T     Y Z CH SH ZH ) . AO)
-        ((-   C D   G H   K L M N     R S T     Y Z CH SH ZH ) . E)
-        ((- B C D F G H   K L M N P       T W     Z    SH ZH ) . EI)
-        ((- B C D F G H   K   M N P   R S   W     Z CH SH ZH ) . EN)
-        ((- B C D F G H   K L M N P   R S T W     Z CH SH ZH ) . ENG)
-        ((-                                                  ) . ER)
-        ((  B C D       J   L M N P Q R S T   X Y Z CH SH ZH ) . I)
-        ((      D       J   L       Q         X              ) . IA)
-        ((  B   D       J   L M N P Q     T   X              ) . IAN)
-        ((              J   L   N   Q         X              ) . IANG)
-        ((  B   D       J   L M N P Q     T   X              ) . IAO)
-        ((  B   D       J   L M N P Q     T   X              ) . IE)
-        ((  B           J   L M N P Q         X Y            ) . IN)
-        ((  B   D       J   L M N P Q     T   X Y            ) . ING)
-        ((              J           Q         X              ) . IONG)
-        ((      D       J   L M N   Q         X              ) . IU)
-        ((- B     F         L M   P         W   Y            ) . O)
-        ((    C D   G H   K L   N     R S T     Y Z CH    ZH ) . ONG)
-        ((-   C D F G H   K L M N P   R S T     Y Z CH SH ZH ) . OU)
-        ((  B C D F G H J K L M N P Q R S T W X Y Z CH SH ZH ) . U)
-        ((                  L   N                            ) . V)
-        ((          G H   K           R             CH SH ZH ) . UA)
-        ((          G H   K                         CH SH ZH ) . UAI)
-        ((    C D   G H J K L   N   Q R S T   X Y Z CH SH ZH ) . UAN)
-        ((          G H   K                         CH SH ZH ) . UANG)
-        ((              J           Q         X Y            ) . UE)
-        ((                  L   N                            ) . VE)
-        ((    C D   G H   K           R S T       Z CH SH ZH ) . UI)
-        ((    C D   G H J K L       Q R S T   X Y Z CH SH ZH ) . UN)
-        ((    C D   G H   K L   N     R S T       Z CH SH ZH ) . UO)
-
-        ((J Q X) . (cons "a"   (cdr IA  )))
-        ((J Q X) . (cons "ai"  (cdr IA  )))
-        ((J Q X) . (cons "an"  (cdr IAN )))
-        ((J Q X) . (cons "ang" (cdr IANG)))
-        ((J Q X) . (cons "ao"  (cdr IAO )))
-        ((J Q X) . (cons "e"   (cdr IE  )))
-        ((J Q X) . (cons "ei"  (cdr IE  )))
-        ((J Q X) . (cons "en"  (cdr IN  )))
-        ((J Q X) . (cons "eng" (cdr ING )))
-        ((J Q X) . (cons "ou"  (cdr IU  )))))
+       (((- B C D F G H   K L M N P     S T W   Y Z CH SH ZH ) A)
+        ((- B C D   G H   K L M N P     S T W     Z CH SH ZH ) AI)
+        ((- B C D F G H   K L M N P   R S T W   Y Z CH SH ZH ) AN)
+        ((- B C D F G H   K L M N P   R S T W   Y Z CH SH ZH ) ANG)
+        ((- B C D   G H   K L M N P   R S T     Y Z CH SH ZH ) AO)
+        ((-   C D   G H   K L M N     R S T     Y Z CH SH ZH ) E)
+        ((- B C D F G H   K L M N P       T W     Z    SH ZH ) EI)
+        ((- B C D F G H   K   M N P   R S   W     Z CH SH ZH ) EN)
+        ((- B C D F G H   K L M N P   R S T W     Z CH SH ZH ) ENG)
+        ((-                                                  ) ER)
+        ((  B C D       J   L M N P Q R S T   X Y Z CH SH ZH ) I)
+        ((      D       J   L       Q         X              ) IA)
+        ((  B   D       J   L M N P Q     T   X              ) IAN)
+        ((              J   L   N   Q         X              ) IANG)
+        ((  B   D       J   L M N P Q     T   X              ) IAO)
+        ((  B   D       J   L M N P Q     T   X              ) IE)
+        ((  B           J   L M N P Q         X Y            ) IN)
+        ((  B   D       J   L M N P Q     T   X Y            ) ING)
+        ((              J           Q         X              ) IONG)
+        ((      D       J   L M N   Q         X              ) IU)
+        ((- B     F         L M   P         W   Y            ) O)
+        ((    C D   G H   K L   N     R S T     Y Z CH    ZH ) ONG)
+        ((-   C D F G H   K L M N P   R S T     Y Z CH SH ZH ) OU)
+        ((  B C D F G H J K L M N P Q R S T W X Y Z CH SH ZH ) U)
+        ((                  L   N                            ) V)
+        ((          G H   K           R             CH SH ZH ) UA)
+        ((          G H   K                         CH SH ZH ) UAI)
+        ((    C D   G H J K L   N   Q R S T   X Y Z CH SH ZH ) UAN)
+        ((          G H   K                         CH SH ZH ) UANG)
+        ((              J           Q         X Y            ) UE)
+        ((                  L   N                            ) VE)
+        ((    C D   G H   K           R S T       Z CH SH ZH ) UI)
+        ((    C D   G H J K L       Q R S T   X Y Z CH SH ZH ) UN)
+        ((    C D   G H   K L   N     R S T       Z CH SH ZH ) UO)
+
+        ((J Q X) (cons "a"   (cdr IA  )))
+        ((J Q X) (cons "ai"  (cdr IA  )))
+        ((J Q X) (cons "an"  (cdr IAN )))
+        ((J Q X) (cons "ang" (cdr IANG)))
+        ((J Q X) (cons "ao"  (cdr IAO )))
+        ((J Q X) (cons "e"   (cdr IE  )))
+        ((J Q X) (cons "ei"  (cdr IE  )))
+        ((J Q X) (cons "en"  (cdr IN  )))
+        ((J Q X) (cons "eng" (cdr ING )))
+        ((J Q X) (cons "ou"  (cdr IU  )))))
 
        (its-define-qingsheng   "hm"    "")
        (its-define-qingsheng   "hng"   "")
 (define-its-state-machine its-pinyin-cn-map
   "pinyin-cn" "\e$AF4\e(BG" "Chinese-GB"
   "Map for Pinyin input. (Chinese-GB)"
+
+  (defconst its-quanjiao-escape "Z")
+  (defconst its-banjiao-escape  "X")
+
+  (its-defrule-select-mode-temporally "B" downcase)
+  (its-defrule-select-mode-temporally "Q" quanjiao-downcase-cn)
+
   (its-define-pinyin-table)
   (its-defoutput*      "b "    "\e$A2;\e(B")
   (its-defoutput*      "c "    "\e$A2E\e(B")
                   ("U" . "\e$A#U\e(B")  ("V" . "\e$A#V\e(B")  ("W" . "\e$A#W\e(B")  ("X" . "\e$A#X\e(B")
                   ("Y" . "\e$A#Y\e(B")  ("Z" . "\e$A#Z\e(B")))
     (let ((in (car ascii)) (out (cdr ascii)))
-      (if (and (or (string< in "a") (string< "z" in))
-              (null (equal in " "))
-              (null (equal in its-banjiao-escape))
-              (null (equal in its-quanjiao-escape)))
-         (progn
-           (its-defrule in in)
-           (its-defrule (concat (downcase its-banjiao-escape) in) in)
-           (its-defrule (concat (downcase its-quanjiao-escape) in) out)))
       (its-defrule (concat its-banjiao-escape in) in)
       (its-defrule (concat its-quanjiao-escape in) out)))
 
-  (its-defrule ","     "\e$A#,\e(B"      nil t)
-  (its-defrule "."     "\e$A!#\e(B"      nil t)
-  (its-defrule "/"     "\e$A!"\e(B"      nil t)
-  (its-defrule ":"     "\e$A#:\e(B"      nil t)
-  (its-defrule ";"     "\e$A#;\e(B"      nil t)
-  (its-defrule "?"     "\e$A#?\e(B"      nil t)
-  (its-defrule "!"     "\e$A#!\e(B"      nil t)
-  (its-defrule "-"     "\e$A!*\e(B"      nil t))
+  (its-defrule ","     "\e$A#,\e(B")
+  (its-defrule "."     "\e$A!#\e(B")
+  (its-defrule "/"     "\e$A!"\e(B")
+  (its-defrule ":"     "\e$A#:\e(B")
+  (its-defrule ";"     "\e$A#;\e(B")
+  (its-defrule "?"     "\e$A#?\e(B")
+  (its-defrule "!"     "\e$A#!\e(B"))
 
 (define-its-state-machine its-pinyin-tw-map
   "pinyin-tw" "\e$(GQ;\e(BC" "Chinese-CNS"
   "Map for Pinyin input."
+
+  (defconst its-quanjiao-escape "Z")
+  (defconst its-banjiao-escape  "X")
+
+  (its-defrule-select-mode-temporally "B" downcase)
+  (its-defrule-select-mode-temporally "Q" quanjiao-downcase-tw)
+
   (its-define-pinyin-table)
   (its-defoutput*      "b "    "\e$(GDb\e(B")
   (its-defoutput*      "c "    "\e$(GD_\e(B")
                   ("U" . "\e$(G$U\e(B")  ("V" . "\e$(G$V\e(B")  ("W" . "\e$(G$W\e(B")  ("X" . "\e$(G$X\e(B")
                   ("Y" . "\e$(G$Y\e(B")  ("Z" . "\e$(G$Z\e(B")))
     (let ((in (car ascii)) (out (cdr ascii)))
-      (if (and (or (string< in "a") (string< "z" in))
-              (null (equal in " "))
-              (null (equal in its-banjiao-escape))
-              (null (equal in its-quanjiao-escape)))
-         (progn
-           (its-defrule in in)
-           (its-defrule (concat (downcase its-banjiao-escape) in) in)
-           (its-defrule (concat (downcase its-quanjiao-escape) in) out)))
       (its-defrule (concat its-banjiao-escape in) in)
       (its-defrule (concat its-quanjiao-escape in) out)))
 
-  (its-defrule ","     "\e$(G!"\e(B"     nil t)
-  (its-defrule "."     "\e$(G!$\e(B"     nil t)
-  (its-defrule "/"     "\e$(G!#\e(B"     nil t)
-  (its-defrule ":"     "\e$(G!(\e(B"     nil t)
-  (its-defrule ";"     "\e$(G!'\e(B"     nil t)
-  (its-defrule "?"     "\e$(G!)\e(B"     nil t)
-  (its-defrule "!"     "\e$(G!*\e(B"     nil t)
-  (its-defrule "-"     "\e$(G"1\e(B"     nil t)
-  (its-defrule "["     "\e$(G!V\e(B"     nil t)
-  (its-defrule "]"     "\e$(G!W\e(B"     nil t))
+  (its-defrule ","     "\e$(G!"\e(B")
+  (its-defrule "."     "\e$(G!$\e(B")
+  (its-defrule "/"     "\e$(G!#\e(B")
+  (its-defrule ":"     "\e$(G!(\e(B")
+  (its-defrule ";"     "\e$(G!'\e(B")
+  (its-defrule "?"     "\e$(G!)\e(B")
+  (its-defrule "!"     "\e$(G!*\e(B"))
 
 (define-its-state-machine-append its-pinyin-cn-map
-  (its-defrule "[" its-pinyin-cn-open-braket  nil t)
-  (its-defrule "]" its-pinyin-cn-close-braket nil t))
+  (its-defrule "[" its-pinyin-cn-open-braket)
+  (its-defrule "]" its-pinyin-cn-close-braket)
+
+  (if its-pinyin-cn-enable-quanjioao-alphabet
+      (progn
+       (its-defrule "1"  "\e$A#1\e(B")  (its-defrule "2"  "\e$A#2\e(B")
+       (its-defrule "3"  "\e$A#3\e(B")  (its-defrule "4"  "\e$A#4\e(B")
+       (its-defrule "5"  "\e$A#5\e(B")  (its-defrule "6"  "\e$A#6\e(B")
+       (its-defrule "7"  "\e$A#7\e(B")  (its-defrule "8"  "\e$A#8\e(B")
+       (its-defrule "9"  "\e$A#9\e(B")  (its-defrule "0"  "\e$A#0\e(B")
+       (its-defrule "@"  "\e$A#@\e(B")
+       (its-defrule "#"  "\e$A##\e(B")  (its-defrule "$"  "\e$A!g\e(B")
+       (its-defrule "%"  "\e$A#%\e(B")  (its-defrule "^"  "\e$A#^\e(B")
+       (its-defrule "&"  "\e$A#&\e(B")  (its-defrule "*"  "\e$A#*\e(B")
+       (its-defrule "("  "\e$A#(\e(B")  (its-defrule ")"  "\e$A#)\e(B")
+       (its-defrule "-"  "\e$A#-\e(B")  (its-defrule "~"  "\e$A!+\e(B")
+       (its-defrule "="  "\e$A#=\e(B")  (its-defrule "`"  "\e$A#`\e(B")
+       (its-defrule "\\" "\e$A#\\e(B")  (its-defrule "|"  "\e$A#|\e(B")
+       (its-defrule "_"  "\e$A#_\e(B")  (its-defrule "+"  "\e$A#+\e(B")
+       (its-defrule "{"  "\e$A#{\e(B")  (its-defrule "}"  "\e$A#}\e(B")
+       (its-defrule "\"" "\e$A#"\e(B")  (its-defrule "'"  "\e$A#'\e(B")
+       (its-defrule "<"  "\e$A#<\e(B")  (its-defrule ">"  "\e$A#>\e(B"))
+    (progn
+      (its-defrule "1"  "1")  (its-defrule "2"  "2")
+      (its-defrule "3"  "3")  (its-defrule "4"  "4")
+      (its-defrule "5"  "5")  (its-defrule "6"  "6")
+      (its-defrule "7"  "7")  (its-defrule "8"  "8")
+      (its-defrule "9"  "9")  (its-defrule "0"  "0")
+      (its-defrule "@"  "@")
+      (its-defrule "#"  "#")  (its-defrule "$"  "$")
+      (its-defrule "%"  "%")  (its-defrule "^"  "^")
+      (its-defrule "&"  "&")  (its-defrule "*"  "*")
+      (its-defrule "("  "(")  (its-defrule ")"  ")")
+      (its-defrule "-"  "-")  (its-defrule "~"  "~")
+      (its-defrule "="  "=")  (its-defrule "`"  "`")
+      (its-defrule "\\" "\\") (its-defrule "|"  "|")
+      (its-defrule "_"  "_")  (its-defrule "+"  "+")
+      (its-defrule "{"  "{")  (its-defrule "}"  "}")
+      (its-defrule "\"" "\"") (its-defrule "'"  "'")
+      (its-defrule "<"  "<")  (its-defrule ">"  ">"))))
 
 (define-its-state-machine-append its-pinyin-tw-map
-  (its-defrule "[" its-pinyin-tw-open-braket  nil t)
-  (its-defrule "]" its-pinyin-tw-close-braket nil t))
+  (its-defrule "[" its-pinyin-tw-open-braket)
+  (its-defrule "]" its-pinyin-tw-close-braket)
+
+  (if its-pinyin-tw-enable-quanjioao-alphabet
+      (progn
+       (its-defrule "1"  "\e$(G$"\e(B")  (its-defrule "2"  "\e$(G$#\e(B")
+       (its-defrule "3"  "\e$(G$$\e(B")  (its-defrule "4"  "\e$(G$%\e(B")
+       (its-defrule "5"  "\e$(G$&\e(B")  (its-defrule "6"  "\e$(G$'\e(B")
+       (its-defrule "7"  "\e$(G$(\e(B")  (its-defrule "8"  "\e$(G$)\e(B")
+       (its-defrule "9"  "\e$(G$*\e(B")  (its-defrule "0"  "\e$(G$!\e(B")
+       (its-defrule "@"  "\e$(G"i\e(B")
+       (its-defrule "#"  "\e$(G!l\e(B")  (its-defrule "$"  "\e$(G"c\e(B")
+       (its-defrule "%"  "\e$(G"h\e(B")  (its-defrule "^"  "\e$(G!T\e(B")
+       (its-defrule "&"  "\e$(G!m\e(B")  (its-defrule "*"  "\e$(G!n\e(B")
+       (its-defrule "("  "\e$(G!>\e(B")  (its-defrule ")"  "\e$(G!?\e(B")
+       (its-defrule "-"  "\e$(G"1\e(B")  (its-defrule "~"  "\e$(G"D\e(B")
+       (its-defrule "="  "\e$(G"8\e(B")  (its-defrule "`"  "\e$(G!j\e(B")
+       (its-defrule "\\" "\e$(G"b\e(B")  (its-defrule "|"  "\e$(G"^\e(B")
+       (its-defrule "_"  "\e$(G"%\e(B")  (its-defrule "+"  "\e$(G"0\e(B")
+       (its-defrule "{"  "\e$A#{\e(B")  (its-defrule "}"  "\e$(G!a\e(B")
+       (its-defrule "\"" "\e$(G!i\e(B")  (its-defrule "'"  "\e$(G!k\e(B")
+       (its-defrule "<"  "\e$(G"6\e(B")  (its-defrule ">"  "\e$(G"7\e(B"))
+    (progn
+      (its-defrule "1"  "1")  (its-defrule "2"  "2")
+      (its-defrule "3"  "3")  (its-defrule "4"  "4")
+      (its-defrule "5"  "5")  (its-defrule "6"  "6")
+      (its-defrule "7"  "7")  (its-defrule "8"  "8")
+      (its-defrule "9"  "9")  (its-defrule "0"  "0")
+      (its-defrule "@"  "@")
+      (its-defrule "#"  "#")  (its-defrule "$"  "$")
+      (its-defrule "%"  "%")  (its-defrule "^"  "^")
+      (its-defrule "&"  "&")  (its-defrule "*"  "*")
+      (its-defrule "("  "(")  (its-defrule ")"  ")")
+      (its-defrule "-"  "-")  (its-defrule "~"  "~")
+      (its-defrule "="  "=")  (its-defrule "`"  "`")
+      (its-defrule "\\" "\\") (its-defrule "|"  "|")
+      (its-defrule "_"  "_")  (its-defrule "+"  "+")
+      (its-defrule "{"  "{")  (its-defrule "}"  "}")
+      (its-defrule "\"" "\"") (its-defrule "'"  "'")
+      (its-defrule "<"  "<")  (its-defrule ">"  ">"))))
 
 (provide 'its/pinyin)