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. */
8 @page mdbIM Input Method
10 @section im-description DESCRIPTION
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).
16 This section describes the data format that defines those input
19 @section im-format SYNTAX and SEMANTICS
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.
27 IM-DECLARATION ? DESCRIPTION ? TITLE ?
28 VARIABLE-LIST ? COMMAND-LIST ? MODULE-LIST ?
29 MACRO-LIST ? MAP-LIST ? STATE-LIST ?
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 ')'
38 VARIABLE-DECLARATION ::=
39 '(' VAR-NAME [ MTEXT-OR-GETTEXT | nil ] VALUE VALUE-CANDIDATE * ')'
41 COMMAND-DECLARATION ::=
42 '(' CMD-NAME [ MTEXT-OR-GETTEXT | nil ] KEYSEQ * ')'
45 [ MTEXT | '(' '_' MTEXT ')']
51 IM-DESCRIPTION ::= MTEXT
53 VAR-DESCRIPTION ::= MTEXT
54 VALUE ::= MTEXT | SYMBOL | INTEGER
55 VALUE-CANDIDATE ::= VALUE | '(' RANGE-FROM RANGE-TO ')'
56 RANGE-FROM ::= INTEGER
59 CMD-DESCRIPTION ::= MTEXT
63 @c IM-DECLARATION specifies the language and name of this input
66 When @c LANGUAGE is @c t, the use of the input method is not limited
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.
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.
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
82 @c TITLE-TEXT is a text displayed on the screen when this input method
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.
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.
94 MODULE-LIST ::= '(' 'module' MODULE * ')'
96 MODULE ::= '(' MODULE-NAME FUNCTION * ')'
98 MODULE-NAME ::= SYMBOL
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.
111 MACRO-LIST ::= MACRO-INCLUSION ? '(' 'macro' MACRO * ')' MACRO-INCLUSION ?
113 MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
115 MACRO-NAME ::= SYMBOL
117 MACRO-ACTION ::= ACTION
119 TAGS ::= `(` LANGUAGE NAME EXTRA-ID ? `)`
121 MACRO-INCLUSION ::= '(' 'include' TAGS 'macro' MACRO-NAME ? ')'
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.
129 MAP-LIST ::= MAP-INCLUSION ? '(' 'map' MAP * ')' MAP-INCLUSION ?
131 MAP ::= '(' MAP-NAME RULE * ')'
135 RULE ::= '(' KEYSEQ MAP-ACTION * ')'
137 KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
139 MAP-INCLUSION ::= '(' 'include' TAGS 'map' MAP-NAME ? ')'
143 When an input system is never standalone and always included in
144 another system, @c MAP-LIST can be omitted.
146 @c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
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.
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) .
167 @c INTEGER in the definition of @c KEYSEQ must be a valid character
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.
174 MAP-ACTION ::= ACTION
176 ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK
177 | SHOW | HIDE | PUSHBACK | POP | UNDO
178 | COMMIT | UNHANDLE | SHIFT | CALL
179 | SET | IF | COND | '(' MACRO-NAME ')'
181 PREDEFINED-SYMBOL ::=
182 '@0' | '@1' | '@2' | '@3' | '@4'
183 | '@5' | '@6' | '@7' | '@8' | '@9'
184 | '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
186 | '@-0' | '@-N' | '@+N'
190 STATE-LIST ::= STATE-INCUSION ? '(' 'state' STATE * ')' STATE-INCUSION ?
192 STATE ::= '(' STATE-NAME [ STATE-TITLE-TEXT ] BRANCH * ')'
194 STATE-NAME ::= SYMBOL
196 STATE-TITLE-TEXT ::= MTEXT
198 BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
199 | '(' nil BRANCH-ACTION * ')'
200 | '(' t BRANCH-ACTION * ')'
202 STATE-INCLUSION ::= '(' 'include' TAGS 'state' STATE-NAME ? ')'
206 When an input system is never standalone and always included in
207 another system, @c STATE-LIST can be omitted.
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.
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.
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.
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
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.
230 BRANCH-ACTION ::= ACTION
233 An input method has the following two lists of symbols.
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.
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
251 Each @c PREDEFINED-SYMBOL has a special meaning when used as a marker.
254 <li> @c @@0, @c @@1, @c @@2, @c @@3, @c @@4, @c @@5, @c @@6, @c @@7, @c @@8, @c @@9
256 The 0th, 1st, 2nd, ... 9th position respectively.
258 <li> @c @@<, @c @@=, @c @@>
260 The first, the current, and the last position.
264 The previous and the next position.
268 The previous and the next position where a candidate list changes.
271 Some of the @c PREDEFINED-SYMBOL has a special meaning when used as a candidate
272 index in the @c SELECT action.
276 <li> @c @@<, @c @@=, @c @@>
278 The first, the current, and the last candidate of the current candidate group.
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.
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
294 The candidate in the previous and the next candidate group having the same
295 candidate index as the current one.
298 And, this also has a special meaning.
303 Number of handled keys at that moment.
307 These are for supporting surround text handling.
312 -1 if surrounding text is supported, -2 if not.
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.
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.
331 The arguments and the behavior of each action are listed below.
334 INSERT ::= '(' 'insert' MTEXT ')'
337 | '(' 'insert' SYMBOL ')'
338 | '(' 'insert' '(' CANDIDATES * ')' ')'
339 | '(' CANDIDATES * ')'
341 CANDIDATES ::= MTEXT | '(' MTEXT * ')'
344 The first and second forms insert @c MTEXT before the current position.
346 The third form inserts the character @c INTEGER before the current
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.
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.
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.
362 The marker positions affected by the insertion are automatically relocated.
365 DELETE ::= '(' 'delete' SYMBOL ')'
366 | '(' 'delete' INTEGER ')'
369 The first form treats @c SYMBOL as a marker, and deletes characters
370 between the current position and the marker position.
372 The second form treats @c INTEGER as a character position, and deletes
373 characters between the current position and the character position.
375 The marker positions affected by the deletion are automatically relocated.
378 SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
379 | '(' 'select' INTEGER ')'
380 | '(' 'select' SYMBOL ')'
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
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.
391 The second form treats @c INTEGER as a candidate index that specifies a
392 new candidate in the candidate list.
394 In the third form, @c SYMBOL must have a integer value, and it is treated
395 as a candidate index.
397 @verbatim SHOW ::= '(show)' @endverbatim
399 This actions instructs the input method driver to display a candidate
400 list associated with the string before the current position.
406 This action instructs the input method driver to hide the currently
407 displayed candidate list.
410 MOVE ::= '(' 'move' SYMBOL ')'
411 | '(' 'move' INTEGER ')'
414 The first form treats @c SYMBOL as a marker, and makes the marker
415 position be the new current position.
417 The second form treats @c INTEGER as a character position, and makes
418 that position be the new current position.
421 MARK ::= '(' 'mark' SYMBOL ')'
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.
428 PUSHBACK :: = '(' 'pushback' INTEGER ')'
429 | '(' 'pushback' KEYSEQ ')'
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.
436 The second form pushes back keys in @c KEYSEQ to the event queue.
439 POP ::= '(' 'pop' ')'
442 This action pops the first key event that is not yet handled from the
446 UNDO :: = '(' 'undo' [ INTEGER | SYMBOL ] ')'
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).
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.
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.
460 COMMIT :: = '(commit)'
463 This action commits the current preedit.
466 UNHANDLE :: = '(unhandle)'
469 This action commits the current preedit and return the last key as
473 SHIFT :: = '(' 'shift' STATE-NAME ')'
476 This action shifts the current state to @c STATE-NAME. @c
477 STATE-NAME must appear in @c STATE-LIST.
480 CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
482 ARG ::= INTEGER | SYMBOL | MTEXT | PLIST
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
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
498 The function must return NULL or a value of the type (#MPlist *) that
499 represents a list of actions to take.
502 SET ::= '(' CMD SYMBOL1 EXPRESSION ')'
504 CMD ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
506 EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERATOR EXPRESSION * ')'
508 OPERATOR ::= '+' | '-' | '*' | '/' | '|' | '&' | '!'
509 | '=' | '<' | '>' | '<=' | '>='
513 This action treats @c SYMBOL1 and @c SYMBOL2 as variables and sets the
514 value of @c SYMBOL1 as below.
516 If @c CMD is 'set', it sets the value of @c SYMBOL1 to the value of @c
519 If @c CMD is 'add', it increments the value of @c SYMBOL1 by the value
522 If @c CMD is 'sub', it decrements the value of @c SYMBOL1 by the value
525 If @c CMD is 'mul', it multiplies the value of @c SYMBOL1 by the value
528 If @c CMD is 'div', it divides the value of @c SYMBOL1 by the value of
532 IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ')'
534 CONDITION ::= [ '=' | '<' | '>' | '<=' | '>=' ] EXPRESSION1 EXPRESSION2
536 ACTION-LIST1 ::= '(' ACTION * ')'
538 ACTION-LIST2 ::= '(' ACTION * ')'
541 This action performs actions in @c ACTION-LIST1 if @c CONDITION is
542 true, and performs @c ACTION-LIST2 (if any) otherwise.
544 @c SYMBOL1 and @c SYMBOL2 are treated as variables.
547 COND ::= '(' 'cond' [ '(' EXPRESSION ACTION * ') ] * ')'
550 This action performs the first action @c ACTION whose corresponding
551 @c EXPRESSION has nonzero value.
555 @section im-example1 EXAMPLE 1
557 This is a very simple example for inputting Latin characters with
558 diacritical marks (acute and cedilla). For instance, when you type:
560 Comme'die-Franc,aise, chic,,
565 Commédie-Française, chic,
570 \hskip5mm\texttt{\footnotesize Comm\'{e}die-Fran\c{c}aise, chic,}
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.
579 (title "latin-postfix")
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'")
586 ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")
595 \texttt{\footnotesize
596 \hskip2mm(title "latin-postfix")\\
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,")))\\
613 @section im-example2 EXAMPLE 2
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):
619 ^u2190^u2191^u2192^u2193
621 you will get this (Unicode arrow symbols):
624 $\leftarrow \uparrow \rightarrow \downarrow
633 The definition utilizes @c SET and @c IF commands as below:
640 ("0" ?0) ("1" ?1) ... ("9" ?9) ("a" ?A) ("b" ?B) ... ("f" ?F)))
643 (starter (set code 0) (set count 0) (shift unicode)))
649 (mul code 16) (add code this)
652 ((delete @<) (insert code) (shift init))))))
655 @section im-example3 EXAMPLE 3
657 This example is for inputting Chinese characters by typing PinYin key
660 For instance, when you type:
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
677 ;; The initial character of Pinyin.
679 ("a") ("b") ... ("h") ("j") ... ("t") ("w") ("x") ("y") ("z"))
681 ;; Big table of Pinyin vs the corresponding Chinese characters.
684 ("bei" ("被北备背悲辈杯倍贝碑" ...))
685 ("hao" ("好号毫豪浩耗皓嚎昊郝" ...))
686 ("jing" ("经京精境警竟静惊景敬" ...))
687 ("ni" ("你呢尼泥逆倪匿拟腻妮" ...))
689 ;; Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.
691 ("1" (select 0)) ("2" (select 1)) ... ("9" (select 8)) ("0" (select 9))))
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)))
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))
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)))
709 ;; When a number is typed, select the corresponding canidate,
710 ;; produce it, and shift to "init" state.
711 (choose (hide) (shift init))
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))))
721 \fbox{This example is readable only in the documentation of HTML version.}
728 @section im-seealso SEE ALSO
730 @ref mim-list "Input Methods provided by the m17n database",
731 @ref mdbGeneral "mdbGeneral(5)"
735 Copyright (C) 2003, 2004, 2005
736 National Institute of Advanced Industrial Science and Technology (AIST)
737 Registration Number H15PRO112
739 This file is part of the m17n database; a sub-part of the m17n
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.
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.
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.
758 /* Local Variables: */