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
22 a definition from a file, a stream, etc. A definitions is converted
23 into the form of plist in the driver.
27 IM-DECLARATION ? DESCRIPTION ? VARIABLE-LIST ? COMMAND-LIST ?
28 TITLE MAP-LIST MACRO-LIST ? MODULE-LIST ? STATE-LIST
30 IM-DECLARATION ::= '(' 'input-method' LANGUAGE NAME ')'
31 DESCRIPTION ::= '(' 'description' MTEXT ')'
32 VARIABLE-LIST ::= '(' 'variable' VARIABLE-DECLARATION * ')'
33 COMMAND-LIST ::= '(' 'command' COMMAND-DECLARATION * ')'
34 TITLE ::= '(' 'title' TITLE-TEXT ')'
36 VARIABLE-DECLARATION ::=
37 '(' VAR-NAME [ VAR-DESCRIPTION | nil ] VALUE VALUE-CANDIDATE * ')'
39 COMMAND-DECLARATION ::=
40 '(' CMD-NAME [ CMD-DESCRIPTION | nil ] KEYSEQ * ')'
44 IM-DESCRIPTION ::= MTEXT
46 VAR-DESCRIPTION ::= MTEXT
47 VALUE ::= MTEXT | SYMBOL | INTEGER
48 VALUE-CANDIDATE ::= VALUE | '(' RANGE-FROM RANGE-TO ')'
49 RANGE-FROM ::= INTEGER
52 CMD-DESCRIPTION ::= MTEXT
64 @c VARIABLE-DECLARATION
68 @c COMMAND-DECLARATION
72 @c TITLE-TEXT is a text displayed on the screen when this input method
76 MAP-LIST ::= '(' 'map' MAP * ')'
78 MAP ::= '(' MAP-NAME RULE * ')'
82 RULE ::= '(' KEYSEQ MAP-ACTION * ')'
84 KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
87 @c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
90 @c MTEXT in the definition of @c KEYSEQ consists of characters that
91 can be generated by a keyboard. Therefore @c MTEXT usually contains
92 only ASCII characters. However, if the input method is intended to be
93 used, for instance, with a West European keyboard, @c MTEXT may
94 contain Latin-1 characters.
96 @c SYMBOL in the definition of @c KEYSEQ must be the return value of
97 the minput_event_to_key () function.
99 @c INTEGER in the definition of @c KEYSEQ must be a valid character
103 MAP-ACTION ::= ACTION
105 ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK
106 | SHOW | HIDE | PUSHBACK | UNDO | SHIFT | CALL
107 | SET | IF | COND | '(' MACRO-NAME ')'
109 PREDEFINED-SYMBOL ::=
110 '@0' | '@1' | '@2' | '@3' | '@4'
111 | '@5' | '@6' | '@7' | '@8' | '@9'
112 | '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
116 MACRO-LIST ::= '(' 'macro' MACRO * ')'
118 MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
120 MACRO-NAME ::= SYMBOL
122 MACRO-ACTION ::= ACTION
125 MODULE-LIST ::= '(' 'module' MODULE * ')'
127 MODULE ::= '(' MODULE-NAME FUNCTION * ')'
129 MODULE-NAME ::= SYMBOL
134 Each @c MODULE declares the name of external module (i.e. dynamic
135 library) and function names exported by the module. If a @c FUNCTION has
136 name "init", it is called with only the default arguments (see the
137 section about @c CALL) when an input context is created for the input
138 method. If a @c FUNCTION has name "fini", it is called with only the
139 default arguments when an input context is destroyed.
142 STATE-LIST ::= '(' 'state' STATE * ')'
144 STATE ::= '(' STATE-NAME BRANCH * ')'
146 STATE-NAME ::= SYMBOL
148 BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
149 | '(' nil BRANCH-ACTION * ')'
150 | '(' t BRANCH-ACTION * ')'
153 In the first form of @c BRANCH, @c MAP-NAME must be an item that appears
154 in @c MAP. In this case, if a key sequence matching one of @c
155 KEYSEQs of @c MAP-NAME is typed, @c BRANCH-ACTIONs are executed.
157 In the second form of @c BRANCH, @c BRANCH-ACTIONs are executed if a
158 key sequence that doesn't match any of @c Branch's of the current
161 In the third form of @c BRANCH, @c BRANCH-ACTIONs are executed when we
162 shift to the current state. If the current state is the initial
163 state, @c BRANCH-ACTIONs are executed also when an input context of
164 the input method is created.
167 BRANCH-ACTION ::= ACTION
170 An input method has the following two lists of symbols.
175 A marker is a symbol indicating a character position in the preediting
176 text. The @c MARK action assigns a position to a marker. The
177 position of a marker is referred by the @c MOVE and the @c DELETE actions.
181 A variable is a symbol associated with an integer value. The value of
182 a variable is set by the @c SET action, and is referred by the @c SET,
183 the @c INSERT, and the @c IF actions. All variables are implicitly
188 Each @c PREDEFINED-SYMBOL has a special meaning when used as a marker.
191 <li> @c @@0, @c @@1, @c @@2, @c @@3, @c @@4, @c @@5, @c @@6, @c @@7, @c @@8, @c @@9
193 The 0th, 1st, 2nd, ... 9th position respectively.
195 <li> @c @@<, @c @@=, @c @@>
197 The first, the current, and the last position.
201 The previous and the next position.
205 The previous and the next position where a candidate list changes.
208 Some of the @c PREDEFINED-SYMBOL has a special meaning when used as a candidate
209 index in the @c SELECT action.
213 <li> @c @@<, @c @@=, @c @@>
215 The first, the current, and the last candidate of the current candidate group.
219 The previous candidate. If the current candidate is the first one in
220 the current candidate group, then it means the last candidate in the
221 previous candidate group.
225 The next candidate. If the current candidate is the last one in the
226 current candidate group, then it means the first candidate in the next
231 The candidate in the previous and the next candidate group having the same
232 candidate index as the current one.
235 And, this also has a special meaning.
240 Number of handled keys at that moment.
244 The arguments and the behavior of each action are listed below.
247 INSERT ::= '(' 'insert' MTEXT ')'
250 | '(' 'insert' SYMBOL ')'
251 | '(' 'insert' '(' CANDIDATES * ')' ')'
252 | '(' CANDIDATES * ')'
254 CANDIDATES ::= MTEXT | '(' MTEXT * ')'
257 The first and second forms insert @c MTEXT before the current position.
259 The third form inserts the character @c INTEGER before the current
262 The fourth form treats @c SYMBOL as a variable, and inserts its value
263 (if it is a valid character code) before the current position.
265 In the fifth and sixth forms, each @c CANDIDATES represents a
266 candidate group, and each element of @c CANDIDATES represents a
267 candidate, i.e. if @c CANDIDATES is an M-text, the candidates are the
268 characters in the M-text; if @c CANDIDATES is a list of M-texts, the
269 candidates are the M-texts in the list.
271 These forms insert the first candidate before the current position.
272 The inserted string is associated with the list of candidates and
273 the information indicating the currently selected candidate.
275 The marker positions affected by the insertion are automatically relocated.
278 DELETE ::= '(' 'delete' SYMBOL ')'
279 | '(' 'delete' INTEGER ')'
282 The first form treats @c SYMBOL as a marker, and deletes characters
283 between the current position and the marker position.
285 The second form treats @c INTEGER as a character position, and deletes
286 characters between the current position and the character position.
288 The marker positions affected by the deletion are automatically relocated.
291 SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
292 | '(' 'select' INTEGER ')'
295 This action first checks if the character just before the current position
296 belongs to a string that is associated with a candidate list. If it is,
297 the action replaces that string with a candidate specified by the
300 The first form treats @c PREDEFINED-SYMBOL as a candidate index (as
301 described above) that specifies a new candidate in the candidate list.
303 The second form treats @c INTEGER as a candidate index that specifies a
304 new candidate in the candidate list.
310 This actions instructs the input method driver to display a candidate
311 list associated with the string before the current position.
317 This action instructs the input method driver to hide the currently
318 displayed candidate list.
321 MOVE ::= '(' 'move' SYMBOL ')'
322 | '(' 'move' INTEGER ')'
325 The first form treats @c SYMBOL as a marker, and makes the marker
326 position be the new current position.
328 The second form treats @c INTEGER as a character position, and makes
329 that position be the new current position.
332 MARK ::= '(' 'mark' SYMBOL ')'
335 This action treats @c SYMBOL as a marker, and sets its position to the
336 current position. @c SYMBOL must not be a @c PREDEFINED-SYMBOL.
340 PUSHBACK :: = '(' 'pushback' INTEGER ')'
341 | '(' 'pushback' KEYSEQ ')'
344 The first form pushes back the latest @c INTEGER number of key events
345 to the event queue if @c INTEGER is positive, and pushes back all key
346 events if @c INTEGER is zero.
348 The second form pushes back keys in KEYSEQ to the event queue.
351 UNDO :: = '(' 'undo' [ INTEGER | SYMBOL ] ')'
354 If there's no argument, this action cancels the last two key events
355 (i.e. the one that invoked this command, and the previous one).
357 If there's an integer argument NUM, it must be positive or negative
358 (not zero). If positive, the NUMth event to the last one are
359 cancelled. If negative the last (- NUM) events are cancelled.
361 If there's a symbol argument, it must be resolved to an integer number
362 and the number is treated as the actual argument as above.
365 SHIFT :: = '(' 'shift' STATE-NAME ')'
368 This action shifts the current state to @c STATE-NAME. @c
369 STATE-NAME must appear in @c STATE-LIST.
372 CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
374 ARG ::= INTEGER | SYMBOL | MTEXT | PLIST
377 This action calls the function @c FUNCTION of external module @c
378 MODULE-NAME. @c MODULE-NAME and @c FUNCTION must appear in @c
381 The function is called with an argument of the type (#MPlist *). The
382 key of the first element is #Mt and its value is a pointer to an
383 object of the type #MInputContext. The key of the second element is
384 #Msymbol and its value is the current state name. @c ARGs are used as
385 the value of the third and later elements. Their keys are determined
386 automatically; if an @c ARG is an integer, the corresponding key is
387 #Minteger; if an @c ARG is a symbol, the corresponding key is
390 The function must return NULL or a value of the type (#MPlist *) that
391 represents a list of actions to take.
394 SET ::= '(' CMD SYMBOL1 EXPRESSION ')'
396 CMD ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
398 EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERAND EXPRESSION * ')'
400 OPERAND ::= '+' | '-' | '*' | '/' | '|' | '&' | '!' | '=' | '<' | '>'
404 This action treats @c SYMBOL1 and @c SYMBOL2 as variables and sets the
405 value of @c SYMBOL1 as below.
407 If @c CMD is 'set', it sets the value of @c SYMBOL1 to the value of @c
410 If @c CMD is 'add', it increments the value of @c SYMBOL1 by the value
413 If @c CMD is 'sub', it decrements the value of @c SYMBOL1 by the value
416 If @c CMD is 'mul', it multiplies the value of @c SYMBOL1 by the value
419 If @c CMD is 'div', it divides the value of @c SYMBOL1 by the value of
423 IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ')'
425 CONDITION ::= [ '=' | '<' | '>' ] EXPRESSION1 EXPRESSION2
427 ACTION-LIST1 ::= '(' ACTION * ')'
429 ACTION-LIST2 ::= '(' ACTION * ')'
432 This action performs actions in @c ACTION-LIST1 if @c CONDITION is
433 true, and performs @c ACTION-LIST2 (if any) otherwise.
435 @c SYMBOL1 and @c SYMBOL2 are treated as variables.
438 COND ::= '(' 'cond' [ '(' EXPRESSION ACTION * ') ] * ')'
441 This action performs the first actions @c ACTION whose corresponding
442 @c EXPRESSION has nonzero value.
446 @section im-example1 EXAMPLE 1
448 This is a very simple example for inputting Latin characters with
449 diacritical marks (acute and cedilla). For instance, when you type:
451 Comme'die-Franc,aise, chic,,
456 Commédie-Française, chic,
461 \hskip5mm\texttt{\footnotesize Comm\'{e}die-Fran\c{c}aise, chic,}
465 The definition of the input method is very simple as below, and it is
466 quite straight forward to extend it to cover all Latin characters.
470 (title "latin-postfix")
473 ("a'" ?á) ("e'" ?é) ("i'" ?í) ("o'" ?ó) ("u'" ?ú) ("c," ?ç)
474 ("A'" ?Á) ("E'" ?É) ("I'" ?Í) ("O'" ?Ó) ("U'" ?Ú) ("C," ?Ç)
475 ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")
477 ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")
486 \texttt{\footnotesize
487 \hskip2mm(title "latin-postfix")\\
490 \hskip6mm ("a'" ?\'{a}) ("e'" ?\'{e}) ("i'" ?\'{i}) ("o'" ?\'{o})
491 ("u'" ?\'{u}) ("c," ?\c{c})\\
492 \hskip6mm ("A'" ?\'{A}) ("E'" ?\'{E}) ("I'" ?\'{I}) ("O'" ?\'{O})
493 ("U'" ?\'{U}) ("C," ?\c{C})\\
494 \hskip6mm ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")\\
495 \hskip6mm ("c,," "c,")\\
496 \hskip6mm ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")\\
497 \hskip6mm ("C,," "C,")))\\
504 @section im-example2 EXAMPLE 2
506 This example is for inputting Unicode characters by typing C-u
507 (Control-u) followed by four hexadecimal numbers. For instance, when
508 you type ("^u" means Control-u):
510 ^u2190^u2191^u2192^u2193
512 you will get this (Unicode arrow symbols):
517 The definition utilizes @c SET and @c IF commands as below:
524 ("0" ?0) ("1" ?1) ... ("9" ?9) ("a" ?A) ("b" ?B) ... ("f" ?F)))
527 (starter (set code 0) (set count 0) (shift unicode)))
533 (mul code 16) (add code this)
536 ((delete @<) (insert code) (shift init))))))
539 @section im-example3 EXAMPLE 3
541 This example is for inputting Chinese characters by typing PinYin key
544 For instance, when you type:
553 The definition utilizes @c CANDIDATE and @c SELECT commands as below.
554 Note that this is just an example, and it ignores such important key
561 ;; The initial character of Pinyin.
563 ("a") ("b") ... ("h") ("j") ... ("t") ("w") ("x") ("y") ("z"))
565 ;; Big table of Pinyin vs the corresponding Chinese characters.
568 ("bei" ("被北备背悲辈杯倍贝碑" ...))
569 ("hao" ("好号毫豪浩耗皓嚎昊郝" ...))
570 ("jing" ("经京精境警竟静惊景敬" ...))
571 ("ni" ("你呢尼泥逆倪匿拟腻妮" ...))
573 ;; Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.
575 ("1" (select 0)) ("2" (select 1)) ... ("9" (select 8)) ("0" (select 9))))
579 ;; When an initial character of Pinyin is typed, re-handle it in
580 ;; "main" state. Anything else is just produced as is.
581 (starter (show) (pushback 1) (shift main)))
584 ;; When a complete Pinyin sequence is typed, shift to "select" state
585 ;; to allow users to select one from the candidates.
586 (pinyin (shift select))
588 ;; When anything else is typed, produce the current candidate (if
589 ;; any), and re-handle the last input in "init" state.
590 (nil (hide) (shift init)))
593 ;; When a number is typed, select the corresponding canidate,
594 ;; produce it, and shift to "init" state.
595 (choose (hide) (shift init))
597 ;; When anything else is typed, produce the current candidate,
598 ;; and re-handle the last input in "init" state.
599 (nil (hide) (shift init))))
605 \fbox{This example is readable only in the documentation of HTML version.}
612 @section im-seealso SEE ALSO
614 @ref mim-list "Input Methods provided by the m17n database",
615 @ref mdbGeneral "mdbGeneral(5)"
619 Copyright (C) 2003, 2004, 2005
620 National Institute of Advanced Industrial Science and Technology (AIST)
621 Registration Number H15PRO112
623 This file is part of the m17n database; a sub-part of the m17n
626 The m17n library is free software; you can redistribute it and/or
627 modify it under the terms of the GNU Lesser General Public License
628 as published by the Free Software Foundation; either version 2.1 of
629 the License, or (at your option) any later version.
631 The m17n library is distributed in the hope that it will be useful,
632 but WITHOUT ANY WARRANTY; without even the implied warranty of
633 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
634 Lesser General Public License for more details.
636 You should have received a copy of the GNU Lesser General Public
637 License along with the m17n library; if not, write to the Free
638 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
642 /* Local Variables: */