(%.tab): Fix previous change.
[m17n/m17n-db.git] / FORMATS / IM.txt
index 1373ec5..f7398b5 100644 (file)
@@ -24,64 +24,122 @@ into the form of plist in the driver.
 
 @verbatim
 INPUT-METHOD ::=
-    IM-DECLARATION ? DESCRIPTION ? VARIABLE-LIST ? COMMAND-LIST ?
-    TITLE MAP-LIST MACRO-LIST ? MODULE-LIST ? STATE-LIST
+    IM-DECLARATION ? IM-DESCRIPTION ? TITLE ?
+     VARIABLE-LIST ? COMMAND-LIST ?  MODULE-LIST ?
+     MACRO-LIST ? MAP-LIST ? STATE-LIST ?
 
-IM-DECLARATION ::= '(' 'input-method' LANGUAGE NAME [ VERSION ] ')'
-DESCRIPTION ::= '(' 'description' [ MTEXT-OR-GETTEXT | nil] ')'
-VARIABLE-LIST ::= '(' 'variable' VARIABLE-DECLARATION * ')'
-COMMAND-LIST ::= '(' 'command' COMMAND-DECLARATION * ')'
-TITLE ::= '(' 'title' TITLE-TEXT ')'
-
-VARIABLE-DECLARATION ::=
-    '(' VAR-NAME [ MTEXT-OR-GETTEXT | nil ] VALUE VALUE-CANDIDATE * ')'
+IM-DECLARATION ::= '(' 'input-method' LANGUAGE NAME EXTRA-ID ? VERSION ? ')'
+LANGUAGE ::= SYMBOL
+NAME ::= SYMBOL
+EXTRA-ID ::= SYMBOL
+VERSION ::= '(' 'version' VERSION-NUMBER ')'
 
-COMMAND-DECLARATION ::=
-    '(' CMD-NAME [ MTEXT-OR-GETTEXT | nil ] KEYSEQ * ')'
+IM-DESCRIPTION ::= '(' 'description' DESCRIPTION ')'
+DESCRIPTION ::= MTEXT-OR-GETTEXT | 'nil'
+MTEXT-OR-GETTEXT ::=  [ MTEXT | '(' '_' MTEXT ')']
 
-MTEXT-OR-GETTEXT ::=
-    [ MTEXT | '(' '_' MTEXT ')']
+TITLE ::= '(' 'title' TITLE-TEXT ')'
+TITLE-TEXT ::= MTEXT
 
-LANGUAGE ::= SYMBOL
-NAME ::= SYMBOL
-VERSION ::= MTEXT
-IM-DESCRIPTION ::= MTEXT
+VARIABLE-LIST ::= '(' 'variable' VARIABLE-DECLARATION * ')'
+VARIABLE-DECLARATION ::=  '(' VAR-NAME [ DESCRIPTION VALUE VALUE-CANDIDATE * ]')'
 VAR-NAME ::= SYMBOL
-VAR-DESCRIPTION ::= MTEXT
 VALUE ::= MTEXT | SYMBOL | INTEGER
 VALUE-CANDIDATE ::= VALUE | '(' RANGE-FROM RANGE-TO ')'
 RANGE-FROM ::= INTEGER
 RANGE-TO ::= INTEGER
+
+COMMAND-LIST ::= '(' 'command' COMMAND-DECLARATION * ')'
+COMMAND-DECLARATION ::=  '(' CMD-NAME [ DESCRIPTION KEYSEQ * ] ')'
 CMD-NAME ::= SYMBOL
-CMD-DESCRIPTION ::= MTEXT
-TITLE-TEXT ::= MTEXT
+
 @endverbatim
 
+@c IM-DECLARATION specifies the language and name of this input
+method.  
+
+When @c LANGUAGE is @c t, the use of the input method is not limited
+to one language.
+
+When @c NAME is @c nil, the input method is not standalone, but
+is expected to be used in other input methods.  In such cases,
+@c EXTRA-ID is required to identify the input method.
+
 @c VERSION specifies the required minimum version number of the m17n
-library.  The format is is "XX.YY.ZZ" where XX is a major version
+library.  The format is "XX.YY.ZZ" where XX is a major version
 number, YY is a minor version number, and ZZ is a patch level.
 
-@c IM-DECLARATION specifies the language and name of this input
-method.
+@c DESCRIPTION, if not nil, specifies the description text of an input
+method, a variable or a command.  If @c MTEXT-OR-GETTEXT takes the
+second form, the text is translated according to the current locale by
+"gettext" (if the translation is provided).
 
-@c DESCRIPTION specifies the description text of this input method by
-MTEXT-OR-GETTEXT.  It it takes the second form, the text is translated
-according to the current locale by "gettext" (if the translation is
-provided).
+@c TITLE-TEXT is a text displayed on the screen when this input method
+is active.
+
+There is one special input method file "global.mim" that declares
+common variables and commands.  The input method driver always loads
+this file and other input methods can inherit the variables and the
+commands.
 
 @c VARIABLE-DECLARATION declares a variable used in this input method.
 If a variable must be initialized to the default value, or is to be
-customized by a user, it must be declared here.
+customized by a user, it must be declared here.  The declaration can
+be used in two ways.  One is to introduce a new variable.  In that
+case, @c VALUE must not be omitted.  Another is to inherit the variable
+from what declared in "global.mim", and to give the different default
+value and/or to make the variable customizable specially for the
+current input method.  In the latter case, @c VALUE can be omitted.
 
 @c COMMAND-DECLARATION declares a command used in this input method.
 If a command must be bound to the default key sequence, or is to be
-customized by a user, it must be declared here.
+customized by a user, it must be declared here.  Like @c
+VARIABLE-DECLARATION, the declaration can be used in two ways.  One is
+to introduce a new command.  In that case, @c KEYSEQ must not be omitted.
+Another is to inherit the command from what declared in "global.mim",
+and to give the different key binding and/or to make the command
+customizable specially for the current input method.  In the latter
+case, @c KEYSEQ can be omitted.
 
-@c TITLE-TEXT is a text displayed on the screen when this input method
-is active.
 
 @verbatim
-MAP-LIST ::= '(' 'map' MAP * ')'
+MODULE-LIST ::= '(' 'module' MODULE * ')'
+
+MODULE ::= '(' MODULE-NAME FUNCTION * ')'
+
+MODULE-NAME ::= SYMBOL
+
+FUNCTION ::= SYMBOL
+@endverbatim
+
+Each @c MODULE declares the name of an external module (i.e. dynamic
+library) and function names exported by the module.  If a @c FUNCTION has
+name "init", it is called with only the default arguments (see the
+section about @c CALL) when an input context is created for the input
+method.  If a @c FUNCTION has name "fini", it is called with only the
+default arguments when an input context is destroyed.
+
+@verbatim
+MACRO-LIST ::=  MACRO-INCLUSION ? '(' 'macro' MACRO * ')' MACRO-INCLUSION ?
+
+MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
+
+MACRO-NAME ::= SYMBOL
+
+MACRO-ACTION ::= ACTION
+
+TAGS ::= `(` LANGUAGE NAME EXTRA-ID ? `)`
+
+MACRO-INCLUSION ::= '(' 'include' TAGS 'macro' MACRO-NAME ? ')'
+
+@endverbatim
+
+@c MACRO-INCLUSION includes macros from another input method specified
+by @c TAGS.  When @c MACRO-NAME is not given, all macros from the
+input method are included.
+
+@verbatim MAP-LIST ::= MAP-INCLUSION ? '(' 'map' MAP * ')'
+MAP-INCLUSION ?
 
 MAP ::= '(' MAP-NAME RULE * ')'
 
@@ -90,8 +148,14 @@ MAP-NAME ::= SYMBOL
 RULE ::= '(' KEYSEQ MAP-ACTION * ')'
 
 KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
+
+MAP-INCLUSION ::= '(' 'include' TAGS 'map' MAP-NAME ? ')'
+
 @endverbatim
 
+When an input method is never standalone and always included in
+another method, @c MAP-LIST can be omitted.
+
 @c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
 nil.
 
@@ -108,7 +172,7 @@ the return key, the backspace key, and the 0 key on the keypad are
 represented as @c (Return) , @c (BackSpace) , and @c (KP_0)
 respectively.  If the shift, control, meta, alt, super, and hyper
 modifiers are used, they are represented by the S- , C- , M- , A- , s-
-, and H- prefixes respectively in this oreder.  Thus, "return with
+, and H- prefixes respectively in this order.  Thus, "return with
 shift with meta with hyper" is @c (S-M-H-Return) .  Note that "a with
 shift" .. "z with shift" are represented simply as A .. Z . Thus "a
 with shift with meta with hyper" is @c (M-H-A) .
@@ -116,11 +180,17 @@ with shift with meta with hyper" is @c (M-H-A) .
 @c INTEGER in the definition of @c KEYSEQ must be a valid character
 code.
 
+@c MAP-INCLUSION includes maps from another input method specified by
+@c TAGS. When @c MAP-NAME is not given, all maps from the input method
+are included.
+
+
 @verbatim
 MAP-ACTION ::= ACTION
 
 ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK
-           | SHOW | HIDE | PUSHBACK | POP | UNDO | UNHANDLE | SHIFT | CALL
+           | SHOW | HIDE | PUSHBACK | POP | UNDO 
+          | COMMIT | UNHANDLE | SHIFT | CALL
           | SET | IF | COND | '(' MACRO-NAME ')'
 
 PREDEFINED-SYMBOL ::=
@@ -128,36 +198,11 @@ PREDEFINED-SYMBOL ::=
     | '@5' | '@6' | '@7' | '@8' | '@9'
     | '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
     | '@@'
-    | '@-N' | '@+N'
+    | '@-0' | '@-N' | '@+N'
 @endverbatim
-@verbatim
-MACRO-LIST ::= '(' 'macro' MACRO * ')'
 
-MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
-
-MACRO-NAME ::= SYMBOL
-
-MACRO-ACTION ::= ACTION
-@endverbatim
 @verbatim
-MODULE-LIST ::= '(' 'module' MODULE * ')'
-
-MODULE ::= '(' MODULE-NAME FUNCTION * ')'
-
-MODULE-NAME ::= SYMBOL
-
-FUNCTION ::= SYMBOL
-@endverbatim
-
-Each @c MODULE declares the name of external module (i.e. dynamic
-library) and function names exported by the module.  If a @c FUNCTION has
-name "init", it is called with only the default arguments (see the
-section about @c CALL) when an input context is created for the input
-method.  If a @c FUNCTION has name "fini", it is called with only the
-default arguments when an input context is destroyed.
-
-@verbatim
-STATE-LIST ::= '(' 'state' STATE * ')'
+STATE-LIST ::= STATE-INCUSION ? '(' 'state' STATE * ')'  STATE-INCUSION ?
 
 STATE ::= '(' STATE-NAME [ STATE-TITLE-TEXT ] BRANCH * ')'
 
@@ -166,10 +211,20 @@ STATE-NAME ::= SYMBOL
 STATE-TITLE-TEXT ::= MTEXT
 
 BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
-          | '(' nil BRANCH-ACTION * ')'
-          | '(' t BRANCH-ACTION * ')'
+          | '(' 'nil' BRANCH-ACTION * ')'
+          | '(' 't' BRANCH-ACTION * ')'
+
+STATE-INCLUSION ::= '(' 'include' TAGS 'state' STATE-NAME ? ')'
+
 @endverbatim
 
+When an input system is never standalone and always included in
+another system, @c STATE-LIST can be omitted.
+
+@c STATE-INCLUSION includes states from another input method specified
+by @c TAGS. When @c STATE-NAME is not given, all states from the input
+method are included.
+
 The optional @c STATE-TITLE-TEXT specifies a title text displayed on
 the screen when the input method is in this state.  If @c
 STATE-TITLE-TEXT is omitted, @c TITLE-TEXT is used.
@@ -182,6 +237,10 @@ In the second form of @c BRANCH, @c BRANCH-ACTIONs are executed if a
 key sequence that doesn't match any of @c Branch's of the current
 state is typed.
 
+If there is no @c BRANCH beginning with @c nil and the typed key
+sequence does not match any of the current @c BRANCHs, the input
+method transits to the initial state.
+
 In the third form of @c BRANCH, @c BRANCH-ACTIONs are executed when
 shifted to the current state.  If the current state is the initial
 state, @c BRANCH-ACTIONs are executed also when an input context of
@@ -202,10 +261,14 @@ position of a marker is referred by the @c MOVE and the @c DELETE actions.
 
 <li> variable list
 
-A variable is a symbol associated with an integer value.  The value of
-a variable is set by the @c SET action, and is referred by the @c SET,
-the @c INSERT, and the @c IF actions.  All variables are implicitly
-initialized to zero.
+A variable is a symbol associated with an integer, a symbol, or an
+M-text value.  The integer value of a variable can be set and referred
+by the @c SET action.  It can be referred by the @c SET, the @c
+INSERT, the @c SELECT, the @c UNDO, the @c IF, the @c COND actions.
+The M-text value of a variable can be referred by the @c INSERT
+action.  The symbol value of a variable can not be referred directly,
+is used the library implicitly (e.g. candidates-charset).  All
+variables are implicitly initialized to the integer value zero.
 
 </ul>
 
@@ -268,19 +331,25 @@ Number of handled keys at that moment.
 These are for supporting surround text handling.
 
 <ul>
+<li> @c @@-0
+
+-1 if surrounding text is supported, -2 if not.
+
 <li> @c @@-N
 
-Here, @c N is a positive integer.  The value is a character at Nth
-previous position from the current caret of the surrounding text.
-When this is used as the argument of @c delete action, it specifies
-how many preceding characters in the surround text to delete.
+Here, @c N is a positive integer.  The value is the Nth previous
+character in the preedit buffer.  If there are only M (M<N) previous
+characters in it, the value is the (N-M)th previous character from the
+inputting spot.  When this is used as the argument of @c delete
+action, it specifies the number of characters to be deleted.
 
 <li> @c @@+N
 
-Here, @c N is a positive integer.  The value is a character at Nth
-next position from the current caret of the surrounding text.
-When this is used as the argument of @c delete action, it specifies
-how many following characters in the surround text to delete.
+Here, @c N is a positive integer.  The value is the Nth following
+character in the preedit buffer.  If there are only M (M<N) following
+characters in it, the value is the (N-M)th following character from
+the inputting spot.  When this is used as the argument of @c delete
+action, it specifies the number of characters to be deleted.
 </ul>
 
 The arguments and the behavior of each action are listed below.
@@ -289,6 +358,7 @@ The arguments and the behavior of each action are listed below.
 INSERT ::= '(' 'insert' MTEXT ')'
            | MTEXT
           | INTEGER
+          | SYMBOL
            | '(' 'insert' SYMBOL ')'
            | '(' 'insert' '(' CANDIDATES * ')' ')'
            | '(' CANDIDATES * ')' 
@@ -301,10 +371,11 @@ The first and second forms insert @c MTEXT before the current position.
 The third form inserts the character @c INTEGER before the current
 position.
 
-The fourth form treats @c SYMBOL as a variable, and inserts its value
-(if it is a valid character code) before the current position.
+The fourth and fith form treats @c SYMBOL as a variable, and inserts
+its value (if it is a valid character code) before the current
+position.
 
-In the fifth and sixth forms, each @c CANDIDATES represents a
+In the sixth and seventh forms, each @c CANDIDATES represents a
 candidate group, and each element of @c CANDIDATES represents a
 candidate, i.e. if @c CANDIDATES is an M-text, the candidates are the
 characters in the M-text; if @c CANDIDATES is a list of M-texts, the
@@ -332,6 +403,7 @@ The marker positions affected by the deletion are automatically relocated.
 @verbatim
 SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
            | '(' 'select' INTEGER ')'
+          | '(' 'select' SYMBOL ')'
 @endverbatim
 
 This action first checks if the character just before the current position
@@ -345,9 +417,10 @@ described above) that specifies a new candidate in the candidate list.
 The second form treats @c INTEGER as a candidate index that specifies a
 new candidate in the candidate list.
 
-@verbatim
-SHOW ::= '(show)'
-@endverbatim
+In the third form, @c SYMBOL must have a integer value, and it is treated 
+as a candidate index.
+
+@verbatim SHOW ::= '(show)' @endverbatim
 
 This actions instructs the input method driver to display a candidate
 list associated with the string before the current position.
@@ -404,24 +477,31 @@ If there's no argument, this action cancels the last two key events
 
 If there's an integer argument NUM, it must be positive or negative
 (not zero).  If positive, from the NUMth to the last events are
-canceled.  If negative the last (- NUM) events are canceled.
+canceled.  If negative, the last (- NUM) events are canceled.
 
 If there's a symbol argument, it must be resolved to an integer number
 and the number is treated as the actual argument as above.
 
 @verbatim
+COMMIT :: = '(commit)'
+@endverbatim
+
+This action commits the current preedit.
+
+@verbatim
 UNHANDLE :: = '(unhandle)'
 @endverbatim
 
-This action commit the current preedit and return the last key as
+This action commits the current preedit and returns the last key as
 unhandled.
 
 @verbatim
 SHIFT :: = '(' 'shift' STATE-NAME ')'
 @endverbatim
 
-This action shifts the current state to @c STATE-NAME.  @c
-STATE-NAME must appear in @c STATE-LIST.
+If @c STATE-NAME is @c t, this action shifts the current state to the
+previous one, otherwise it shifts to @c STATE-NAME.  In the latter
+case, @c STATE-NAME must appear in @c STATE-LIST.
 
 @verbatim
 CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
@@ -450,9 +530,9 @@ SET ::= '(' CMD SYMBOL1 EXPRESSION ')'
 
 CMD ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
 
-EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERAND EXPRESSION * ')'
+EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERATOR EXPRESSION * ')'
 
-OPERAND ::= '+' | '-' | '*' | '/' | '|' | '&' | '!'
+OPERATOR ::= '+' | '-' | '*' | '/' | '|' | '&' | '!'
             | '=' | '<' | '>' | '<=' | '>='
 
 @endverbatim
@@ -476,7 +556,7 @@ If @c CMD is 'div', it divides the value of @c SYMBOL1 by the value of
 @c EXPRESSION.
 
 @verbatim
-IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ')'
+IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ? ')'
 
 CONDITION ::= [ '=' | '<' | '>' | '<=' | '>=' ] EXPRESSION1 EXPRESSION2
 
@@ -488,8 +568,6 @@ ACTION-LIST2 ::= '(' ACTION * ')'
 This action performs actions in @c ACTION-LIST1 if @c CONDITION is
 true, and performs @c ACTION-LIST2 (if any) otherwise.
 
-@c SYMBOL1 and @c SYMBOL2 are treated as variables.
-
 @verbatim
 COND ::= '(' 'cond' [ '(' EXPRESSION ACTION * ') ] * ')'
 @endverbatim
@@ -566,9 +644,16 @@ you type ("^u" means Control-u):
     ^u2190^u2191^u2192^u2193
 @endverbatim
 you will get this (Unicode arrow symbols):
+@if FOR-LATEX
+@verbatim
+    $\leftarrow \uparrow \rightarrow \downarrow
+@endverbatim
+@endif
+@if FOR-HTML
 @verbatim
     ←↑→↓
 @endverbatim
+@endif
 
 The definition utilizes @c SET and @c IF commands as below:
 @verbatim