1 /* Copyright (C) 2003, 2004
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
22 a definition from a file, a stream, etc. A definitions is converted
23 into the form of plist in the driver.
26 INPUT-METHOD ::= TITLE MAP-LIST MACRO-LIST ? MODULE-LIST ? STATE-LIST
28 TITLE ::= '(' 'title' MTEXT ')'
31 @c MTEXT is a text displayed on the screen when this input method is
35 MAP-LIST ::= '(' 'map' MAP * ')'
37 MAP ::= '(' MAP-NAME RULE * ')'
41 RULE ::= '(' KEYSEQ MAP-ACTION * ')'
43 KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
46 @c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
49 @c MTEXT in the definition of @c KEYSEQ consists of characters that
50 can be generated by a keyboard. Therefore @c MTEXT usually contains
51 only ASCII characters. However, if the input method is intended to be
52 used, for instance, with a West European keyboard, @c MTEXT may
53 contain Latin-1 characters.
55 @c SYMBOL in the definition of @c KEYSEQ must be the return value of
56 the minput_event_to_key () function.
58 @c INTEGER in the definition of @c KEYSEQ must be a valid character
64 ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK |
65 | SHOW | HIDE | PUSHBACK | UNDO | SHIFT | CALL
66 | SET | IF | '(' MACRO-NAME ')'
69 '@0' | '@1' | '@2' | '@3' | '@4' |
70 '@5' | '@6' | '@7' | '@8' | '@9' |
71 '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
74 MACRO-LIST ::= '(' 'macro' MACRO * ')'
76 MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
80 MACRO-ACTION ::= ACTION
83 MODULE-LIST ::= '(' 'module' MODULE * ')'
85 MODULE ::= '(' MODULE-NAME FUNCTION * ')'
87 MODULE-NAME ::= SYMBOL
92 Each @c MODULE declares the name of external module (i.e. dynamic
93 library) and function names exported by the module. If a @c FUNCTION has
94 name "init", it is called with only the default arguments (see the
95 section about @c CALL) when an input context is created for the input
96 method. If a @c FUNCTION has name "fini", it is called with only the
97 default arguments when an input context is destroyed.
100 STATE-LIST ::= '(' 'state' STATE * ')'
102 STATE ::= '(' STATE-NAME BRANCH * ')'
104 STATE-NAME ::= SYMBOL
106 BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
107 | '(' nil BRANCH-ACTION * ')'
108 | '(' t BRANCH-ACTION * ')'
111 In the first form of @c BRANCH, @c MAP-NAME must be an item that appears
112 in @c MAP. In this case, if a key sequence matching one of @c
113 KEYSEQs of @c MAP-NAME is typed, @c BRANCH-ACTIONs are executed.
115 In the second form of @c BRANCH, @c BRANCH-ACTIONs are executed if a
116 key sequence that doesn't match any of @c Branch's of the current
119 In the third form of @c BRANCH, @c BRANCH-ACTIONs are executed if we
120 shift to the current state after handling all typed keys. If the
121 current state is the initial state, @c BRANCH-ACTIONs are executed
122 just after an input context of the input method is created.
125 BRANCH-ACTION ::= ACTION
128 An input method has the following two lists of symbols.
133 A marker is a symbol indicating a character position in the preediting
134 text. The @c MARK action assigns a position to a marker. The
135 position of a marker is referred by the @c MOVE and the @c DELETE actions.
139 A variable is a symbol associated with an integer value. The value of
140 a variable is set by the @c SET action, and is referred by the @c SET,
141 the @c INSERT, and the @c IF actions. All variables are implicitly
146 Each @c PREDEFINED-SYMBOL has a special meaning when used as a marker.
149 <li> @c @@0, @c @@1, @c @@2, @c @@3, @c @@4, @c @@5, @c @@6, @c @@7, @c @@8, @c @@9
151 The 0th, 1st, 2nd, ... 9th position respectively.
153 <li> @c @@<, @c @@=, @c @@>
155 The first, the current, and the last position.
159 The previous and the next position.
163 The previous and the next position where a candidate list changes.
166 Some of the @c PREDEFINED-SYMBOL has a special meaning when used as a candidate
167 index in the @c SELECT action.
171 <li> @c @@<, @c @@=, @c @@>
173 The first, the current, and the last candidate of the current candidate group.
177 The previous candidate. If the current candidate is the first one in
178 the current candidate group, then it means the last candidate in the
179 previous candidate group.
183 The next candidate. If the current candidate is the last one in the
184 current candidate group, then it means the first candidate in the next
189 The candidate in the previous and the next candidate group having the same
190 candidate index as the current one.
193 The arguments and the behavior of each action are listed below.
196 INSERT ::= '(' 'insert' MTEXT ')'
199 | '(' 'insert' SYMBOL ')'
200 | '(' 'insert' '(' CANDIDATES * ')' ')'
201 | '(' CANDIDATES * ')'
203 CANDIDATES ::= MTEXT | '(' MTEXT * ')'
206 The first and second forms insert @c MTEXT before the current position.
208 The third form inserts the character @c INTEGER before the current
211 The fourth form treats @c SYMBOL as a variable, and inserts its value
212 (if it is a valid character code) before the current position.
214 In the fifth and sixth forms, each @c CANDIDATES represents a
215 candidate group, and each element of @c CANDIDATES represents a
216 candidate, i.e. if @c CANDIDATES is an M-text, the candidates are the
217 characters in the M-text; if @c CANDIDATES is a list of M-texts, the
218 candidates are the M-texts in the list.
220 These forms insert the first candidate before the current position.
221 The inserted string is associated with the list of candidates and
222 the information indicating the currently selected candidate.
224 The marker positions affected by the insertion are automatically relocated.
227 DELETE ::= '(' 'delete' SYMBOL ')'
228 | '(' 'delete' INTEGER ')'
231 The first form treats @c SYMBOL as a marker, and deletes characters
232 between the current position and the marker position.
234 The second form treats @c INTEGER as a character position, and deletes
235 characters between the current position and the character position.
237 The marker positions affected by the deletion are automatically relocated.
240 SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
241 | '(' 'select' INTEGER ')'
244 This action first checks if the character just before the current position
245 belongs to a string that is associated with a candidate list. If it is,
246 the action replaces that string with a candidate specified by the
249 The first form treats @c PREDEFINED-SYMBOL as a candidate index (as
250 described above) that specifies a new candidate in the candidate list.
252 The second form treats @c INTEGER as a candidate index that specifies a
253 new candidate in the candidate list.
259 This actions instructs the input method driver to display a candidate
260 list associated with the string before the current position.
266 This action instructs the input method driver to hide the currently
267 displayed candidate list.
270 MOVE ::= '(' 'move' SYMBOL ')'
271 | '(' 'move' INTEGER ')'
274 The first form treats @c SYMBOL as a marker, and makes the marker
275 position be the new current position.
277 The second form treats @c INTEGER as a character position, and makes
278 that position be the new current position.
281 MARK ::= '(' 'mark' SYMBOL ')'
284 This action treats @c SYMBOL as a marker, and sets its position to the
285 current position. @c SYMBOL must not be a @c PREDEFINED-SYMBOL.
289 PUSHBACK :: = '(pushback INTEGER)'
292 This action pushes back the latest @c INTEGER number of key events to the event queue.
298 This action cancels the last key event.
301 SHIFT :: = '(' 'shift' STATE-NAME ')'
304 This action shifts the current state to @c STATE-NAME. @c
305 STATE-NAME must appear in @c STATE-LIST.
308 CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
310 ARG ::= INTEGER | SYMBOL | MTEXT | PLIST
313 This action calls the function @c FUNCTION of external module @c
314 MODULE-NAME. @c MODULE-NAME and @c FUNCTION must appear in @c
317 The function is called with an argument of the type (#MPlist *). The
318 key of the first element is #Mt and its value is a pointer to an
319 object of the type #MInputContext. The key of the second element is
320 #Msymbol and its value is the current state name. @c ARGs are used as
321 the value of the third and later elements. Their keys are determined
322 automatically; if an @c ARG is an integer, the corresponding key is
323 #Minteger; if an @c ARG is a symbol, the corresponding key is
326 The function must return NULL or a value of the type (#MPlist *) that
327 represents a list of actions to take.
330 SET ::= '(' OPERAND SYMBOL1 [ INTEGER | SYMBOL2 ] ')'
332 OPERAND ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
335 This action treats @c SYMBOL1 and @c SYMBOL2 as variables and sets the
336 value of @c SYMBOL1 as below.
338 If @c OPERAND is 'set', it sets the value of @c SYMBOL1 to @c INTEGER or the
341 If @c OPERAND is 'add', it increments the value of @c SYMBOL1 by @c INTEGER
342 or the value of @c SYMBOL2.
344 If @c OPERAND is 'sub', it decrements the value of @c SYMBOL1 by @c INTEGER
345 or the value of @c SYMBOL2.
347 If @c OPERAND is 'mul', it multiplies the value of @c SYMBOL1 by @c INTEGER
348 or the value of @c SYMBOL2.
350 If @c OPERAND is 'div', it divides the value of @c SYMBOL1 by @c INTEGER or
351 the value of @c SYMBOL2.
354 IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 * ')'
356 CONDITION ::= OPERAND VAL1 VAL2
358 ACTION-LIST1 ::= '(' ACTION * ')'
360 ACTION-LIST2 ::= '(' ACTION * ')'
362 OPERAND ::= '=' '<' '>'
364 VAL1 ::= [ INTEGER1 | SYMBOL1 ]
366 VAL2 ::= [ INTEGER2 | SYMBOL2 ]
369 This action performs actions in @c ACTION-LIST1 if @c CONDITION is
370 true, and performs @c ACTION-LIST2 (if any) otherwise.
372 @c SYMBOL1 and @c SYMBOL2 are treated as variables.
376 @section im-example1 EXAMPLE 1
378 This is a very simple example for inputting Latin characters with
379 diacritical marks (acute and cedilla). For instance, when you type:
381 Comme'die-Franc,ais, chic,,
386 Commédie-Français, chic,
391 \hskip5mm\texttt{\footnotesize Comm\'{e}die-Fran\c{c}ais, chic,}
395 The definition of the input method is very simple as below, and it is
396 quite straight forward to extend it to cover all Latin characters.
400 (title "latin-postfix")
403 ("a'" ?á) ("e'" ?é) ("i'" ?í) ("o'" ?ó) ("u'" ?ú) ("c," ?ç)
404 ("A'" ?Á) ("E'" ?É) ("I'" ?Í) ("O'" ?Ó) ("U'" ?Ú) ("C," ?Ç)
405 ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")
407 ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")
416 \texttt{\footnotesize
417 \hskip2mm(title "latin-postfix")\\
420 \hskip6mm ("a'" ?\'{a}) ("e'" ?\'{e}) ("i'" ?\'{i}) ("o'" ?\'{o})
421 ("u'" ?\'{u}) ("c," ?\c{c})\\
422 \hskip6mm ("A'" ?\'{A}) ("E'" ?\'{E}) ("I'" ?\'{I}) ("O'" ?\'{O})
423 ("U'" ?\'{U}) ("C," ?\c{C})\\
424 \hskip6mm ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")\\
425 \hskip6mm ("c,," "c,")\\
426 \hskip6mm ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")\\
427 \hskip6mm ("C,," "C,")))\\
434 @section im-example2 EXAMPLE 2
436 This example is for inputting Unicode characters by typing C-u
437 (Control-u) followed by four hexadecimal numbers. For instance, when
438 you type ("^u" means Control-u):
440 ^u2190^u2191^u2192^u2193
442 you will get this (Unicode arrow symbols):
447 The definition utilizes @c SET and @c IF commands as below:
454 ("0" ?0) ("1" ?1) ... ("9" ?9) ("a" ?A) ("b" ?B) ... ("f" ?F)))
457 (starter (set code 0) (set count 0) (shift unicode)))
463 (mul code 16) (add code this)
466 ((delete @<) (insert code) (shift init))))))
469 @section im-example3 EXAMPLE 3
471 This example is for inputting Chinese characters by typing PinYin key
474 For instance, when you type:
483 The definition utilizes @c CANDIDATE and @c SELECT commands as below.
484 Note that this is just an example, and it ignores such important key
491 ;; The initial character of Pinyin.
493 ("a") ("b") ... ("h") ("j") ... ("t") ("w") ("x") ("y") ("z"))
495 ;; Big table of Pinyin vs the corresponding Chinese characters.
498 ("bei" ("被北备背悲辈杯倍贝碑" ...))
499 ("hao" ("好号毫豪浩耗皓嚎昊郝" ...))
500 ("jing" ("经京精境警竟静惊景敬" ...))
501 ("ni" ("你呢尼泥逆倪匿拟腻妮" ...))
503 ;; Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.
505 ("1" (select 0)) ("2" (select 1)) ... ("9" (select 8)) ("0" (select 9))))
509 ;; When an initial character of Pinyin is typed, re-handle it in
510 ;; "main" state. Anything else is just produced as is.
511 (starter (show) (pushback 1) (shift main)))
514 ;; When a complete Pinyin sequence is typed, shift to "select" state
515 ;; to allow users to select one from the candidates.
516 (pinyin (shift select))
518 ;; When anything else is typed, produce the current candidate (if
519 ;; any), and re-handle the last input in "init" state.
520 (nil (hide) (shift init)))
523 ;; When a number is typed, select the corresponding canidate,
524 ;; produce it, and shift to "init" state.
525 (choose (hide) (shift init))
527 ;; When anything else is typed, produce the current candidate,
528 ;; and re-handle the last input in "init" state.
529 (nil (hide) (shift init))))
535 \fbox{This example is readable only in the documentation of HTML version.}
542 @section im-seealso SEE ALSO
544 @ref mim-list "Input Methods provided by the m17n database",
545 @ref mdbGeneral "mdbGeneral(5)"
549 Copyright (C) 2003, 2004
550 National Institute of Advanced Industrial Science and Technology (AIST)
551 Registration Number H15PRO112
553 This file is part of the m17n database; a sub-part of the m17n
556 The m17n library is free software; you can redistribute it and/or
557 modify it under the terms of the GNU Lesser General Public License
558 as published by the Free Software Foundation; either version 2.1 of
559 the License, or (at your option) any later version.
561 The m17n library is distributed in the hope that it will be useful,
562 but WITHOUT ANY WARRANTY; without even the implied warranty of
563 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
564 Lesser General Public License for more details.
566 You should have received a copy of the GNU Lesser General Public
567 License along with the m17n library; if not, write to the Free
568 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
572 /* Local Variables: */