*** empty log message ***
[m17n/m17n-db.git] / FORMATS / IM.txt
1 /* Copyright (C) 2003, 2004, 2005
2      National Institute of Advanced Industrial Science and Technology (AIST)
3      Registration Number H15PRO112
4    See the end for copying conditions.  */
5
6 /***en
7
8 @page mdbIM Input Method
9
10 @section im-description DESCRIPTION
11
12 The m17n library provides a driver for input methods that are
13 dynamically loadable from the m17n database (see @ref m17nInputMethod
14 @latexonly (P.\pageref{group__m17nInputMethod}) @endlatexonly).
15
16 This section describes the data format that defines those input
17 methods.
18
19 @section im-format SYNTAX and SEMANTICS
20
21 The following data format defines an input method.  The driver loads a
22 definition from a file, a stream, etc.  The definition is converted
23 into the form of plist in the driver.
24
25 @verbatim
26 INPUT-METHOD ::=
27     IM-DECLARATION ? DESCRIPTION ? TITLE ?
28      VARIABLE-LIST ? COMMAND-LIST ?  MODULE-LIST ?
29      MACRO-LIST ? MAP-LIST ? STATE-LIST ?
30
31 IM-DECLARATION ::= '(' 'input-method' LANGUAGE NAME EXTRA-ID ? VERSION ? ')'
32 VERSION ::= '(' 'version' VERSION-NUMBER ')'
33 DESCRIPTION ::= '(' 'description' [ MTEXT-OR-GETTEXT | nil] ')'
34 VARIABLE-LIST ::= '(' 'variable' VARIABLE-DECLARATION * ')'
35 COMMAND-LIST ::= '(' 'command' COMMAND-DECLARATION * ')'
36 TITLE ::= '(' 'title' TITLE-TEXT ')'
37
38 VARIABLE-DECLARATION ::=
39     '(' VAR-NAME [ MTEXT-OR-GETTEXT | nil ] VALUE VALUE-CANDIDATE * ')'
40
41 COMMAND-DECLARATION ::=
42     '(' CMD-NAME [ MTEXT-OR-GETTEXT | nil ] KEYSEQ * ')'
43
44 MTEXT-OR-GETTEXT ::=
45     [ MTEXT | '(' '_' MTEXT ')']
46
47 LANGUAGE ::= SYMBOL
48 NAME ::= SYMBOL
49 EXTRA-ID ::= SYMBOL
50 VERSION ::= MTEXT
51 IM-DESCRIPTION ::= MTEXT
52 VAR-NAME ::= SYMBOL
53 VAR-DESCRIPTION ::= MTEXT
54 VALUE ::= MTEXT | SYMBOL | INTEGER
55 VALUE-CANDIDATE ::= VALUE | '(' RANGE-FROM RANGE-TO ')'
56 RANGE-FROM ::= INTEGER
57 RANGE-TO ::= INTEGER
58 CMD-NAME ::= SYMBOL
59 CMD-DESCRIPTION ::= MTEXT
60 TITLE-TEXT ::= MTEXT
61 @endverbatim
62
63 @c IM-DECLARATION specifies the language and name of this input
64 method.
65
66 When @c LANGUAGE is @c t, the use of the input method is not limited
67 to one language.
68
69 When @c NAME is @c nil, the input method is not standalone, but
70 is expected to be used in other input methods.  In such cases,
71 @EXTRA-ID is required to identify the input method.
72
73 @c VERSION specifies the required minimum version number of the m17n
74 library.  The format is "XX.YY.ZZ" where XX is a major version
75 number, YY is a minor version number, and ZZ is a patch level.
76
77 @c DESCRIPTION specifies the description text of this input method by
78 MTEXT-OR-GETTEXT.  It it takes the second form, the text is translated
79 according to the current locale by "gettext" (if the translation is
80 provided).
81
82 @c TITLE-TEXT is a text displayed on the screen when this input method
83 is active.
84
85 @c VARIABLE-DECLARATION declares a variable used in this input method.
86 If a variable must be initialized to the default value, or is to be
87 customized by a user, it must be declared here.
88
89 @c COMMAND-DECLARATION declares a command used in this input method.
90 If a command must be bound to the default key sequence, or is to be
91 customized by a user, it must be declared here.
92
93 @verbatim
94 MODULE-LIST ::= '(' 'module' MODULE * ')'
95
96 MODULE ::= '(' MODULE-NAME FUNCTION * ')'
97
98 MODULE-NAME ::= SYMBOL
99
100 FUNCTION ::= SYMBOL
101 @endverbatim
102
103 Each @c MODULE declares the name of external module (i.e. dynamic
104 library) and function names exported by the module.  If a @c FUNCTION has
105 name "init", it is called with only the default arguments (see the
106 section about @c CALL) when an input context is created for the input
107 method.  If a @c FUNCTION has name "fini", it is called with only the
108 default arguments when an input context is destroyed.
109
110 @verbatim
111 MACRO-LIST ::=  MACRO-INCLUSION ? '(' 'macro' MACRO * ')' MACRO-INCLUSION ?
112
113 MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
114
115 MACRO-NAME ::= SYMBOL
116
117 MACRO-ACTION ::= ACTION
118
119 TAGS ::= `(` LANGUAGE NAME EXTRA-ID ? `)`
120
121 MACRO-INCLUSION ::= '(' 'include' TAGS 'macro' MACRO-NAME ? ')'
122
123 @endverbatim
124
125 @c MACRO-INCLUSION includes macros from another input method specified by @c TAGS.
126 When @c MACRO-NAME is not given, all macros from the input method are included.
127
128 @verbatim
129 MAP-LIST ::= MAP-INCLUSION ? '(' 'map' MAP * ')' MAP-INCLUSION ?
130
131 MAP ::= '(' MAP-NAME RULE * ')'
132
133 MAP-NAME ::= SYMBOL
134
135 RULE ::= '(' KEYSEQ MAP-ACTION * ')'
136
137 KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
138
139 MAP-INCLUSION ::= '(' 'include' TAGS 'map' MAP-NAME ? ')'
140
141 @endverbatim
142
143 When an input system is never standalone and always included in
144 another system, @c MAP-LIST can be omitted.
145
146 @c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
147 nil.
148
149 @c MTEXT in the definition of @c KEYSEQ consists of characters that
150 can be generated by a keyboard.  Therefore @c MTEXT usually contains
151 only ASCII characters.  However, if the input method is intended to be
152 used, for instance, with a West European keyboard, @c MTEXT may
153 contain Latin-1 characters.
154
155 @c SYMBOL in the definition of @c KEYSEQ must be the return value of
156 the minput_event_to_key () function.  Under the X window system, you
157 can quickly check the value using the @c xev command.  For example,
158 the return key, the backspace key, and the 0 key on the keypad are
159 represented as @c (Return) , @c (BackSpace) , and @c (KP_0)
160 respectively.  If the shift, control, meta, alt, super, and hyper
161 modifiers are used, they are represented by the S- , C- , M- , A- , s-
162 , and H- prefixes respectively in this oreder.  Thus, "return with
163 shift with meta with hyper" is @c (S-M-H-Return) .  Note that "a with
164 shift" .. "z with shift" are represented simply as A .. Z . Thus "a
165 with shift with meta with hyper" is @c (M-H-A) .
166
167 @c INTEGER in the definition of @c KEYSEQ must be a valid character
168 code.
169
170 @c MAP-INCLUSION includes maps from another input method specified by @c TAGS.
171 When @c MAP-NAME is not given, all maps from the input method are included.
172
173 @verbatim
174 MAP-ACTION ::= ACTION
175
176 ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK
177            | SHOW | HIDE | PUSHBACK | POP | UNDO 
178            | COMMIT | UNHANDLE | SHIFT | CALL
179            | SET | IF | COND | '(' MACRO-NAME ')'
180
181 PREDEFINED-SYMBOL ::=
182     '@0' | '@1' | '@2' | '@3' | '@4'
183     | '@5' | '@6' | '@7' | '@8' | '@9'
184     | '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
185     | '@@'
186     | '@-0' | '@-N' | '@+N'
187 @endverbatim
188
189 @verbatim
190 STATE-LIST ::= STATE-INCUSION ? '(' 'state' STATE * ')'  STATE-INCUSION ?
191
192 STATE ::= '(' STATE-NAME [ STATE-TITLE-TEXT ] BRANCH * ')'
193
194 STATE-NAME ::= SYMBOL
195
196 STATE-TITLE-TEXT ::= MTEXT
197
198 BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
199            | '(' nil BRANCH-ACTION * ')'
200            | '(' t BRANCH-ACTION * ')'
201
202 STATE-INCLUSION ::= '(' 'include' TAGS 'state' STATE-NAME ? ')'
203
204 @endverbatim
205
206 When an input system is never standalone and always included in
207 another system, @c STATE-LIST can be omitted.
208
209 @c STATE-INCLUSION includes states from another input method specified by @c TAGS.
210 When @c STATE-NAME is not given, all states from the input method are included.
211
212 The optional @c STATE-TITLE-TEXT specifies a title text displayed on
213 the screen when the input method is in this state.  If @c
214 STATE-TITLE-TEXT is omitted, @c TITLE-TEXT is used.
215
216 In the first form of @c BRANCH, @c MAP-NAME must be an item that
217 appears in @c MAP.  In this case, if a key sequence matching one of @c
218 KEYSEQs of @c MAP-NAME is typed, @c BRANCH-ACTIONs are executed.
219
220 In the second form of @c BRANCH, @c BRANCH-ACTIONs are executed if a
221 key sequence that doesn't match any of @c Branch's of the current
222 state is typed.
223
224 In the third form of @c BRANCH, @c BRANCH-ACTIONs are executed when
225 shifted to the current state.  If the current state is the initial
226 state, @c BRANCH-ACTIONs are executed also when an input context of
227 the input method is created.
228
229 @verbatim
230 BRANCH-ACTION ::= ACTION
231 @endverbatim
232
233 An input method has the following two lists of symbols.
234
235 <ul>
236 <li> marker list
237
238 A marker is a symbol indicating a character position in the preediting
239 text.  The @c MARK action assigns a position to a marker.  The
240 position of a marker is referred by the @c MOVE and the @c DELETE actions.
241
242 <li> variable list
243
244 A variable is a symbol associated with an integer value.  The value of
245 a variable is set by the @c SET action, and is referred by the @c SET,
246 the @c INSERT, and the @c IF actions.  All variables are implicitly
247 initialized to zero.
248
249 </ul>
250
251 Each @c PREDEFINED-SYMBOL has a special meaning when used as a marker.
252
253 <ul>
254 <li> @c @@0, @c @@1, @c @@2, @c @@3, @c @@4, @c @@5, @c @@6, @c @@7, @c @@8, @c @@9
255
256 The 0th, 1st, 2nd, ... 9th position respectively.
257
258 <li> @c @@<, @c @@=, @c @@>
259
260 The first, the current, and the last position.
261
262 <li> @c @@-, @c @@+
263
264 The previous and the next position.
265
266 <li> @c @@[, @c @@]
267
268 The previous and the next position where a candidate list changes.
269 </ul>
270
271 Some of the @c PREDEFINED-SYMBOL has a special meaning when used as a candidate
272 index in the @c SELECT action.
273
274 <ul>
275
276 <li> @c @@<, @c @@=, @c @@>
277
278 The first, the current, and the last candidate of the current candidate group.
279
280 <li> @c @@-
281
282 The previous candidate.  If the current candidate is the first one in
283 the current candidate group, then it means the last candidate in the
284 previous candidate group.
285
286 <li> @c @@+
287
288 The next candidate.  If the current candidate is the last one in the
289 current candidate group, then it means the first candidate in the next
290 candidate group.
291
292 <li> @c @@[, @c @@]
293
294 The candidate in the previous and the next candidate group having the same
295 candidate index as the current one.
296 </ul>
297
298 And, this also has a special meaning.
299
300 <ul>
301 <li> @c @@@
302
303 Number of handled keys at that moment.
304
305 </ul>
306
307 These are for supporting surround text handling.
308
309 <ul>
310 <li> @c @@-0
311
312 -1 if surrounding text is supported, -2 if not.
313
314 <li> @c @@-N
315
316 Here, @c N is a positive integer.  The value is the Nth previous
317 character in the preedit buffer.  If there are only M (M<N) previous
318 characters in it, the value is the (N-M)th previous character from the
319 inputting spot.  When this is used as the argument of @c delete
320 action, it specifies the number of characters to be deleted.
321
322 <li> @c @@+N
323
324 Here, @c N is a positive integer.  The value is the Nth following
325 character in the preedit buffer.  If there are only M (M<N) following
326 characters in it, the value is the (N-M)th following character from
327 the inputting spot.  When this is used as the argument of @c delete
328 action, it specifies the number of characters to be deleted.
329 </ul>
330
331 The arguments and the behavior of each action are listed below.
332
333 @verbatim
334 INSERT ::= '(' 'insert' MTEXT ')'
335            | MTEXT
336            | INTEGER
337            | '(' 'insert' SYMBOL ')'
338            | '(' 'insert' '(' CANDIDATES * ')' ')'
339            | '(' CANDIDATES * ')' 
340
341 CANDIDATES ::= MTEXT | '(' MTEXT * ')'
342 @endverbatim
343
344 The first and second forms insert @c MTEXT before the current position.
345
346 The third form inserts the character @c INTEGER before the current
347 position.
348
349 The fourth form treats @c SYMBOL as a variable, and inserts its value
350 (if it is a valid character code) before the current position.
351
352 In the fifth and sixth forms, each @c CANDIDATES represents a
353 candidate group, and each element of @c CANDIDATES represents a
354 candidate, i.e. if @c CANDIDATES is an M-text, the candidates are the
355 characters in the M-text; if @c CANDIDATES is a list of M-texts, the
356 candidates are the M-texts in the list.
357
358 These forms insert the first candidate before the current position.
359 The inserted string is associated with the list of candidates and
360 the information indicating the currently selected candidate.
361
362 The marker positions affected by the insertion are automatically relocated.
363
364 @verbatim
365 DELETE ::= '(' 'delete' SYMBOL ')'
366            | '(' 'delete' INTEGER ')'
367 @endverbatim
368
369 The first form treats @c SYMBOL as a marker, and deletes characters
370 between the current position and the marker position.
371
372 The second form treats @c INTEGER as a character position, and deletes
373 characters between the current position and the character position.
374
375 The marker positions affected by the deletion are automatically relocated.
376
377 @verbatim
378 SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
379            | '(' 'select' INTEGER ')'
380            | '(' 'select' SYMBOL ')'
381 @endverbatim
382
383 This action first checks if the character just before the current position
384 belongs to a string that is associated with a candidate list.  If it is,
385 the action replaces that string with a candidate specified by the
386 argument.
387
388 The first form treats @c PREDEFINED-SYMBOL as a candidate index (as
389 described above) that specifies a new candidate in the candidate list.
390
391 The second form treats @c INTEGER as a candidate index that specifies a
392 new candidate in the candidate list.
393
394 In the third form, @c SYMBOL must have a integer value, and it is treated 
395 as a candidate index.
396
397 @verbatim SHOW ::= '(show)' @endverbatim
398
399 This actions instructs the input method driver to display a candidate
400 list associated with the string before the current position.
401
402 @verbatim
403 HIDE ::= '(hide)'
404 @endverbatim
405
406 This action instructs the input method driver to hide the currently
407 displayed candidate list.
408
409 @verbatim
410 MOVE ::= '(' 'move' SYMBOL ')'
411          | '(' 'move' INTEGER ')'
412 @endverbatim
413
414 The first form treats @c SYMBOL as a marker, and makes the marker
415 position be the new current position.
416
417 The second form treats @c INTEGER as a character position, and makes
418 that position be the new current position.
419
420 @verbatim
421 MARK ::= '(' 'mark' SYMBOL ')'
422 @endverbatim
423
424 This action treats @c SYMBOL as a marker, and sets its position to the
425 current position.  @c SYMBOL must not be a @c PREDEFINED-SYMBOL.
426
427 @verbatim
428 PUSHBACK :: = '(' 'pushback' INTEGER ')'
429               | '(' 'pushback' KEYSEQ ')'
430 @endverbatim
431
432 The first form pushes back the latest @c INTEGER number of key events
433 to the event queue if @c INTEGER is positive, and pushes back all key
434 events if @c INTEGER is zero.
435
436 The second form pushes back keys in @c KEYSEQ to the event queue.
437
438 @verbatim
439 POP ::= '(' 'pop' ')'
440 @endverbatim
441
442 This action pops the first key event that is not yet handled from the
443 event queue.
444
445 @verbatim
446 UNDO :: = '(' 'undo' [ INTEGER | SYMBOL ] ')'
447 @endverbatim
448
449 If there's no argument, this action cancels the last two key events
450 (i.e. the one that invoked this command, and the previous one).
451
452 If there's an integer argument NUM, it must be positive or negative
453 (not zero).  If positive, from the NUMth to the last events are
454 canceled.  If negative the last (- NUM) events are canceled.
455
456 If there's a symbol argument, it must be resolved to an integer number
457 and the number is treated as the actual argument as above.
458
459 @verbatim
460 COMMIT :: = '(commit)'
461 @endverbatim
462
463 This action commits the current preedit.
464
465 @verbatim
466 UNHANDLE :: = '(unhandle)'
467 @endverbatim
468
469 This action commits the current preedit and return the last key as
470 unhandled.
471
472 @verbatim
473 SHIFT :: = '(' 'shift' STATE-NAME ')'
474 @endverbatim
475
476 This action shifts the current state to @c STATE-NAME.  @c
477 STATE-NAME must appear in @c STATE-LIST.
478
479 @verbatim
480 CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
481
482 ARG ::= INTEGER | SYMBOL | MTEXT | PLIST
483 @endverbatim
484
485 This action calls the function @c FUNCTION of external module @c
486 MODULE-NAME.  @c MODULE-NAME and @c FUNCTION must appear in @c
487 MODULE-LIST.
488
489 The function is called with an argument of the type (#MPlist *).  The
490 key of the first element is #Mt and its value is a pointer to an
491 object of the type #MInputContext.  The key of the second element is
492 #Msymbol and its value is the current state name.  @c ARGs are used as
493 the value of the third and later elements.  Their keys are determined
494 automatically; if an @c ARG is an integer, the corresponding key is
495 #Minteger; if an @c ARG is a symbol, the corresponding key is
496 #Msymbol, etc.
497
498 The function must return NULL or a value of the type (#MPlist *) that
499 represents a list of actions to take.
500
501 @verbatim
502 SET ::= '(' CMD SYMBOL1 EXPRESSION ')'
503
504 CMD ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
505
506 EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERATOR EXPRESSION * ')'
507
508 OPERATOR ::= '+' | '-' | '*' | '/' | '|' | '&' | '!'
509             | '=' | '<' | '>' | '<=' | '>='
510
511 @endverbatim
512
513 This action treats @c SYMBOL1 and @c SYMBOL2 as variables and sets the
514 value of @c SYMBOL1 as below.
515
516 If @c CMD is 'set', it sets the value of @c SYMBOL1 to the value of @c
517 EXPRESSION.
518
519 If @c CMD is 'add', it increments the value of @c SYMBOL1 by the value
520 of @c EXPRESSION.
521
522 If @c CMD is 'sub', it decrements the value of @c SYMBOL1 by the value
523 of @c EXPRESSION.
524
525 If @c CMD is 'mul', it multiplies the value of @c SYMBOL1 by the value
526 of @c EXPRESSION.
527
528 If @c CMD is 'div', it divides the value of @c SYMBOL1 by the value of
529 @c EXPRESSION.
530
531 @verbatim
532 IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ')'
533
534 CONDITION ::= [ '=' | '<' | '>' | '<=' | '>=' ] EXPRESSION1 EXPRESSION2
535
536 ACTION-LIST1 ::= '(' ACTION * ')'
537
538 ACTION-LIST2 ::= '(' ACTION * ')'
539 @endverbatim
540
541 This action performs actions in @c ACTION-LIST1 if @c CONDITION is
542 true, and performs @c ACTION-LIST2 (if any) otherwise.
543
544 @c SYMBOL1 and @c SYMBOL2 are treated as variables.
545
546 @verbatim
547 COND ::= '(' 'cond' [ '(' EXPRESSION ACTION * ') ] * ')'
548 @endverbatim
549
550 This action performs the first action @c ACTION whose corresponding
551 @c EXPRESSION has nonzero value.
552
553 @ifnot FOR-MAN
554
555 @section im-example1 EXAMPLE 1
556
557 This is a very simple example for inputting Latin characters with
558 diacritical marks (acute and cedilla).  For instance, when you type:
559 @verbatim
560     Comme'die-Franc,aise, chic,,
561 @endverbatim
562 you will get this:
563 @if FOR-HTML
564 @verbatim
565     Commédie-Française, chic,
566 @endverbatim
567 @endif
568 @if FOR-LATEX
569 @latexonly
570 \hskip5mm\texttt{\footnotesize Comm\'{e}die-Fran\c{c}aise, chic,}
571 @endlatexonly
572 @endif
573
574 The definition of the input method is very simple as below, and it is
575 quite straight forward to extend it to cover all Latin characters.
576
577 @if FOR-HTML
578 @verbatim
579 (title "latin-postfix")
580 (map
581  (trans
582   ("a'" ?á) ("e'" ?é) ("i'" ?í) ("o'" ?ó) ("u'" ?ú) ("c," ?ç)
583   ("A'" ?Á) ("E'" ?É) ("I'" ?Í) ("O'" ?Ó) ("U'" ?Ú) ("C," ?Ç)
584   ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")
585   ("c,," "c,")
586   ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")
587   ("C,," "C,")))
588 (state
589  (init
590   (trans)))
591 @endverbatim
592 @endif
593 @if FOR-LATEX
594 @latexonly
595 \texttt{\footnotesize
596 \hskip2mm(title "latin-postfix")\\
597 \hskip2mm(map\\
598 \hskip4mm (trans\\
599 \hskip6mm  ("a'" ?\'{a}) ("e'" ?\'{e}) ("i'" ?\'{i}) ("o'" ?\'{o})
600 ("u'" ?\'{u}) ("c," ?\c{c})\\
601 \hskip6mm  ("A'" ?\'{A}) ("E'" ?\'{E}) ("I'" ?\'{I}) ("O'" ?\'{O})
602 ("U'" ?\'{U}) ("C," ?\c{C})\\
603 \hskip6mm  ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")\\
604 \hskip6mm  ("c,," "c,")\\
605 \hskip6mm  ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")\\
606 \hskip6mm  ("C,," "C,")))\\
607 \hskip2mm(state\\
608 \hskip4mm (init\\
609 \hskip6mm  (trans)))}
610 @endlatexonly
611 @endif
612
613 @section im-example2 EXAMPLE 2
614
615 This example is for inputting Unicode characters by typing C-u
616 (Control-u) followed by four hexadecimal digits.  For instance, when
617 you type ("^u" means Control-u):
618 @verbatim
619     ^u2190^u2191^u2192^u2193
620 @endverbatim
621 you will get this (Unicode arrow symbols):
622 @if FOR-LATEX
623 @verbatim
624     $\leftarrow \uparrow \rightarrow \downarrow
625 @endverbatim
626 @endif
627 @if FOR-HTML
628 @verbatim
629     ←↑→↓
630 @endverbatim
631 @endif
632
633 The definition utilizes @c SET and @c IF commands as below:
634 @verbatim
635 (title "UNICODE")
636 (map
637  (starter
638   ((C-U) "U+"))
639  (hex
640   ("0" ?0) ("1" ?1) ... ("9" ?9) ("a" ?A) ("b" ?B) ... ("f" ?F)))
641 (state
642  (init
643   (starter (set code 0) (set count 0) (shift unicode)))
644  (unicode
645   (hex (set this @-)
646        (< this ?A
647           ((sub this 48))
648           ((sub this 55)))
649        (mul code 16) (add code this)
650        (add count 1)
651        (= count 4
652           ((delete @<) (insert code) (shift init))))))
653 @endverbatim
654
655 @section im-example3 EXAMPLE 3
656
657 This example is for inputting Chinese characters by typing PinYin key
658 sequence.
659 @if FOR-HTML
660 For instance, when you type:
661 @verbatim
662     nihaobei2jing2
663 @endverbatim
664 you will get:
665 @verbatim
666     你好北京
667 @endverbatim
668
669 The definition utilizes @c CANDIDATE and @c SELECT commands as below.
670 Note that this is just an example, and it ignores such important key
671 as Backspace.
672
673 @verbatim
674 (title "拼")
675
676 (map
677  ;; The initial character of Pinyin.
678  (starter
679   ("a") ("b") ... ("h") ("j") ... ("t") ("w") ("x") ("y") ("z"))
680
681  ;; Big table of Pinyin vs the corresponding Chinese characters.
682  (pinyin
683   ...
684   ("bei" ("被北备背悲辈杯倍贝碑" ...))
685   ("hao" ("好号毫豪浩耗皓嚎昊郝" ...))
686   ("jing" ("经京精境警竟静惊景敬" ...))
687   ("ni" ("你呢尼泥逆倪匿拟腻妮" ...))
688   ...)
689  ;; Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.
690  (choose
691   ("1" (select 0)) ("2" (select 1)) ... ("9" (select 8)) ("0" (select 9))))
692
693 (state
694  (init
695   ;; When an initial character of Pinyin is typed, re-handle it in
696   ;; "main" state.  Anything else is just produced as is.
697   (starter (show) (pushback 1) (shift main)))
698
699  (main
700   ;; When a complete Pinyin sequence is typed, shift to "select" state
701   ;; to allow users to select one from the candidates.
702   (pinyin (shift select))
703
704   ;; When anything else is typed, produce the current candidate (if
705   ;; any), and re-handle the last input in "init" state.
706   (nil (hide) (shift init)))
707
708  (select
709   ;; When a number is typed, select the corresponding canidate,
710   ;; produce it, and shift to "init" state.
711   (choose (hide) (shift init))
712
713   ;; When anything else is typed, produce the current candidate,
714   ;; and re-handle the last input in "init" state.
715   (nil (hide) (shift init))))
716 @endverbatim
717
718 @elseif FOR-LATEX
719 @latexonly
720 \begin{center}
721 \fbox{This example is readable only in the documentation of HTML version.}
722 \end{center}
723 @endlatexonly
724 @endif
725
726 @endif
727
728 @section im-seealso SEE ALSO
729
730 @ref mim-list "Input Methods provided by the m17n database",
731 @ref mdbGeneral "mdbGeneral(5)"
732 */
733
734 /* 
735 Copyright (C) 2003, 2004, 2005
736   National Institute of Advanced Industrial Science and Technology (AIST)
737   Registration Number H15PRO112
738
739 This file is part of the m17n database; a sub-part of the m17n
740 library.
741
742 The m17n library is free software; you can redistribute it and/or
743 modify it under the terms of the GNU Lesser General Public License
744 as published by the Free Software Foundation; either version 2.1 of
745 the License, or (at your option) any later version.
746
747 The m17n library is distributed in the hope that it will be useful,
748 but WITHOUT ANY WARRANTY; without even the implied warranty of
749 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
750 Lesser General Public License for more details.
751
752 You should have received a copy of the GNU Lesser General Public
753 License along with the m17n library; if not, write to the Free
754 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
755 Boston, MA 02110-1301, USA.
756 */
757
758 /* Local Variables: */
759 /* coding: utf-8 */
760 /* End: */