root/trunk/lisp/language/lao-util.el

Revision 4220, 22.1 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

  • Property svn:eol-style set to LF
Line 
1 ;;; lao-util.el --- utilities for Lao -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;;   Free Software Foundation, Inc.
5 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
6 ;;   2007, 2008
7 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
8 ;;   Registration Number H14PRO021
9
10 ;; Keywords: multilingual, Lao
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 ;;; Code:
32
33 ;; Setting information of Thai characters.
34
35 (defconst lao-category-table (make-category-table))
36 (define-category ?c "Lao consonant" lao-category-table)
37 (define-category ?s "Lao semi-vowel" lao-category-table)
38 (define-category ?v "Lao upper/lower vowel" lao-category-table)
39 (define-category ?t "Lao tone" lao-category-table)
40
41 (let ((l '((?(1!(B consonant "LETTER KOR  KAI'" "CHICKEN")
42            (?(1"(B consonant "LETTER KHOR KHAI'" "EGG")
43            (?(1#(B invalid nil)
44            (?(1$(B consonant "LETTER QHOR QHWARGN" "BUFFALO")
45            (?(1%(B invalid nil)
46            (?  invalid nil)
47            (?(1'(B consonant "LETTER NGOR NGUU" "SNAKE")
48            (?(1((B consonant "LETTER JOR JUA" "BUDDHIST NOVICE")
49            (?(1)(B invalid nil)
50            (?(1*(B consonant "LETTER XOR X\"ARNG" "ELEPHANT")
51            (?(1+(B invalid nil)
52            (?(1,(B invalid nil)
53            (?(1-(B consonant "LETTER YOR YUNG" "MOSQUITO")
54            (?(1.(B invalid nil)
55            (?(1.(B invalid nil)
56            (?(1.(B invalid nil)
57            (?(1.(B invalid nil)
58            (?(1.(B invalid nil)
59            (?(1.(B invalid nil)
60            (?(14(B consonant "LETTER DOR DANG" "NOSE")
61            (?(15(B consonant "LETTER TOR TAR" "EYE")
62            (?(16(B consonant "LETTER THOR THUNG" "TO ASK,QUESTION")
63            (?(17(B consonant "LETTER DHOR DHARM" "FLAG")
64            (?(18(B invalid nil)
65            (?(19(B consonant "LETTER NOR NOK" "BIRD")
66            (?(1:(B consonant "LETTER BOR BED" "FISHHOOK")
67            (?(1;(B consonant "LETTER POR PAR" "FISH")
68            (?(1<(B consonant "LETTER HPOR HPER\"" "BEE")
69            (?(1=(B consonant "LETTER FHOR FHAR" "WALL")
70            (?(1>(B consonant "LETTER PHOR PHUU" "MOUNTAIN")
71            (?(1?(B consonant "LETTER FOR FAI" "FIRE")
72            (?(1@(B invalid nil)
73            (?(1A(B consonant "LETTER MOR MAR\"" "HORSE")
74            (?(1B(B consonant "LETTER GNOR GNAR" "MEDICINE")
75            (?(1C(B consonant "LETTER ROR ROD" "CAR")
76            (?(1D(B invalid nil)
77            (?(1E(B consonant "LETTER LOR LIING" "MONKEY")
78            (?(1F(B invalid nil)
79            (?(1G(B consonant "LETTER WOR WII" "HAND FAN")
80            (?(1H(B invalid nil)
81            (?(1I(B invalid nil)
82            (?(1J(B consonant "LETTER SOR SEA" "TIGER")
83            (?(1K(B consonant "LETTER HHOR HHAI" "JAR")
84            (?(1L(B invalid nil)
85            (?(1M(B consonant "LETTER OR OOW" "TAKE")
86            (?(1N(B consonant "LETTER HOR HEA" "BOAT")
87            (?(1O(B special "ELLIPSIS")
88            (?(1P(B vowel-base "VOWEL SIGN SARA A")
89            (?(1Q(B vowel-upper "VOWEL SIGN MAI KAN")
90            (?(1R(B vowel-base "VOWEL SIGN SARA AR")
91            (?(1S(B vowel-base "VOWEL SIGN SARA AM")
92            (?(1T(B vowel-upper "VOWEL SIGN SARA I")
93            (?(1U(B vowel-upper "VOWEL SIGN SARA II")
94            (?(1V(B vowel-upper "VOWEL SIGN SARA EU")
95            (?(1W(B vowel-upper "VOWEL SIGN SARA UR")
96            (?(1X(B vowel-lower "VOWEL SIGN SARA U")
97            (?(1Y(B vowel-lower "VOWEL SIGN SARA UU")
98            (?(1Z(B invalid nil)
99            (?(1[(B vowel-upper "VOWEL SIGN MAI KONG")
100            (?(1\(B semivowel-lower "SEMIVOWEL SIGN LO")
101            (?(1](B vowel-base "SEMIVOWEL SIGN SARA IA")
102            (?(1^(B invalid nil)
103            (?(1_(B invalid nil)
104            (?(1`(B vowel-base "VOWEL SIGN SARA EE")
105            (?(1a(B vowel-base "VOWEL SIGN SARA AA")
106            (?(1b(B vowel-base "VOWEL SIGN SARA OO")
107            (?(1c(B vowel-base "VOWEL SIGN SARA EI MAI MUAN\"")
108            (?(1d(B vowel-base "VOWEL SIGN SARA AI MAI MAY")
109            (?(1e(B invalid nil)
110            (?(1f(B special "KO LA (REPETITION)")
111            (?(1g(B invalid nil)
112            (?(1h(B tone "TONE MAI EK")
113            (?(1i(B tone "TONE MAI THO")
114            (?(1j(B tone "TONE MAI TI")
115            (?(1k(B tone "TONE MAI JADTAWAR")
116            (?(1l(B tone "CANCELLATION MARK")
117            (?(1m(B vowel-upper "VOWEL SIGN SARA OR")
118            (?(1n(B invalid nil)
119            (?(1o(B invalid nil)
120            (?(1p(B special "DIGIT ZERO")
121            (?(1q(B special "DIGIT ONE")
122            (?(1r(B special "DIGIT TWO")
123            (?(1s(B special "DIGIT THREE")
124            (?(1t(B special "DIGIT FOUR")
125            (?(1u(B special "DIGIT FIVE")
126            (?(1v(B special "DIGIT SIX")
127            (?(1w(B special "DIGIT SEVEN")
128            (?(1x(B special "DIGIT EIGHT")
129            (?(1y(B special "DIGIT NINE")
130            (?(1z(B invalid nil)
131            (?(1{(B invalid nil)
132            (?(1|(B consonant "LETTER NHOR NHUU" "MOUSE")
133            (?(1}(B consonant "LETTER MHOR MHAR" "DOG")
134            (?(1~(B invalid nil)
135            ;; Unicode equivalents
136            (?$,1D!(B consonant "LETTER KOR  KAI'" "CHICKEN")
137            (?$,1D"(B consonant "LETTER KHOR KHAI'" "EGG")
138            (?$,1D$(B consonant "LETTER QHOR QHWARGN" "BUFFALO")
139            (?$,1D'(B consonant "LETTER NGOR NGUU" "SNAKE")
140            (?$,1D((B consonant "LETTER JOR JUA" "BUDDHIST NOVICE")
141            (?$,1D*(B consonant "LETTER XOR X\"ARNG" "ELEPHANT")
142            (?$,1D-(B consonant "LETTER YOR YUNG" "MOSQUITO")
143            (?$,1D4(B consonant "LETTER DOR DANG" "NOSE")
144            (?$,1D5(B consonant "LETTER TOR TAR" "EYE")
145            (?$,1D6(B consonant "LETTER THOR THUNG" "TO ASK,QUESTION")
146            (?$,1D7(B consonant "LETTER DHOR DHARM" "FLAG")
147            (?$,1D9(B consonant "LETTER NOR NOK" "BIRD")
148            (?$,1D:(B consonant "LETTER BOR BED" "FISHHOOK")
149            (?$,1D;(B consonant "LETTER POR PAR" "FISH")
150            (?$,1D<(B consonant "LETTER HPOR HPER\"" "BEE")
151            (?$,1D=(B consonant "LETTER FHOR FHAR" "WALL")
152            (?$,1D>(B consonant "LETTER PHOR PHUU" "MOUNTAIN")
153            (?$,1D?(B consonant "LETTER FOR FAI" "FIRE")
154            (?$,1DA(B consonant "LETTER MOR MAR\"" "HORSE")
155            (?$,1DB(B consonant "LETTER GNOR GNAR" "MEDICINE")
156            (?$,1DC(B consonant "LETTER ROR ROD" "CAR")
157            (?$,1DE(B consonant "LETTER LOR LIING" "MONKEY")
158            (?$,1DG(B consonant "LETTER WOR WII" "HAND FAN")
159            (?$,1DJ(B consonant "LETTER SOR SEA" "TIGER")
160            (?$,1DK(B consonant "LETTER HHOR HHAI" "JAR")
161            (?$,1DM(B consonant "LETTER OR OOW" "TAKE")
162            (?$,1DN(B consonant "LETTER HOR HEA" "BOAT")
163            (?$,1DO(B special "ELLIPSIS")
164            (?$,1DP(B vowel-base "VOWEL SIGN SARA A")
165            (?$,1DQ(B vowel-upper "VOWEL SIGN MAI KAN")
166            (?$,1DR(B vowel-base "VOWEL SIGN SARA AR")
167            (?$,1DS(B vowel-base "VOWEL SIGN SARA AM")
168            (?$,1DT(B vowel-upper "VOWEL SIGN SARA I")
169            (?$,1DU(B vowel-upper "VOWEL SIGN SARA II")
170            (?$,1DV(B vowel-upper "VOWEL SIGN SARA EU")
171            (?$,1DW(B vowel-upper "VOWEL SIGN SARA UR")
172            (?$,1DX(B vowel-lower "VOWEL SIGN SARA U")
173            (?$,1DY(B vowel-lower "VOWEL SIGN SARA UU")
174            (?$,1D[(B vowel-upper "VOWEL SIGN MAI KONG")
175            (?$,1D\(B semivowel-lower "SEMIVOWEL SIGN LO")
176            (?$,1D](B vowel-base "SEMIVOWEL SIGN SARA IA")
177            (?$,1D`(B vowel-base "VOWEL SIGN SARA EE")
178            (?$,1Da(B vowel-base "VOWEL SIGN SARA AA")
179            (?$,1Db(B vowel-base "VOWEL SIGN SARA OO")
180            (?$,1Dc(B vowel-base "VOWEL SIGN SARA EI MAI MUAN\"")
181            (?$,1Dd(B vowel-base "VOWEL SIGN SARA AI MAI MAY")
182            (?$,1Df(B special "KO LA (REPETITION)")
183            (?$,1Dh(B tone "TONE MAI EK")
184            (?$,1Di(B tone "TONE MAI THO")
185            (?$,1Dj(B tone "TONE MAI TI")
186            (?$,1Dk(B tone "TONE MAI JADTAWAR")
187            (?$,1Dl(B tone "CANCELLATION MARK")
188            (?$,1Dm(B vowel-upper "VOWEL SIGN SARA OR")
189            (?$,1Dp(B special "DIGIT ZERO")
190            (?$,1Dq(B special "DIGIT ONE")
191            (?$,1Dr(B special "DIGIT TWO")
192            (?$,1Ds(B special "DIGIT THREE")
193            (?$,1Dt(B special "DIGIT FOUR")
194            (?$,1Du(B special "DIGIT FIVE")
195            (?$,1Dv(B special "DIGIT SIX")
196            (?$,1Dw(B special "DIGIT SEVEN")
197            (?$,1Dx(B special "DIGIT EIGHT")
198            (?$,1Dy(B special "DIGIT NINE")
199            (?$,1D|(B consonant "LETTER NHOR NHUU" "MOUSE")
200            (?$,1D}(B consonant "LETTER MHOR MHAR" "DOG")))
201       elm)
202   (while l
203     (setq elm (car l) l (cdr l))
204     (let ((char (car elm))
205           (ptype (nth 1 elm)))
206       (cond ((eq ptype 'consonant)
207              (modify-category-entry char ?c lao-category-table))
208             ((memq ptype '(vowel-upper vowel-lower))
209              (modify-category-entry char ?v lao-category-table))
210             ((eq ptype 'semivowel-lower)
211              (modify-category-entry char ?s lao-category-table))
212             ((eq ptype 'tone)
213              (modify-category-entry char ?t lao-category-table)))
214       (put-char-code-property char 'phonetic-type ptype)
215       (put-char-code-property char 'name (nth 2 elm))
216       (put-char-code-property char 'meaning (nth 3 elm)))))
217
218 ;; The general composing rules are as follows:
219 ;;
220 ;;                          T
221 ;;       V        T         V                  T
222 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
223 ;;                                   v         v
224 ;;                             T
225 ;;        V         T          V                   T
226 ;; CsV -> C, CsT -> C, CsVT -> C, Csv -> C, CvT -> C
227 ;;        s         s          s         s         s
228 ;;                                       v         v
229
230
231 ;; where C: consonant, V: vowel upper, v: vowel lower,
232 ;;       T: tone mark, s: semivowel lower
233
234 (defvar lao-composition-pattern
235   "\\cc\\(\\ct\\|\\cv\\ct?\\|\\cs\\(\\ct\\|\\cv\\ct?\\)?\\)"
236   "Regular expression matching a Lao composite sequence.")
237
238 ;;;###autoload
239 (defun lao-compose-string (str)
240   (with-category-table lao-category-table
241    (let ((idx 0))
242      (while (setq idx (string-match lao-composition-pattern str idx))
243        (compose-string str idx (match-end 0))
244        (setq idx (match-end 0))))
245    str))
246
247 ;;; LRT: Lao <-> Roman Transcription
248
249 ;; Upper vowels and tone-marks are put on the letter.
250 ;; Semi-vowel-sign-lo and lower vowels are put under the letter.
251
252 (defconst lao-transcription-consonant-alist
253   (sort '(;; single consonants
254           ("k" . "(1!(B")
255           ("kh" . "(1"(B")
256           ("qh" . "(1$(B")
257           ("ng" . "(1'(B")
258           ("j" . "(1((B")
259           ("s" . "(1J(B")
260           ("x" . "(1*(B")
261           ("y" . "(1-(B")
262           ("d" . "(14(B")
263           ("t" . "(15(B")
264           ("th" . "(16(B")
265           ("dh" . "(17(B")
266           ("n" . "(19(B")
267           ("b" . "(1:(B")
268           ("p" . "(1;(B")
269           ("hp" . "(1<(B")
270           ("fh" . "(1=(B")
271           ("ph" . "(1>(B")
272           ("f" . "(1?(B")
273           ("m" . "(1A(B")
274           ("gn" . "(1B(B")
275           ("l" . "(1E(B")
276           ("r" . "(1C(B")
277           ("v" . "(1G(B")
278           ("w" . "(1G(B")
279           ("hh" . "(1K(B")
280           ("O" . "(1M(B")
281           ("h" . "(1N(B")
282           ("nh" . "(1|(B")
283           ("mh" . "(1}(B")
284           ("lh" . ["(1K\(B"])
285           ;; double consonants
286           ("ngh" . ["(1K'(B"])
287           ("yh" . ["(1K](B"])
288           ("wh" . ["(1KG(B"])
289           ("hl" . ["(1KE(B"])
290           ("hy" . ["(1K-(B"])
291           ("hn" . ["(1K9(B"])
292           ("hm" . ["(1KA(B"])
293           )
294         (function (lambda (x y) (> (length (car x)) (length (car y)))))))
295
296 (defconst lao-transcription-semi-vowel-alist
297   '(("r" . "(1\(B")))
298
299 (defconst lao-transcription-vowel-alist
300   (sort '(("a" . "(1P(B")
301           ("ar" . "(1R(B")
302           ("i" . "(1T(B")
303           ("ii" . "(1U(B")
304           ("eu" . "(1V(B")
305           ("ur" . "(1W(B")
306           ("u" . "(1X(B")
307           ("uu" . "(1Y(B")
308           ("e" . ["(1`P(B"])
309           ("ee" . "(1`(B")
310           ("ae" . ["(1aP(B"])
311           ("aa" . "(1a(B")
312           ("o" . ["(1bP(B"])
313           ("oo" . "(1b(B")
314           ("oe" . ["(1`RP(B"])
315           ("or" . "(1m(B")
316           ("er" . ["(1`T(B"])
317           ("ir" . ["(1`U(B"])
318           ("ua" . ["(1[GP(B"])
319           ("uaa" . ["(1[G(B"])
320           ("ie" . ["(1`Q]P(B"])
321           ("ia" . ["(1`Q](B"])
322           ("ea" . ["(1`VM(B"])
323           ("eaa" . ["(1`WM(B"])
324           ("ai" . "(1d(B")
325           ("ei" . "(1c(B")
326           ("ao" . ["(1`[R(B"])
327           ("aM" . "(1S(B"))
328         (function (lambda (x y) (> (length (car x)) (length (car y)))))))
329
330 ;; Maa-sakod is put at the tail.
331 (defconst lao-transcription-maa-sakod-alist
332   '(("k" . "(1!(B")
333     ("g" . "(1'(B")
334     ("y" . "(1-(B")
335     ("d" . "(14(B")
336     ("n" . "(19(B")
337     ("b" . "(1:(B")
338     ("m" . "(1A(B")
339     ("v" . "(1G(B")
340     ("w" . "(1G(B")
341     ))
342
343 (defconst lao-transcription-tone-alist
344   '(("'" . "(1h(B")
345     ("\"" . "(1i(B")
346     ("^" . "(1j(B")
347     ("+" . "(1k(B")
348     ("~" . "(1l(B")))
349
350 (defconst lao-transcription-punctuation-alist
351   '(("\\0" . "(1p(B")
352     ("\\1" . "(1q(B")
353     ("\\2" . "(1r(B")
354     ("\\3" . "(1s(B")
355     ("\\4" . "(1t(B")
356     ("\\5" . "(1u(B")
357     ("\\6" . "(1v(B")
358     ("\\7" . "(1w(B")
359     ("\\8" . "(1x(B")
360     ("\\9" . "(1y(B")
361     ("\\\\" . "(1f(B")
362     ("\\$" . "(1O(B")))
363
364 (defconst lao-transcription-pattern
365   (concat
366    "\\("
367    (mapconcat 'car lao-transcription-consonant-alist "\\|")
368    "\\)\\("
369    (mapconcat 'car lao-transcription-semi-vowel-alist "\\|")
370    "\\)?\\(\\("
371    (mapconcat 'car lao-transcription-vowel-alist "\\|")
372    "\\)\\("
373    (mapconcat 'car lao-transcription-maa-sakod-alist "\\|")
374    "\\)?\\("
375    (mapconcat (lambda (x) (regexp-quote (car x)))
376               lao-transcription-tone-alist "\\|")
377    "\\)?\\)?\\|"
378    (mapconcat (lambda (x) (regexp-quote (car x)))
379               lao-transcription-punctuation-alist "\\|")
380    )
381   "Regexp of Roman transcription pattern for one Lao syllable.")
382
383 (defconst lao-transcription-pattern
384   (concat
385    "\\("
386    (regexp-opt (mapcar 'car lao-transcription-consonant-alist))
387    "\\)\\("
388    (regexp-opt (mapcar 'car lao-transcription-semi-vowel-alist))
389    "\\)?\\(\\("
390    (regexp-opt (mapcar 'car lao-transcription-vowel-alist))
391    "\\)\\("
392    (regexp-opt (mapcar 'car lao-transcription-maa-sakod-alist))
393    "\\)?\\("
394    (regexp-opt (mapcar 'car lao-transcription-tone-alist))
395    "\\)?\\)?\\|"
396    (regexp-opt (mapcar 'car lao-transcription-punctuation-alist))
397    )
398   "Regexp of Roman transcription pattern for one Lao syllable.")
399
400 (defconst lao-vowel-reordering-rule
401   '(("(1P(B" (0 ?(1P(B) (0 ?(1Q(B))
402     ("(1R(B" (0 ?(1R(B))
403     ("(1T(B" (0 ?(1U(B))
404     ("(1U(B" (0 ?(1U(B))
405     ("(1V(B" (0 ?(1V(B))
406     ("(1W(B" (0 ?(1W(B))
407     ("(1X(B" (0 ?(1X(B))
408     ("(1Y(B" (0 ?(1Y(B))
409     ("(1`P(B" (?(1`(B 0 ?(1P(B) (?(1`(B 0 ?(1Q(B))
410     ("(1`(B" (?(1`(B 0))
411     ("(1aP(B" (?(1a(B 0 ?(1P(B) (?(1a(B 0 ?(1Q(B))
412     ("(1a(B" (?(1a(B 0))
413     ("(1bP(B" (?(1b(B 0 ?(1P(B) (0 ?(1[(B) (?(1-(B ?(1b(B 0 ?(1Q(B) (?(1G(B ?(1b(B 0 ?(1Q(B))
414     ("(1b(B" (?(1b(B 0))
415     ("(1`RP(B" (?(1`(B 0 ?(1R(B ?(1P(B) (0 ?(1Q(B ?(1M(B))
416     ("(1m(B" (0 ?(1m(B) (0 ?(1M(B))
417     ("(1`T(B" (?(1`(B 0 ?(1T(B))
418     ("(1`U(B" (?(1`(B 0 ?(1U(B))
419     ("(1[GP(B" (0 ?(1[(B ?(1G(B ?(1P(B) (0 ?(1Q(B ?(1G(B))
420     ("(1[G(B" (0 ?(1[(B ?(1G(B) (0 ?(1G(B))
421     ("(1`Q]P(B" (?(1`(B 0 ?(1Q(B ?(1](B ?(1P(B) (0 ?(1Q(B ?(1](B))
422     ("(1`Q](B" (?(1`(B 0 ?(1Q(B ?(1](B) (0 ?(1](B))
423     ("(1`VM(B" (?(1`(B 0 ?(1V(B ?(1M(B))
424     ("(1`WM(B" (?(1`(B 0 ?(1W(B ?(1M(B))
425     ("(1d(B" (?(1d(B 0))
426     ("(1c(B" (?(1c(B 0))
427     ("(1`[R(B" (?(1`(B 0 ?(1[(B ?(1R(B))
428     ("(1S(B" (0 ?(1S(B))
429
430     ;; Unicode equivalents
431     ("$,1DP(B" (0 ?$,1DP(B) (0 ?$,1DQ(B))
432     ("$,1DR(B" (0 ?$,1DR(B))
433     ("$,1DT(B" (0 ?$,1DU(B))
434     ("$,1DU(B" (0 ?$,1DU(B))
435     ("$,1DV(B" (0 ?$,1DV(B))
436     ("$,1DW(B" (0 ?$,1DW(B))
437     ("$,1DX(B" (0 ?$,1DX(B))
438     ("$,1DY(B" (0 ?$,1DY(B))
439     ("$,1D`DP(B" (?$,1D`(B 0 ?$,1DP(B) (?$,1D`(B 0 ?$,1DQ(B))
440     ("$,1D`(B" (?$,1D`(B 0))
441     ("$,1DaDP(B" (?$,1Da(B 0 ?$,1DP(B) (?$,1Da(B 0 ?$,1DQ(B))
442     ("$,1Da(B" (?$,1Da(B 0))
443     ("$,1DbDP(B" (?$,1Db(B 0 ?$,1DP(B) (0 ?$,1D[(B) (?$,1D-(B ?$,1Db(B 0 ?$,1DQ(B) (?$,1DG(B ?$,1Db(B 0 ?$,1DQ(B))
444     ("$,1Db(B" (?$,1Db(B 0))
445     ("$,1D`DRDP(B" (?$,1D`(B 0 ?$,1DR(B ?$,1DP(B) (0 ?$,1DQ(B ?$,1DM(B))
446     ("$,1Dm(B" (0 ?$,1Dm(B) (0 ?$,1DM(B))
447     ("$,1D`DT(B" (?$,1D`(B 0 ?$,1DT(B))
448     ("$,1D`DU(B" (?$,1D`(B 0 ?$,1DU(B))
449     ("$,1D[DGDP(B" (0 ?$,1D[(B ?$,1DG(B ?$,1DP(B) (0 ?$,1DQ(B ?$,1DG(B))
450     ("$,1D[DG(B" (0 ?$,1D[(B ?$,1DG(B) (0 ?$,1DG(B))
451     ("$,1D`DQD]DP(B" (?$,1D`(B 0 ?$,1DQ(B ?$,1D](B ?$,1DP(B) (0 ?$,1DQ(B ?$,1D](B))
452     ("$,1D`DQD](B" (?$,1D`(B 0 ?$,1DQ(B ?$,1D](B) (0 ?$,1D](B))
453     ("$,1D`DVDM(B" (?$,1D`(B 0 ?$,1DV(B ?$,1DM(B))
454     ("$,1D`DWDM(B" (?$,1D`(B 0 ?$,1DW(B ?$,1DM(B))
455     ("$,1Dd(B" (?$,1Dd(B 0))
456     ("$,1Dc(B" (?$,1Dc(B 0))
457     ("$,1D`D[DR(B" (?$,1D`(B 0 ?$,1D[(B ?$,1DR(B))
458     ("$,1DS(B" (0 ?$,1DS(B)))
459   "Alist of Lao vowel string vs the corresponding re-ordering rule.
460 Each element has this form:
461         (VOWEL NO-MAA-SAKOD-RULE WITH-MAA-SAKOD-RULE (MAA-SAKOD-0 RULE-0) ...)
462
463 VOWEL is a vowel string (e.g. \"(1`Q]P(B\").
464
465 NO-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL following a
466 consonant.  It is a list vowel characters or 0.  The element 0
467 indicate the place to embed a consonant.
468
469 Optional WITH-MAA-SAKOD-RULE is a rule to re-order and modify VOWEL
470 follwoing a consonant and preceding a maa-sakod character.  If it is
471 nil, NO-MAA-SAKOD-RULE is used.  The maa-sakod character is alwasy
472 appended at the tail.
473
474 For instance, rule `(\"(1`WM(B\" (?(1`(B t ?(1W(B ?(1M(B))' tells that this vowel
475 string following a consonant `(1!(B' should be re-ordered as \"(1`!WM(B\".
476
477 Optional (MAA-SAKOD-n RULE-n) are rules specially applied to maa-sakod
478 character MAA-SAKOD-n.")
479
480 ;;;###autoload
481 (defun lao-transcribe-single-roman-syllable-to-lao (from to &optional str)
482   "Transcribe a Romanized Lao syllable in the region FROM and TO to Lao string.
483 Only the first syllable is transcribed.
484 The value has the form: (START END LAO-STRING), where
485 START and END are the beggining and end positions of the Roman Lao syllable,
486 LAO-STRING is the Lao character transcription of it.
487
488 Optional 3rd arg STR, if non-nil, is a string to search for Roman Lao
489 syllable.  In that case, FROM and TO are indexes to STR."
490   (if str
491       (if (setq from (string-match lao-transcription-pattern str from))
492           (progn
493             (if (>= from to)
494                 (setq from nil)
495               (setq to (match-end 0)))))
496     (save-excursion
497       (goto-char from)
498       (if (setq to (re-search-forward lao-transcription-pattern to t))
499           (setq from (match-beginning 0))
500         (setq from nil))))
501   (if from
502       (let* ((consonant (match-string 1 str))
503              (semivowel (match-string 3 str))
504              (vowel (match-string 5 str))
505              (maa-sakod (match-string 8 str))
506              (tone (match-string 9 str))
507              lao-consonant lao-semivowel lao-vowel lao-maa-sakod lao-tone
508              clen cidx)
509         (setq to (match-end 0))
510         (if (not consonant)
511             (setq str (cdr (assoc (match-string 0 str)
512                                   lao-transcription-punctuation-alist)))
513           (setq lao-consonant
514                 (cdr (assoc consonant lao-transcription-consonant-alist)))
515           (if (vectorp lao-consonant)
516               (setq lao-consonant (aref lao-consonant 0)))
517           (setq clen (length lao-consonant))
518           (if semivowel
519               ;; Include semivowel in STR.
520               (setq lao-semivowel
521                     (cdr (assoc semivowel lao-transcription-semi-vowel-alist))
522                     str (if (= clen 1)
523                             (concat lao-consonant lao-semivowel)
524                           (concat (substring lao-consonant 0 1) lao-semivowel
525                                   (substring lao-consonant 1))))
526             (setq str lao-consonant))
527           (if vowel
528               (let (rule)
529                 (setq lao-vowel
530                       (cdr (assoc vowel lao-transcription-vowel-alist)))
531                 (if (vectorp lao-vowel)
532                     (setq lao-vowel (aref lao-vowel 0)))
533                 (setq rule (assoc lao-vowel lao-vowel-reordering-rule))
534                 (if (null maa-sakod)
535                     (setq rule (nth 1 rule))
536                   (setq lao-maa-sakod
537                         (cdr (assoc maa-sakod lao-transcription-maa-sakod-alist))
538                         rule
539                         (or (cdr (assq (aref lao-maa-sakod 0) (nthcdr 2 rule)))
540                             (nth 2 rule)
541                             (nth 1 rule))))
542                 (or rule
543                     (error "Lao vowel %S has no re-ordering rule" lao-vowel))
544                 (setq lao-consonant str str "")
545                 (while rule
546                   (if (= (car rule) 0)
547                       (setq str (concat str lao-consonant)
548                             cidx (length str))
549                     (setq str (concat str (list (car rule)))))
550                   (setq rule (cdr rule)))
551                 (or cidx
552                     (error "Lao vowel %S has malformed re-ordering rule" vowel))
553                 ;; Set CIDX to after upper or lower vowel if any.
554                 (let ((len (length str)))
555                   (while (and (< cidx len)
556                               (memq (get-char-code-property (aref str cidx)
557                                                             'phonetic-type)
558                                     '(vowel-lower vowel-upper)))
559                     (setq cidx (1+ cidx))))
560                 (if lao-maa-sakod
561                     (setq str (concat str lao-maa-sakod)))
562                 (if tone
563                     (setq lao-tone
564                           (cdr (assoc tone lao-transcription-tone-alist))
565                           str (concat (substring str 0 cidx) lao-tone
566                                       (substring str cidx)))))))
567         (list from to (lao-compose-string str)))))
568
569 ;;;###autoload
570 (defun lao-transcribe-roman-to-lao-string (str)
571   "Transcribe Romanized Lao string STR to Lao character string."
572   (let ((from 0)
573         (to (length str))
574         (lao-str "")
575         val)
576     (while (setq val (lao-transcribe-single-roman-syllable-to-lao from to str))
577       (let ((start (car val))
578             (end (nth 1 val))
579             (lao (nth 2 val)))
580         (if (> start from)
581             (setq lao-str (concat lao-str (substring str from start) lao))
582           (setq lao-str (concat lao-str lao)))
583         (setq from end)))
584     (if (< from to)
585         (concat lao-str (substring str from to))
586       lao-str)))
587
588 ;;;###autoload
589 (defun lao-post-read-conversion (len)
590   (lao-compose-region (point) (+ (point) len))
591   len)
592
593 ;;;###autoload
594 (defun lao-composition-function (from to pattern &optional string)
595   "Compose Lao text in the region FROM and TO.
596 The text matches the regular expression PATTERN.
597 Optional 4th argument STRING, if non-nil, is a string containing text
598 to compose.
599
600 The return value is number of composed characters."
601   (if (< (1+ from) to)
602       (progn
603         (if string
604             (compose-string string from to)
605           (compose-region from to))
606         (- to from))))
607
608 ;;;###autoload
609 (defun lao-compose-region (from to)
610   (interactive "r")
611   (save-restriction
612     (narrow-to-region from to)
613     (goto-char (point-min))
614     (with-category-table lao-category-table
615       (while (re-search-forward lao-composition-pattern nil t)
616         (compose-region (match-beginning 0) (point))))))
617
618 ;;
619 (provide 'lao-util)
620
621 ;;; arch-tag: 1f828781-3cb8-4695-88af-8f33222338ce
622 ;;; lao-util.el ends here
623
Note: See TracBrowser for help on using the browser.