-/* Copyright (C) 2003, 2004, 2005
+/* Copyright (C) 2003, 2004, 2005, 2009
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H15PRO112
See the end for copying conditions. */
@section im-format SYNTAX and SEMANTICS
-The following data format defines an input method. The driver loads a
-definition from a file, a stream, etc. The definition is converted
-into the form of plist in the driver.
+The following defines a schema for an input method, written in RelaxNG.
+(This schema file can be found at m17n-db-xml/MIM/mim.rng.)
+The driver loads a definition from a file, a stream, etc. The definition
+is converted into the form of plist in the driver.
@verbatim
-INPUT-METHOD ::=
- IM-DECLARATION ? IM-DESCRIPTION ? TITLE ?
- VARIABLE-LIST ? COMMAND-LIST ? MODULE-LIST ?
- MACRO-LIST ? MAP-LIST ? STATE-LIST ?
-IM-DECLARATION ::= '(' 'input-method' LANGUAGE NAME EXTRA-ID ? VERSION ? ')'
-LANGUAGE ::= SYMBOL
-NAME ::= SYMBOL
-EXTRA-ID ::= SYMBOL
-VERSION ::= '(' 'version' VERSION-NUMBER ')'
+<?xml version="1.0" encoding="utf-8"?>
+
+<grammar
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
+ xmlns:xi="http://www.w3.org/1999/XML/xinclude"
+ xmlns="http://relaxng.org/ns/structure/1.0"
+ ns="http://www.m17n.org/MIM">
+
+<start>
+ <element name="input-method">
+ <ref name="im-declaration"/>
+
+ <optional>
+ <element name="description">
+ <choice>
+ <text/>
+ <element name="get-text"><text/> </element>
+ </choice>
+ </element>
+ </optional>
+
+ <optional><element name="title"><data type="string"/></element></optional>
+ <optional><ref name="variable-list"/></optional>
+ <optional><ref name="command-list"/></optional>
+ <optional><ref name="module-list"/></optional>
+ <optional><ref name="macro-list"/></optional>
+ <optional><ref name="map-list"/></optional>
+ <optional><ref name="state-list"/></optional>
+ </element>
+</start>
-IM-DESCRIPTION ::= '(' 'description' DESCRIPTION ')'
-DESCRIPTION ::= MTEXT-OR-GETTEXT | 'nil'
-MTEXT-OR-GETTEXT ::= [ MTEXT | '(' '_' MTEXT ')']
+@endverbatim
-TITLE ::= '(' 'title' TITLE-TEXT ')'
-TITLE-TEXT ::= MTEXT
+The top-level node of an input method has a <input-method> tag.
+
+The element <description> can appear in <input-method>, <variable> or
+<command>, and specifies the description text of its parent. The
+content of the element <get-text> is translated according to the
+current locale by "gettext" (if the translation is provided).
+
+The element <title> contains a string that is displayed on the screen
+when this input method is active.
+
+#if EXAMPLE_CODE
+<input-method xmlns="http://www.m17n.org/MIM">
+ <tags>
+ <language>bo</language>
+ <name>ewts</name>
+ </tags>
+ <description>Tibetan input method based on EWTS.
+This implementation is based on THDL Extended Wylie Transliteration Scheme
+Version 2.0 <http://www.thdl.org/collections/langling/ewts/ewts.php>.</description>
+ <title>ཀ</title>
+ : :
+#endif
+
+<variable-list> declares variables used in this input method.
+<command-list> declares commands used in this input method.
+<module-list> declares external modules used in this input method.
+<macro-list> declares macros used in this input method. <map-list>
+declares maps used in this input method. When an input method is
+never standalone and always included in another method, the element
+<map-list> can be omitted. <state-list> declares states used in this
+input method. When an input system is never standalone and always included in
+another system, the element <state-list> can be omitted.
+
+@subsection im-declarations Input Method Declaration
-VARIABLE-LIST ::= '(' 'variable' VARIABLE-DECLARATION * ')'
-VARIABLE-DECLARATION ::= '(' VAR-NAME [ DESCRIPTION VALUE VALUE-CANDIDATE * ]')'
-VAR-NAME ::= SYMBOL
-VALUE ::= MTEXT | SYMBOL | INTEGER
-VALUE-CANDIDATE ::= VALUE | '(' RANGE-FROM RANGE-TO ')'
-RANGE-FROM ::= INTEGER
-RANGE-TO ::= INTEGER
+@verbatim
-COMMAND-LIST ::= '(' 'command' COMMAND-DECLARATION * ')'
-COMMAND-DECLARATION ::= '(' CMD-NAME [ DESCRIPTION KEYSEQ * ] ')'
-CMD-NAME ::= SYMBOL
+<define name="im-declaration">
+
+ <element name="tags">
+ <element name="language">
+ <choice>
+ <value>t</value>
+ <data type="string"><param name="pattern">[a-z]{2,3}</param>
+ </data>
+ </choice>
+ </element>
+ <choice>
+ <group>
+ <element name="name"><value>nil</value></element>
+ <element name="extra-id"><data type="ID"/></element>
+ </group>
+ <group>
+ <element name="name">
+ <choice>
+ <data type="string"><param name="pattern">[^n][^i][^l]</param></data>
+ <data type="string"><param name="pattern">.{1,2}</param></data>
+ <data type="string"><param name="pattern">....+</param></data>
+ </choice>
+ </element>
+ <optional>
+ <element name="extra-id"><data type="ID"/></element>
+ </optional>
+ </group>
+ </choice>
+ </element>
+
+ <optional>
+ <element name="m17n-version">
+ <data type="string"><param name="pattern">[0-9]+\.[0-9]+\.[0-9]+</param></data>
+ </element>
+ </optional>
+</define>
@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.
+The element <tags> specifies for which language the input method is,
+and the name of the input method. There is one special input method
+file "global.mimx" that declares common variables and commands. The
+input method driver always loads this file and other input methods can
+inherit its variables and commands.
+
+When the element <language> has "t" as its content, the use of the
+input method is not limited to one language. When the content is
+other than "t", it must be a valid code in ISO639-1, two-character
+code or ISO639-2, three charcter code for the names of languages.
+
+When the element <name> has "nil" as its content, the input method is
+not standalone, but is expected to be used in other input methods. In
+such cases, the element <extra-id> is required to identify the input
+method. When the element <name> has content other than "nil", the
+element <extra-id> is optional.
+
+#if EXAMPLE_CODE
+ <tags>
+ <language>bo</language>
+ <name>ewts</name>
+ </tags>
+#endif
+
+#if EXAMPLE_CODE
+ <tags>
+ <language>t</language>
+ <name>nil</name>
+ <extra-id>zh-util</extra-id>
+ </tags>
+#endif
+
+The optional element <m17n-version> specifies the required minimum
+version number of the m17n library. The format is "X.Y.Z" where X is
+a major version number, Y is a minor version number, and Z is a patch
+level.
+
+@subsection im-setups Input Method Setups
-@c VERSION specifies the required minimum version number of the m17n
-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 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).
+@verbatim
-@c TITLE-TEXT is a text displayed on the screen when this input method
-is active.
+<define name="variable-list">
+ <element name="variable-list">
+ <zeroOrMore>
+ <element name="variable">
+ <attribute name="id"/>
+ <optional>
+ <element name="description">
+ <choice>
+ <text/>
+ <element name="get-text"><text/></element>
+ </choice>
+ </element>
+ </optional>
+ <optional>
+ <element name="value">
+ <choice>
+ <group>
+ <attribute name="type"><value>string</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>symbol</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>integer</value></attribute>
+ <data type="integer"/>
+ </group>
+ </choice>
+ </element>
+ </optional>
+
+ <optional>
+ <element name="variable-value-candidate">
+ <oneOrMore>
+ <choice>
+ <element name="c-value">
+ <choice>
+ <group>
+ <attribute name="type"><value>string</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>symbol</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>integer</value></attribute>
+ <data type="integer"/>
+ </group>
+ </choice>
+ </element>
+ <element name="c-range">
+ <attribute name="from"><data type="integer"/></attribute>
+ <attribute name="to"><data type="integer"/></attribute>
+ </element>
+ </choice></oneOrMore></element>
+ </optional>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
-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.
+@endverbatim
-@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
+<variable-list> declares variables 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. 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. 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
+case, the <value> element in <variable> 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 KEYSEQ can be omitted.
-
+case, <value> can be omitted.
+
+Each <variable> declares one variable, and a variable is referred with
+the attribute "id". <value> of a <variable> can be an integer, a
+symbol, or an M-text value. All variables are implicitly initialized
+to the integer value zero.
+
+The M-text (string) <value> can be referred by the <insert> action.
+The symbol <value> can not be referred directly, but is used the
+library implicitly (e.g. candidates-charset). The integer <value> can
+be set, modified and referred by the <set>, <add>, <sub>, <mul>, and
+<div> action. It can be referred by the the <insert>, <select>,
+<undo>, <if>, and <cond> actions.
+
+<variable-value-candidate> lists the possible values of the variable.
+<c-value> specifies one of the possible value of the variable. It can
+be a M-text (string), a symbol or an integer.
+
+<c-range> specifies a range of integers that the variable can have as
+its value. It can be used mixed with <c-value>. The attribute "from"
+is the minimum integer value that a variable can take, and the
+attribute "to" is the maximum.
+
+#if EXAMPLE_CODE
+ <variable-list>
+ <variable id="precomposed">
+ <description>
+ <get-text>Flag to tell whether or not to generate precomposed characters.
+ If 1, generate precomposed characters if available (e.g. "ྲྀ"(U+0F76).
+ If 0, generate only decomposed characters (e.g. "ྲྀ" (U+0FB2 U+0F80).</get-text>
+ </description>
+ <value type="integer">0</value>
+ <variable-value-candidate>
+ <c-value type="integer">0</c-value>
+ <c-value type="integer">1</c-value>
+ </variable-value-candidate>
+ </variable>
+ </variable-list>
+#endif
+
+This code declares one variable "precomposed" whose value can be 0 or
+1 and is initially set to 0.
@verbatim
-MODULE-LIST ::= '(' 'module' MODULE * ')'
-MODULE ::= '(' MODULE-NAME FUNCTION * ')'
+<define name="predefined-variable">
+ <attribute name="type"><value>predefined</value></attribute>
+ <attribute name="id">
+ <choice>
+ <value>handled-keys</value>
+ <value>predefined-surround-text-flag
+ <data type="string"><param name="pattern">@.+</param></data>
+ </choice>
+ </attribute>
+</define>
-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.
+Predefined-variables are variables whose "type" attribute has the
+value "predefiend". When "id" sttribute has the value "handled-keys",
+the value of the variable is the number of handled keys at that
+moment. If the "id" attrubyte has the value
+"predefined-surround-text-flag", the value of the variable is -1
+if surrounding text is supported, and -2 if not.
+
+#if EXAMPLE_CODE
+<variable-reference id="handled-keys" type="predefined"/>
+#endif
+
+This code referes to a predefined varialbe "handled-keys".
@verbatim
-MACRO-LIST ::= MACRO-INCLUSION ? '(' 'macro' MACRO * ')' MACRO-INCLUSION ?
-MACRO ::= '(' MACRO-NAME MACRO-ACTION * ')'
+<define name="command-list">
+ <element name="command-list">
+ <zeroOrMore>
+ <element name="command">
+ <attribute name="id">
+ <data type="ID"><param name="pattern">command-.*</param></data></attribute>
+ <optional>
+ <element name="description">
+ <choice><text/><element name="get-text"><text/></element></choice>
+ </element>
+ </optional>
+ <zeroOrMore><ref name="keyseq"/></zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
-MACRO-NAME ::= SYMBOL
+@endverbatim
-MACRO-ACTION ::= ACTION
+<command-list> declares a command used in the 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. Like <variable-list>,
+the declaration can be used in two ways. One is to introduce a new
+command. In that case, the <keyseq> element must appear in <command>.
+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, <keyseq> can be omitted.
+
+Each <command> declares one command and a command <command> is
+referred with the attribute "id".
+
+#if EXAMPLE_CODE
+ <command-list>
+ <command id="command-commit">
+ <description>
+ <get-text>Commit
+ Commit the preedit text</get-text>
+ </description>
+ <keyseq><key-event>Return</key-event></keyseq>
+ <keyseq><key-event>Linefeed</key-event></keyseq>
+ </command>
+ </command-list>
+#endif
-TAGS ::= `(` LANGUAGE NAME EXTRA-ID ? `)`
+@verbatim
-MACRO-INCLUSION ::= '(' 'include' TAGS 'macro' MACRO-NAME ? ')'
+<define name="module-list">
+ <element name="module-list">
+ <zeroOrMore>
+ <element name="module">
+ <attribute name="id">
+ <data type="ID"><param name="pattern">module-.*</param></data>
+ </attribute>
+ <zeroOrMore>
+ <element name="function">
+ <attribute name="id">
+ <data type="ID">
+ <param name="pattern">function-.*</param></data>
+ </attribute>
+ </element>
+ </zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
@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.
+Each <module> element declares an external module (i.e. dynamic
+library). The value of "id" attribute gives the name of the module
+
+<function> elements specify function names exported by the module. If
+the "id" attribute has the value "function-init", it is called with
+only the default arguments (see <call>) when an input context is
+created for the input method. If the "id" attribute has the value
+"function-fini", it is called with only the default arguments when the
+input context is destroyed.
+
+#if EXAMPLE_CODE
+ <module-list>
+ <module id="module-libmimx-anthy">
+ <function id="function-convert"/>
+ <function id="function-resize"/>
+ <function id="function-change"/>
+ <function id="function-commit"/>
+ <function id="function-init"/>
+ <function id="function-fini"/>
+ </module>
+ </module-list>
+#endif
+
+This code declares a module "module-libmimx-anthy" who export six functions.
+
+@verbatim
+
+<define name="macro-list">
+ <element name="macro-list" ns="http://www.m17n.org/MIM">
+ <zeroOrMore>
+ <element name="macro">
+ <attribute name="id">
+ <data type="ID"><param name="pattern">macro-.*</param></data>
+ </attribute>
+ <zeroOrMore><ref name="action"/></zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
-@verbatim MAP-LIST ::= MAP-INCLUSION ? '(' 'map' MAP * ')'
-MAP-INCLUSION ?
+@endverbatim
-MAP ::= '(' MAP-NAME RULE * ')'
+The elemnt <macro> bundles and names a set of <action>s. The
+attribute "id" gives the name of a <macro>, and a macro is referred
+with this attribute.
-MAP-NAME ::= SYMBOL
+#if EXAMPLE_CODE
+ <macro-list>
+ <macro id="macro-forward">
+ <set id="cc3">
+ <predefined-nth-previous-or-following-character position="+3"/>
+ </set>
+ <conditional>
+ : : ;; more <action>s
+ </macro>
+ </macro-list>
+#endif
-RULE ::= '(' KEYSEQ MAP-ACTION * ')'
+This code declares one macro "macro-forward".
-KEYSEQ ::= MTEXT | '(' [ SYMBOL | INTEGER ] * ')'
+@verbatim
-MAP-INCLUSION ::= '(' 'include' TAGS 'map' MAP-NAME ? ')'
+<define name="marker">
+ <choice>
+ <ref name="predefined-marker"/>
+ <ref name="user-defined-marker"/>
+ </choice>
+</define>
@endverbatim
-When an input method is never standalone and always included in
-another method, @c MAP-LIST can be omitted.
+A marker is a symbol indicating a character position in the preediting
+text. The element <mark-current-position> assigns a position to
+a marker. The position of a marker is referred by the elements
+<move-to-marker> and <delete-to-marker>.
-@c SYMBOL in the definitions of @c MAP-NAME must not be @c t nor @c
-nil.
+@verbatim
-@c MTEXT in the definition of @c KEYSEQ consists of characters that
-can be generated by a keyboard. Therefore @c MTEXT usually contains
-only ASCII characters. However, if the input method is intended to be
-used, for instance, with a West European keyboard, @c MTEXT may
-contain Latin-1 characters.
+<define name="predefined-marker">
+ <attribute name="position">
+ <choice>
+ <data type="string"><param name="pattern">@[0-9]</param>
+ </data>
+ <value>@first</value>
+ <value>@current</value>
+ <value>@last</value>
+ <value>@previous</value>
+ <value>@next</value>
+ <value>@previous_candidate_list
+ <value>@next_candidate_list
+ </choice>
+ </attribute>
+</define>
-@c SYMBOL in the definition of @c KEYSEQ must be the return value of
-the minput_event_to_key () function. Under the X window system, you
-can quickly check the value using the @c xev command. For example,
-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 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) .
+@endverbatim
-@c INTEGER in the definition of @c KEYSEQ must be a valid character
-code.
+Predefined markers start with @@. @@0, @@1, ... , @@9 mark the 0th, 1st,
+2nd,... 9th position respetively. @@previous_candidate_list mark the
+previous position where a candidate list changes.
+@@next_candidate_list mark the next position where a candidate list
+changes.
-@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.
+#if EXAMPLE_CODE
+ <delete-to-marker position="@first"/>
+#endif
+This code deletes character between the first position and the current
+position in the buffer.
@verbatim
-MAP-ACTION ::= ACTION
-ACTION ::= INSERT | DELETE | SELECT | MOVE | MARK
- | SHOW | HIDE | PUSHBACK | POP | UNDO
- | COMMIT | UNHANDLE | SHIFT | CALL
- | SET | IF | COND | '(' MACRO-NAME ')'
+<define name="user-defined-marker">
+ <attribute name="markerID">
+ <data type="string"><param name="pattern">[^@].*</param></data>
+ </attribute>
+</define>
-PREDEFINED-SYMBOL ::=
- '@0' | '@1' | '@2' | '@3' | '@4'
- | '@5' | '@6' | '@7' | '@8' | '@9'
- | '@<' | '@=' | '@>' | '@-' | '@+' | '@[' | '@]'
- | '@@'
- | '@-0' | '@-N' | '@+N'
@endverbatim
+User-defined markers may not start with @@.
+
+#if EXAMPLE_CODE
+ <move-to-marker position="T"/>
+#endif
+
+This code moves the marker to the usr defined position T.
+
@verbatim
-STATE-LIST ::= STATE-INCUSION ? '(' 'state' STATE * ')' STATE-INCUSION ?
-STATE ::= '(' STATE-NAME [ STATE-TITLE-TEXT ] BRANCH * ')'
+<define name="predefined-nth-previous-or-following-character">
+ <element name="predefined-nth-previous-or-following-character">
+ <attribute name="position">
+ <choice>
+ <data type="negativeInteger"/>
+ <data type="positiveInteger"/>
+ </choice>
+ </attribute>
+ </element>
+</define>
+
+@endverbatim
+
+The element <predefined-nth-previous-or-following-character> specifies
+a character inside or outside of the preedit buffer.
-STATE-NAME ::= SYMBOL
+When the value of the attribute "position" is a negative integer -N,
+the element <predefined-nth-previous-or-following-character> means 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.
-STATE-TITLE-TEXT ::= MTEXT
+When the value of the attribute "position" is a positive integer N,
+the element <predefined-nth-previous-or-following-character> means 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.
-BRANCH ::= '(' MAP-NAME BRANCH-ACTION * ')'
- | '(' 'nil' BRANCH-ACTION * ')'
- | '(' 't' BRANCH-ACTION * ')'
+#if EXAMPLE_CODE
+<predefined-nth-previous-or-following-character position="-1"/>
+#endif
-STATE-INCLUSION ::= '(' 'include' TAGS 'state' STATE-NAME ? ')'
+This code refers to the previous character.
+
+@verbatim
+<define name="predefined-selector">
+ <choice>
+ <data type="string"><param name="pattern">@[0-9]</param></data>
+ <value>@first</value>
+ <value>@current</value>
+ <value>@last</value>
+ <value>@previous</value>
+ <value>@next</value>
+ <value>@previous_candidate_list</value>
+ <value>@next_candidate_list</value>
+ </choice>
+</define>
@endverbatim
-When an input system is never standalone and always included in
-another system, @c STATE-LIST can be omitted.
+Predefined-selectors specify positions in a candidate list. They are
+used in the element <select>.
+
+@@0, @@1, ... , @@9 specify the 0th, 1st, ... 9th position
+respetively. @@previous means the previous position, and if the
+current candidate is the first one in the current candidate group,
+this value means the last candidate in the previous candidate
+group. @@next means the next position, and if the current candidate is
+the last one in the current candidate group, this value means the
+first candidate in the next candidate group.
+@@previous_candidate_list specifies the candidate in the previous
+candidate group having the same candidate index as the current one,
+and @@next_candidate_list specifies the candidate in the next
+candidate group having the same candidate index as the current one.
-@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.
+#if EXAMPLE_CODE
+<select selector="@previous"/>
+#endif
-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.
+This code selects the previous candidate.
-In the first form of @c BRANCH, @c MAP-NAME must be an item that
-appears in @c MAP. In this case, if a key sequence matching one of @c
-KEYSEQs of @c MAP-NAME is typed, @c BRANCH-ACTIONs are executed.
+@subsection immap Input Method Maps and Rules
-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.
+@verbatim
+<define name="map-list">
+ <element name="map-list">
+ <zeroOrMore>
+ <element name="map">
+ <attribute name="id">
+ <data type="ID"><param name="pattern">map-.*</param></data>
+ </attribute>
+ <zeroOrMore>
+ <element name="rule">
+ <choice>
+ <ref name="keyseq"/>
+ <ref name="command-reference"/>
+ </choice>
+ <zeroOrMore><ref name="action"/></zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
-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.
+@endverbatim
-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
-the input method is created.
+The element <map> bundles and names a set of groups similar <rule>s,
+so that <state> transitions can be clearly defined. The attribute
+"id" gives the name of a <map>.
+
+The element <rule> defines the mapping of an input key sequence
+<keyseq> (or <command>) and <action>s the input
+method driver should take. When the <action> is to
+<insert> an appropriate character, for example, the <rule>
+defines the mapping between the input key on the keyboad and the
+character to appear on the screen.
+
+#if EXAMPLE_CODE
+ <map-list>
+ <map id="map-consonant">
+ <rule><keyseq keys="k"/><insert string="ཀ"/></rule>
+ <rule><keyseq keys="kh"/><insert string="ཁ"/></rule>
+ : :
+ <rule><keyseq keys="a"/><insert string="ཨ"/></rule>
+ </map>
+ <map id="map-standard-stack">
+ : :
+ </map>
+ : :
+ </map-list>
+#endif
@verbatim
-BRANCH-ACTION ::= ACTION
+
+<define name="keyseq">
+ <element name="keyseq">
+ <choice>
+ <attribute name="keys"><data type="string"/></attribute>
+ <oneOrMore>
+ <choice>
+ <element name="key-event"><data type="string"/></element>
+ <element name="character-code">
+ <choice>
+ <data type="nonNegativeInteger"><param name="pattern">[0-9]{1,7}</param></data>
+ <data type="string"><param name="pattern">[0#]x[0-9A-F]{1,6}</param></data>
+ <data type="string"><param name="pattern">\?.</param></data>
+ </choice>
+ </element>
+ </choice>
+ </oneOrMore>
+ </choice>
+ </element>
+</define>
+
@endverbatim
-An input method has the following two lists of symbols.
+The value of the attribute "keys" of <keyseq> element consists of
+characters that can be generated by a keyboard. Therefore it usually
+contains only ASCII characters. However, if the input method is
+intended to be used, for instance, with a West European keyboard, the
+value may contain Latin-1 characters.
+
+The content of the element <key-event> must be the return value of the
+minput_event_to_key () function. Under the X window system, you can
+quickly check the value using the xev command. For example, the
+return key, the backspace key, and the 0 key on the keypad are
+represented as Return, BackSpace, 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 order. Thus, "return with shift with meta with
+hyper" is 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 M-H-A.
+
+The content of the element <character-code> must be a valid character code.
+
+#if EXAMPLE_CODE
+<keyseq>
+ <character-code>0x6F</character-code>
+ <key-event>A-z</key-event>
+</keyseq>
+
+<keyseq keys="k"/>
+#endif
+
+These are both valid key sequences.
-<ul>
-<li> marker list
+@verbatim
-A marker is a symbol indicating a character position in the preediting
-text. The @c MARK action assigns a position to a marker. The
-position of a marker is referred by the @c MOVE and the @c DELETE actions.
+<define name="command-reference">
+ <element name="command-reference">
+ <attribute name="id"><data type="IDREF"/></attribute>
+ </element>
+</define>
+
+@endverbatim
+
+The element <command-reference> has the same effect that the <keyseq>
+in the referred <command> would have, if appeared in its place.
-<li> variable list
+#if EXAMPLE_CODE
+<command-reference id="command-start"/>
+#endif
-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.
+This code calls command "commad-start".
-</ul>
+@verbatim
-Each @c PREDEFINED-SYMBOL has a special meaning when used as a marker.
+<define name="action">
+ <choice>
+ <ref name="insert"/>
+ <ref name="delete"/>
+ <ref name="select"/>
-<ul>
-<li> @c @@0, @c @@1, @c @@2, @c @@3, @c @@4, @c @@5, @c @@6, @c @@7, @c @@8, @c @@9
+ <element name="show-candidates"><empty/></element>
+ <element name="hide-candidates"><empty/></element>
-The 0th, 1st, 2nd, ... 9th position respectively.
+ <ref name="move"/>
+ <ref name="mark"/>
+ <ref name="pushback"/>
-<li> @c @@<, @c @@=, @c @@>
+ <element name="pop"><empty/></element>
-The first, the current, and the last position.
+ <ref name="undo"/>
-<li> @c @@-, @c @@+
+ <element name="commit"> <empty/></element>
+ <element name="unhandle"><empty/></element>
-The previous and the next position.
+ <ref name="call"/>
-<li> @c @@[, @c @@]
+ <element name="set"><ref name="set-val"/></element>
+ <element name="add"><ref name="set-val"/></element>
+ <element name="sub"><ref name="set-val"/></element>
+ <element name="mul"><ref name="set-val"/></element>
+ <element name="div"><ref name="set-val"/></element>
-The previous and the next position where a candidate list changes.
-</ul>
+ <ref name="if"/>
+ <ref name="conditional"/>
-Some of the @c PREDEFINED-SYMBOL has a special meaning when used as a candidate
-index in the @c SELECT action.
+ <element name="macro-reference">
+ <attribute name="id">
+ <data type="IDREF"/>
+ </attribute>
+ </element>
+ </choice>
+</define>
-<ul>
+@endverbatim
-<li> @c @@<, @c @@=, @c @@>
+The element <action>s appear in <rule>s.
-The first, the current, and the last candidate of the current candidate group.
+The element <show-candidates> instructs the input method driver to
+display a candidate list associated with the string before the current
+position.
-<li> @c @@-
+The element <hide-candidates> instructs the input method driver to
+hide the currently displayed candidate list.
-The previous candidate. If the current candidate is the first one in
-the current candidate group, then it means the last candidate in the
-previous candidate group.
+The element <pop> pops the first key event that is not yet handled
+from the event queue.
-<li> @c @@+
+The element <commit> commits the current preedit.
-The next candidate. If the current candidate is the last one in the
-current candidate group, then it means the first candidate in the next
-candidate group.
+The element <unhandle> commits the current preedit and returns the last key as
+unhandled.
-<li> @c @@[, @c @@]
+The element <set>, <add>, <sub>, <mul> and
+<div> sets, increments, decrements, multiplies and divides the
+value of the variable respecrively.
-The candidate in the previous and the next candidate group having the same
-candidate index as the current one.
-</ul>
+#if EXAMPLE_CODE
+<set id="MAX-COUNT">
+ <int-val>4</int-val>
+</set>
+#endif
-And, this also has a special meaning.
+This code sets @c MAX-COUNT to 4.
-<ul>
-<li> @c @@@
+#if EXAMPLE_CODE
+<add id="C-AFTER-V">
+ <int-val>1</int-val>
+</add>
+#endif
-Number of handled keys at that moment.
+This code increments @c C-AFTER-V by 1.
-</ul>
+The element <macro-reference> has the same effect that the <action>s
+in the referred <macro> would have, if appeared in its place.
-These are for supporting surround text handling.
+@verbatim
-<ul>
-<li> @c @@-0
+<define name="set-val">
+ <attribute name="id"/>
+ <ref name="expr"/>
+</define>
--1 if surrounding text is supported, -2 if not.
+@endverbatim
-<li> @c @@-N
+The value of the variable specified by the attribute "id" is set to,
+or added, subtracted, multiplied or divided by the value of
+<expr>.
-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.
+@verbatim
-<li> @c @@+N
+<define name="insert">
+ <element name="insert">
+ <choice>
+ <attribute name="string"><data type="string"/></attribute>
+ <attribute name="character">
+ <choice>
+ <data type="string"><param name="pattern">\?.</param></data>
+ <data type="string"><param name="pattern">[0#]x[0-9A-F]{1,6}</param></data>
+ <data type="nonNegativeInteger"><param name="pattern">[0-9]{1,7}</param></data>
+ </choice>
+ </attribute>
+ <group>
+ <attribute name="character-or-string"><value>variable</value></attribute>
+ <ref name="variable-reference"/>
+ </group>
+
+ <oneOrMore>
+ <element name="candidates">
+ <data type="string"/>
+ </element>
+ </oneOrMore>
+ <oneOrMore>
+ <element name="list-of-candidates">
+ <list>
+ <zeroOrMore><data type="NMTOKEN"/></zeroOrMore></list>
+ </element></oneOrMore>
+ </choice>
+ </element>
+</define>
-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>
+@endverbatim
-The arguments and the behavior of each action are listed below.
+The element <insert> inserts a character or a M-text specified by its
+attribute, before the current position. The marker positions affected
+by the insertion are automatically relocated.
+
+The attribute "string" specifies a M-text to be inserted. The
+attriubute "character" specifies the code of a character to be
+inserted. The attribute "character-or-string" must have a variable as
+its value and <insert> inserts the value of the specified variable, if
+it is a valid character code or a M-text.
+
+#if EXAMPLE_CODE
+<insert string="á"/>
+<insert character="225"/>
+<insert character="0x00E1"/>
+#endif
+
+These codes insert the same character "á".
+
+When the element <candidates> is given, each character in the content
+of the element <candidtes> is a candidate to be inserted. <insert>
+inserts the first candidate before the current position. The inserted
+character is associated with the list of candidates and the
+information indicating the currently selected candidate.
+
+When the element <list-of-candidates> is given, each item in this list
+is a candidate to be inserted. <insert> inserts the first candidate
+before the current position. The inserted string is associated with
+the list of candidates and the information indicating the currently
+selected candidate.
+
+#if EXAMPLE_CODE
+<insert>
+ <candidates>$¢£¥₩</candidates>
+</insert>
+
+<insert>
+ <list-of-candidates>a ā á ǎ à</list-of-candidates>
+</insert>
+#endif
+
+These codes insert $, and a respectively and associate the whole list
+with it.
@verbatim
-INSERT ::= '(' 'insert' MTEXT ')'
- | MTEXT
- | INTEGER
- | SYMBOL
- | '(' 'insert' SYMBOL ')'
- | '(' 'insert' '(' CANDIDATES * ')' ')'
- | '(' CANDIDATES * ')'
-CANDIDATES ::= MTEXT | '(' MTEXT * ')'
+<define name="delete">
+ <choice>
+ <element name="delete-to-marker"><ref name="marker"/></element>
+ <element name="delete-to-character-position"><data type="integer"/></element>
+ <element name="delete-n-characters">
+ <attribute name="n"><data type="integer"/></attribute>
+ </element>
+ </choice>
+</define>
+
@endverbatim
-The first and second forms insert @c MTEXT before the current position.
+There are three <action>s for deleting characters. The marker
+positions affected by these <action>s are automatically relocated.
-The third form inserts the character @c INTEGER before the current
-position.
+The element <delet-to-marker> deletes characters between the current
+position and the marker 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.
+#if EXAMPLE_CODE
+<delete-to-marker position="@first"/>
+#endif
-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
-candidates are the M-texts in the list.
+This code deletes character between the first position and the current
+position in the buffer.
-These forms insert the first candidate before the current position.
-The inserted string is associated with the list of candidates and
-the information indicating the currently selected candidate.
+The element <delete-to-character-position> treats its content as a
+character position, and deletes characters between the current
+position and the character position.
-The marker positions affected by the insertion are automatically relocated.
+#if EXAMPLE_CODE
+<delete-to-character-position>-3</delete-to-character-position>
+#endif
-@verbatim
-DELETE ::= '(' 'delete' SYMBOL ')'
- | '(' 'delete' INTEGER ')'
-@endverbatim
+This code deletes 3 characters before the current position in the buffer.
-The first form treats @c SYMBOL as a marker, and deletes characters
-between the current position and the marker position.
+The element <delete-n-characters> treats the value of the attribute
+"n" as the number of characters to be deleted, and executes the
+deletion. If the value N is negative, the preceding N characters from
+the current position are deleted. If positive, folliwing N characters
+are deleted.
-The second form treats @c INTEGER as a character position, and deletes
-characters between the current position and the character position.
+#if EXAMPLE_CODE
+<delete-n-characters n="+1"/>
+#endif
-The marker positions affected by the deletion are automatically relocated.
+This code deletes one following character.
@verbatim
-SELECT ::= '(' 'select' PREDEFINED-SYMBOL ')'
- | '(' 'select' INTEGER ')'
- | '(' 'select' SYMBOL ')'
-@endverbatim
-This action first checks if the character just before the current position
-belongs to a string that is associated with a candidate list. If it is,
-the action replaces that string with a candidate specified by the
-argument.
+<define name="select">
+ <element name="select">
+ <choice>
+ <attribute name="selector">
+ <ref name="predefined-selector"/>
+ </attribute>
+ <attribute name="index">
+ <data type="integer"/>
+ </attribute>
+ <group>
+ <attribute name="index"><value>variable</value></attribute>
+ <ref name="variable-reference"/>
+ </group>
+ </choice>
+ </element>
+</define>
-The first form treats @c PREDEFINED-SYMBOL as a candidate index (as
-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.
+@endverbatim
-In the third form, @c SYMBOL must have a integer value, and it is treated
-as a candidate index.
+The element <select> first checks if the character just before the
+current position belongs to a string that is associated with a
+candidate list. If it is, the action replaces that string with a
+candidate specified by the attribute. The value of the attribute
+"selector" is a predefined-selector that specifies a new candidate in
+the candidate list. The value of the attribute "index" specifies a
+position in the candidate list, and the candidate at the position is
+selected. When the value is "variable", the variable referred must
+have an integer value that specifies the position in the candidate
+list.
-@verbatim SHOW ::= '(show)' @endverbatim
+#if EXAMPLE_CODE
+<select selector="@previous"/>
+<select index="0"/>
+#endif
-This actions instructs the input method driver to display a candidate
-list associated with the string before the current position.
+These code selects the previous or the first candidate respectively.
@verbatim
-HIDE ::= '(hide)'
+
+<define name="move">
+ <choice>
+ <element name="move-to-marker"> <ref name="marker"/></element>
+ <element name="move-to-character-position"> <data type="integer"/></element>
+ </choice>
+</define>
+
@endverbatim
-This action instructs the input method driver to hide the currently
-displayed candidate list.
+These two <action>s moves marker positions. The element
+<move-to-marker> makes the marker position to be the new current
+position. The element <move-to-character-position> treats its
+content integer value as a character position, and makes that position
+to be the new current position.
+
+#if EXAMPLE_CODE
+<move-to-marker position="@previous"/>
+<move-to-character-position>0</move-to-character-position>
+#endif
@verbatim
-MOVE ::= '(' 'move' SYMBOL ')'
- | '(' 'move' INTEGER ')'
+
+<define name="mark">
+ <element name="mark-current-position">
+ <ref name="user-defined-marker"/>
+ </element>
+</define>
+
@endverbatim
-The first form treats @c SYMBOL as a marker, and makes the marker
-position be the new current position.
+The element <mark-current-position> sets the position of the specified marker
+to the current position.
+
+#if EXAMPLE_CODE
+<mark-current-position markerID="M"/>
+#endif
-The second form treats @c INTEGER as a character position, and makes
-that position be the new current position.
+This code sets the marker "M" to the current position.
@verbatim
-MARK ::= '(' 'mark' SYMBOL ')'
+
+<define name="pushback">
+ <choice>
+ <element name="pushback-n-events">
+ <attribute name="n"><data type="nonNegativeInteger"/></attribute>
+ </element>
+ <element name="pushback-keyseq"><ref name="keyseq"/></element>
+ </choice>
+</define>
+
@endverbatim
-This action treats @c SYMBOL as a marker, and sets its position to the
-current position. @c SYMBOL must not be a @c PREDEFINED-SYMBOL.
+These two <action>s pushes back key events to the event queue. The
+element <pushback-n-events> pushes back the latest key events. If the
+value of the attribute "n" is positive integer, it specifies how many
+key events should be pushed back. If the value is zero, all key
+events are pushed back. The element <pushback-keyseq> pushes back
+keys specified by <keyseq;gt;.
+
+#if EXAMPLE_CODE
+<pushback-keyseq><keyseq keys="b"/></pushback-keyseq>
+#endif
+
+This code pushes back a "b".
@verbatim
-PUSHBACK :: = '(' 'pushback' INTEGER ')'
- | '(' 'pushback' KEYSEQ ')'
+
+<define name="undo">
+ <element name="undo">
+ <optional>
+ <choice>
+ <attribute name="target-of-undo">
+ <choice>
+ <data type="positiveInteger"/>
+ <data type="negativeInteger"/>
+ </choice>
+ </attribute>
+ <ref name="variable-reference"/>
+ </choice>
+ </optional>
+ </element>
+</define>
+
@endverbatim
-The first form pushes back the latest @c INTEGER number of key events
-to the event queue if @c INTEGER is positive, and pushes back all key
-events if @c INTEGER is zero.
+The element <undo> cancels the last two key events (i.e. the one that
+invoked this command, and the previous one) when no attirubute is
+given. If the value of the attribute "target-of-undo" is a positive
+integer NUM, from the NUMth to the last events are canceled. If it is
+a negative integer NUM, the last (- NUM) events are canceled. When a
+variable appears, it must be resolved to an nonzero integer and the
+integer is treated as above.
-The second form pushes back keys in @c KEYSEQ to the event queue.
+#if EXAMPLE_CODE
+<undo target-of-undo="-1"/>
+#endif
@verbatim
-POP ::= '(' 'pop' ')'
+
+<define name="call">
+ <element name="call">
+ <attribute name="id"><data type="IDREF"/></attribute>
+ <element name="function-reference">
+ <attribute name="id"><data type="IDREF"/></attribute>
+ </element>
+ <zeroOrMore>
+ <element name="argument">
+ <choice>
+ <group>
+ <attribute name="type"><value>string</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>integer</value></attribute>
+ <choice>
+ <data type="string"><param name="pattern">\?.</param></data>
+ <data type="string"><param name="pattern">[0#]x[0-9A-F]{1,6}</param></data>
+ <data type="nonNegativeInteger"><param name="pattern">[0-9]{1,7}</param></data>
+ </choice>
+ </group>
+ <group>
+ <attribute name="type"><value>plist</value></attribute>
+ <ref name="plistObject"/>
+ </group>
+ <group>
+ <attribute name="type"><value>symbol</value></attribute>
+ <ref name="variable-reference"/>
+ </group>
+ </choice>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
+
@endverbatim
-This action pops the first key event that is not yet handled from the
-event queue.
+The element <call> calls a function of an external module. The
+function must return NULL or a value of the type (#MPlist *) that
+represents a list of actions to take.
+
+The value of the attribute "id" specifies an external module. It must
+appear in the elemenet <module-list>. The element
+<function-reference> specifies a function to be called. It must
+appear in the elemenet <module-list>.
+
+The function can be called with an argument of the type (#MPlist
+*). The key of the first element of the list is #Mt and its value is
+a pointer to an object of the type #MInputContext. The key of the second
+element of the list is #Msymbol and its value is the current state name.
+The element <argument> specifies the value of the third element or later.
+Their keys are determined automatically; if the value of the attribute "type"
+is "integer", the corresponding key is #Minteger; if it is a symbol, the
+corresponding key is #Msymbol, etc.
+
+#if EXAMPLE_CODE
+<call id="module-libmimx-anthy">
+ <function-reference id="function-resize"/>
+ <argument type="symbol">
+ <variable-reference id="t"/>
+ </argument>
+</call>
+#endif
+
+This code calls the function function-resize of the module
+module-libmimx-anthy with a symbol argument whose value is "t".
@verbatim
-UNDO :: = '(' 'undo' [ INTEGER | SYMBOL ] ')'
+
+<define name="expr">
+ <choice>
+ <group>
+ <element name="expr">
+ <attribute name="operator"><ref name="operator"/></attribute>
+ <zeroOrMore><ref name="expr"/></zeroOrMore>
+ </element>
+ </group>
+ <element name="int-val">
+ <choice>
+ <data type="integer"/>
+ <data type="string"><param name="pattern">[0#]x[0-9A-F]{1,6}</param></data>
+ <data type="string"><param name="pattern">\?.</param></data>
+ </choice>
+ </element>
+ <ref name="predefined-nth-previous-or-following-character">
+ </ref>
+ <ref name="variable-reference">
+ </ref>
+ </choice>
+</define>
+
@endverbatim
-If there's no argument, this action cancels the last two key events
-(i.e. the one that invoked this command, and the previous one).
+An <expr>ession can be
+ @li a zero or more <expr>essions conbined with an operator,
+ @li an integer value.
+ @li a character at a specified position.
+ @li a variable.
-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.
+#if EXAMPLE_CODE
+<expr operator="=">
+ <predefined-nth-previous-or-following-character position="-1"/>
+ <int-val>0x0D91</int-val>
+</expr>
+#endif
-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.
+This code is an expression as a whole, and it contains two (the second
+and the third line) expressions.
@verbatim
-COMMIT :: = '(commit)'
-@endverbatim
-This action commits the current preedit.
+<define name="variable-reference">
+ <element name="variable-reference">
+ <choice>
+ <attribute name="id"/>
+ <ref name="predefined-variable"/>
+ </choice>
+ </element>
+</define>
-@verbatim
-UNHANDLE :: = '(unhandle)'
@endverbatim
-This action commits the current preedit and returns the last key as
-unhandled.
+The element <variable-reference> has the same effect that the value of
+the referred <variable> would have, if appeared in its place.
+
+#if EXAMPLE_CODE
+<variable-reference id="handled-keys" type="predefined"/>
+<variable-reference id="KK"/>
+#endif
@verbatim
-SHIFT :: = '(' 'shift' STATE-NAME ')'
+
+<define name="operator">
+ <choice>
+ <value>+</value>
+ <value>-</value>
+ <value>*</value>
+ <value>/</value>
+ <value>|</value>
+ <value>&</value>
+ <value>!</value>
+ <value>=</value>
+ <value><</value>
+ <value>></value>
+ <value><=</value>
+ <value>>=</value>
+ </choice>
+</define>
+
@endverbatim
-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.
+These are the operatiors that can appear in <expr>essions. The
+operators @c +, @c -, @c *, @c / does arithmetics. @c |, @c &, @c
+! are OR, AND, NOT operators. The operators @c =, @c <, @c >,
+@c <=, @c >= take two arguments and compare them.
@verbatim
-CALL ::= '(' 'call' MODULE-NAME FUNCTION ARG * ')'
-ARG ::= INTEGER | SYMBOL | MTEXT | PLIST
+<define name="if">
+ <element name="if">
+ <attribute name="condition">
+ <choice>
+ <value>=</value>
+ <value><</value>
+ <value>></value>
+ <value><=</value>
+ <value>>=</value>
+ </choice></attribute>
+ <ref name="expr"/>
+ <ref name="expr"/>
+ <element name="if-true-action-list">
+ <zeroOrMore><ref name="saction"/></zeroOrMore></element>
+ <optional><element name="if-not-true-action-list">
+ <zeroOrMore><ref name="saction"/></zeroOrMore></element></optional>
+ </element>
+</define>
+
@endverbatim
-This action calls the function @c FUNCTION of external module @c
-MODULE-NAME. @c MODULE-NAME and @c FUNCTION must appear in @c
-MODULE-LIST.
+The element <if> performs actions in <if-true-action-list> if the
+relation between its two <expr>essions meets the attribute
+"condition". If not, <if> performs actions in the element
+<if-not-true-action-list> (if it exists.)
-The function is called with an argument of the type (#MPlist *). The
-key of the first element is #Mt and its value is a pointer to an
-object of the type #MInputContext. The key of the second element is
-#Msymbol and its value is the current state name. @c ARGs are used as
-the value of the third and later elements. Their keys are determined
-automatically; if an @c ARG is an integer, the corresponding key is
-#Minteger; if an @c ARG is a symbol, the corresponding key is
-#Msymbol, etc.
+#if EXAMPLE_CODE
+<if condition="<">
+ <variable-reference id="C"/><int-val>0</int-val>
+ <if-true-action-list><shift-to id="state-init"/></if-true-action-list>
+</if>
+#endif
-The function must return NULL or a value of the type (#MPlist *) that
-represents a list of actions to take.
+This code performs the <shift-to> action if the variable @c C is negative.
@verbatim
-SET ::= '(' CMD SYMBOL1 EXPRESSION ')'
-CMD ::= 'set' | 'add' | 'sub' | 'mul' | 'div'
+<define name="conditional">
+ <element name="conditional">
+ <zeroOrMore>
+ <group>
+ <element name="case">
+ <ref name="expr"/>
+ <zeroOrMore><ref name="saction"/></zeroOrMore>
+ </element>
+ </group>
+ </zeroOrMore>
+ </element>
+</define>
-EXPRESSION ::= INTEGER | SYMBOL2 | '(' OPERATOR EXPRESSION * ')'
+@endverbatim
-OPERATOR ::= '+' | '-' | '*' | '/' | '|' | '&' | '!'
- | '=' | '<' | '>' | '<=' | '>='
+The element <conditional> checks the <expr>s in the <case>s one by one,
+and performs <saction>s in the first <case> whose <expr> has a nonzero value.
-@endverbatim
+#if EXAMPLE_CODE
-This action treats @c SYMBOL1 and @c SYMBOL2 as variables and sets the
-value of @c SYMBOL1 as below.
+<conditional>
+ <case>
+ <expr operator="=">
+ <predefined-nth-previous-or-following-character position="-2"/>
+ <int-val>0x0E24</int-val>
+ </expr>
+ </case>
+ <case>
+ <int-val>1</int-val>
+ <delete-n-characters n="-1"/>
+ : :
+ </case>
+</conditional>
+#endif
-If @c CMD is 'set', it sets the value of @c SYMBOL1 to the value of @c
-EXPRESSION.
+This code performs the <delete-n-characters n="-1"/> and
+following actions unless the second previous character is Thai
+character RU (whose character code is 0x0E24).
-If @c CMD is 'add', it increments the value of @c SYMBOL1 by the value
-of @c EXPRESSION.
+@subsection imstate Input Method States
-If @c CMD is 'sub', it decrements the value of @c SYMBOL1 by the value
-of @c EXPRESSION.
+@verbatim
+
+<define name="state-list">
+ <element name="state-list">
+ <zeroOrMore>
+ <element name="state">
+ <attribute name="id">
+ <data type="ID"><param name="pattern">state-.*</param></data>
+ </attribute>
+ <optional><element name="state-title-text"><data type="string"/></element></optional>
+ <interleave>
+ <optional>
+ <element name="state-hook"><oneOrMore><ref name="saction"/></oneOrMore></element>
+ </optional>
+ <optional>
+ <element name="catch-all-branch">
+ <zeroOrMore><ref name="saction"/></zeroOrMore>
+ </element>
+ </optional>
+ <zeroOrMore>
+ <element name="branch">
+ <attribute name="branch-selecting-map">
+ <data type="IDREF"/>
+ </attribute>
+ <zeroOrMore><ref name="saction"/></zeroOrMore>
+ </element>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </zeroOrMore>
+ </element>
+</define>
-If @c CMD is 'mul', it multiplies the value of @c SYMBOL1 by the value
-of @c EXPRESSION.
+@endverbatim
-If @c CMD is 'div', it divides the value of @c SYMBOL1 by the value of
-@c EXPRESSION.
+The input method driver is always in one of the <state>s of an
+<input-method> and may transit to another <state> when
+processing an input. The same input sequence can trigger different
+<saction>s and produce different results in different
+<state>s. When an input context is created, i.e. the input
+method is invoked, it is in the first <state> of the
+<state-list>.
+
+The attribute "id" gives the name of a <state>. The element
+<state-title-text> specifies a title text displayed on the
+screen when the input method is in this state. When this element is
+omitted, the content of the <title> element is used instead.
+
+Each <state> has zero or more <branch>es. Each
+<branch> corresponds to a <map> in a <map-list>.
+The value of the attribute "branch-selecting-map" specifies a
+<map>'s "id" value. When the input sequence matches one of the
+<keyseq> (or <command-reference>) of a <rule> of the
+<map>, the corresponding <branch> is selected,
+<action>s in the <rule> are executed, and <saction>s
+in that <branch> are executed.
+
+Optional element <state-hook> specifies <sactions>
+executed when the input method driver is shifted to the current
+<state>. Remember that when an input context of the input
+method is created, the input method is "shifted" to the first
+<state> in the <state-list> element, and the
+<saction>s in the <state-hook> of the first <state>
+will be executed.
+
+When an input sequence does not match with any of the <branch>s in the current <state>,
+ @li If the <catch-all-branch> element exists,
+ <saction>s in the <catch-all-branch> is executed.
+ @li If the <catch-all-branch> is omitted,
+ the input method transits to the initial state.
+
+#if EXAMPLE_CODE
+
+<state-list>
+ <state id="state-init">
+ <branch branch-selecting-map="map-consonant">
+ <move-to-marker position="@first"/>
+ : :
+ </branch>
+ <branch branch-selecting-map="map-misc"/>
+ <branch branch-selecting-map="map-join">
+ <shift-to id="state-join"/>
+ </branch>
+ </state>
+ <state id="state-join">
+ <branch branch-selecting-map="map-consonant">
+ <move-to-marker position="@first"/>
+ : :
+ <shift-to id="state-init"/>
+ </branch>
+ <catch-all-branch>
+ <shift-to id="state-init"/>
+ </catch-all-branch>
+ </state>
+</state-list>
+#endif
+
+This code defines state transitions in an input method. It has two
+states "state-init" and "state-join". The state "state-init" has
+three branches. When an input sequence belonging to "map-consonant",
+"map-misc" and "map-join" is given, the corresponding branch is
+selected and its <saction>s are executed. When "map-join" is
+selected, the state is shift to "state-join". The state "state-join"
+has one branch for input sequences from "map-consonant" and one
+catch-all-branch for everything else, both shiting the state to
+"state-init".
@verbatim
-IF ::= '(' CONDITION ACTION-LIST1 ACTION-LIST2 ? ')'
-
-CONDITION ::= [ '=' | '<' | '>' | '<=' | '>=' ] EXPRESSION1 EXPRESSION2
-ACTION-LIST1 ::= '(' ACTION * ')'
+<define name="saction">
+ <choice>
+ <element name="shift-to"><attribute name="id"><data type="IDREF"/></attribute></element>
+ <element name="shift-back"><empty/></element>
+ <ref name="action"/>
+ </choice>
+</define>
-ACTION-LIST2 ::= '(' ACTION * ')'
@endverbatim
-This action performs actions in @c ACTION-LIST1 if @c CONDITION is
-true, and performs @c ACTION-LIST2 (if any) otherwise.
+<saction>s (state-actions) are <action>s and state transitions.
+
+The element <shift-to> shifts the current state to the one specified
+by the value of the attribute "id". The value must appear in
+<state-list>. The element <shift-back> shifts the current state to
+the previous one.
+
+@subsection implist Plist
+
+plistObject used in the element <call> is defined as below.
+
+@verbatim
-@c SYMBOL1 and @c SYMBOL2 are treated as variables.
+ <define name="plistObject">
+ <element name="pListObject">
+ <choice>
+ <ref name="array"/>
+ <ref name="dict"/>
+ <group>
+ <attribute name="type"><value>string</value></attribute>
+ <data type="string"/>
+ </group>
+ <group>
+ <attribute name="type"><value>symbol</value></attribute>
+ <ref name="variable-reference"/>
+ </group>
+ <group>
+ <attribute name="type"><value>integer</value></attribute>
+ <choice>
+ <data type="string"><param name="pattern">\?.</param></data>
+ <data type="string"><param name="pattern">[0#]x[0-9A-F]{1,6}</param></data>
+ <data type="nonNegativeInteger"><param name="pattern">[0-9]{1,7}</param></data>
+ </choice>
+ </group>
+ </choice>
+ </element>
+ </define>
+
+
+ <!-- Collections -->
+ <define name="array">
+ <element name="array">
+ <zeroOrMore>
+ <ref name="plistObject"/>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <define name="dict">
+ <element name="dict">
+ <zeroOrMore>
+ <element name="dict-item">
+ <attribute name="key"/>
+ <ref name="plistObject"/>
+ </element>
+ </zeroOrMore>
+ </element>
+ </define>
+@endverbatim
@verbatim
-COND ::= '(' 'cond' [ '(' EXPRESSION ACTION * ') ] * ')'
+</grammar>
@endverbatim
-This action performs the first action @c ACTION whose corresponding
-@c EXPRESSION has nonzero value.
+The RelaxNG schema for a input method closes with </grammar>.
@ifnot FOR-MAN
The definition of the input method is very simple as below, and it is
quite straight forward to extend it to cover all Latin characters.
-@if FOR-HTML
@verbatim
-(title "latin-postfix")
-(map
- (trans
- ("a'" ?á) ("e'" ?é) ("i'" ?í) ("o'" ?ó) ("u'" ?ú) ("c," ?ç)
- ("A'" ?Á) ("E'" ?É) ("I'" ?Í) ("O'" ?Ó) ("U'" ?Ú) ("C," ?Ç)
- ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")
- ("c,," "c,")
- ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")
- ("C,," "C,")))
-(state
- (init
- (trans)))
+<?xml version='1.0'?>
+<input-method xmlns="http://www.m17n.org/MIM">
+ <tags>
+ <language>t</language>
+ <name>latn-post</name>
+ </tags>
+ <title>latin-postfix</title>
+ <map-list>
+ <map id="map-trans">
+ <rule><keyseq keys="A'"/><insert string="Á"/></rule>
+ <rule><keyseq keys="a'"/><insert string="á"/></rule>
+ <rule><keyseq keys="A''"/><insert string="A'"/></rule>
+ <rule><keyseq keys="a''"/><insert string="a'"/></rule>
+ <rule><keyseq keys="C,"/><insert string="Ç"/></rule>
+ <rule><keyseq keys="c,"/><insert string="ç"/></rule>
+ <rule><keyseq keys="C,,"/><insert string="C,"/></rule>
+ <rule><keyseq keys="c,,"/><insert string="c,"/></rule>
+ <rule><keyseq keys="E'"/><insert string="É"/></rule>
+ <rule><keyseq keys="e'"/><insert string="é"/></rule>
+ <rule><keyseq keys="E''"/><insert string="E'"/></rule>
+ <rule><keyseq keys="e''"/><insert string="e'"/></rule>
+ <rule><keyseq keys="I'"/><insert string="Í"/></rule>
+ <rule><keyseq keys="i'"/><insert string="í"/></rule>
+ <rule><keyseq keys="I''"/><insert string="I'"/></rule>
+ <rule><keyseq keys="i''"/><insert string="i'"/></rule>
+ <rule><keyseq keys="O'"/><insert string="Ó"/></rule>
+ <rule><keyseq keys="o'"/><insert string="ó"/></rule>
+ <rule><keyseq keys="O''"/><insert string="O'"/></rule>
+ <rule><keyseq keys="o''"/><insert string="o'"/></rule>
+ <rule><keyseq keys="U'"/><insert string="Ú"/></rule>
+ <rule><keyseq keys="u'"/><insert string="ú"/></rule>
+ <rule><keyseq keys="U''"/><insert string="U'"/></rule>
+ <rule><keyseq keys="u''"/><insert string="u'"/></rule>
+ </map>
+ </map-list>
+ <state-list>
+ <state id="state-init">
+ <branch branch-selecting-map="map-trans"/>
+ </state>
+ </state-list>
+</input-method>
@endverbatim
-@endif
-@if FOR-LATEX
-@latexonly
-\texttt{\footnotesize
-\hskip2mm(title "latin-postfix")\\
-\hskip2mm(map\\
-\hskip4mm (trans\\
-\hskip6mm ("a'" ?\'{a}) ("e'" ?\'{e}) ("i'" ?\'{i}) ("o'" ?\'{o})
-("u'" ?\'{u}) ("c," ?\c{c})\\
-\hskip6mm ("A'" ?\'{A}) ("E'" ?\'{E}) ("I'" ?\'{I}) ("O'" ?\'{O})
-("U'" ?\'{U}) ("C," ?\c{C})\\
-\hskip6mm ("a''" "a'") ("e''" "e'") ("i''" "i'") ("o''" "o'") ("u''" "u'")\\
-\hskip6mm ("c,," "c,")\\
-\hskip6mm ("A''" "A'") ("E''" "E'") ("I''" "I'") ("O''" "O'") ("U''" "U'")\\
-\hskip6mm ("C,," "C,")))\\
-\hskip2mm(state\\
-\hskip4mm (init\\
-\hskip6mm (trans)))}
-@endlatexonly
-@endif
+
@section im-example2 EXAMPLE 2
@endverbatim
@endif
-The definition utilizes @c SET and @c IF commands as below:
-@verbatim
-(title "UNICODE")
-(map
- (starter
- ((C-U) "U+"))
- (hex
- ("0" ?0) ("1" ?1) ... ("9" ?9) ("a" ?A) ("b" ?B) ... ("f" ?F)))
-(state
- (init
- (starter (set code 0) (set count 0) (shift unicode)))
- (unicode
- (hex (set this @-)
- (< this ?A
- ((sub this 48))
- ((sub this 55)))
- (mul code 16) (add code this)
- (add count 1)
- (= count 4
- ((delete @<) (insert code) (shift init))))))
+The definition utilizes <set> and <conditional> as below:
+@verbatim
+<?xml version='1.0'?>
+<input-method xmlns="http://www.m17n.org/MIM">
+ <tags>
+ <language>t</language>
+ <name>unicode</name>
+ </tags>
+ <title>UNICODE</title>
+ <map-list>
+ <map id="map-starter">
+ <rule><keyseq><key-event>C-U</key-event></keyseq><insert string="U+"/></rule>
+ </map>
+ <map id="map-hex">
+ <rule><keyseq keys="0"/><insert string="0"/></rule>
+ <rule><keyseq keys="1"/><insert string="1"/></rule>
+ : :
+ <rule><keyseq keys="9"/><insert string="9"/></rule>
+ <rule><keyseq keys="A"/><insert string="A"/></rule>
+ <rule><keyseq keys="B"/><insert string="B"/></rule>
+ : :
+ <rule><keyseq keys="f"/><insert string="F"/></rule>
+ </map>
+ </map-list>
+ <state-list>
+ <state id="state-init">
+ <branch branch-selecting-map="map-starter">
+ <set id="code"><int-val>0</int-val></set>
+ <set id="count"><int-val>0</int-val></set>
+ <shift-to id="state-uni-hex"/>
+ </branch>
+ </state>
+ <state id="state-uni-hex">
+ <branch branch-selecting-map="map-hex">
+ <set id="this"><predefined-nth-previous-or-following-character position="-1"/></set>
+ <conditional>
+ <case>
+ <expr operator="<">
+ <predefined-nth-previous-or-following-character position="-1"/>
+ <int-val>65</int-val> <!-- ?A -->
+ </expr>
+ <sub id="this"><int-val>48</int-val></sub>
+ </case>
+ <case>
+ <int-val>1</int-val>
+ <sub id="this"><int-val>55</int-val></sub>
+ </case>
+ </conditional>
+ <set id="code">
+ <expr operator="+">
+ <expr operator="*">
+ <variable-reference id="code"/>
+ <int-val>16</int-val>
+ </expr>
+ <variable-reference id="this"/>
+ </expr>
+ </set>
+ <set id="count">
+ <expr operator="+">
+ <variable-reference id="count"/>
+ <int-val>1</int-val>
+ </expr>
+ </set>
+ <conditional>
+ <case>
+ <expr operator="=">
+ <variable-reference id="count"/>
+ <int-val>4</int-val>
+ </expr>
+ <delete-to-marker position="@first"/>
+ <insert character-or-string="variable">
+ <variable-reference id="code"/>
+ </insert>
+ <shift-to id="state-init"/>
+ </case>
+ </conditional>
+ </branch>
+ </state>
+ </state-list>
+</input-method>
+
@endverbatim
@section im-example3 EXAMPLE 3
你好北京
@endverbatim
-The definition utilizes @c CANDIDATE and @c SELECT commands as below.
+The definition utilizes <candidate> and <select> as below.
Note that this is just an example, and it ignores such important key
as Backspace.
@verbatim
-(title "拼")
-
-(map
- ;; The initial character of Pinyin.
- (starter
- ("a") ("b") ... ("h") ("j") ... ("t") ("w") ("x") ("y") ("z"))
-
- ;; Big table of Pinyin vs the corresponding Chinese characters.
- (pinyin
- ...
- ("bei" ("被北备背悲辈杯倍贝碑" ...))
- ("hao" ("好号毫豪浩耗皓嚎昊郝" ...))
- ("jing" ("经京精境警竟静惊景敬" ...))
- ("ni" ("你呢尼泥逆倪匿拟腻妮" ...))
- ...)
- ;; Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.
- (choose
- ("1" (select 0)) ("2" (select 1)) ... ("9" (select 8)) ("0" (select 9))))
-
-(state
- (init
- ;; When an initial character of Pinyin is typed, re-handle it in
- ;; "main" state. Anything else is just produced as is.
- (starter (show) (pushback 1) (shift main)))
-
- (main
- ;; When a complete Pinyin sequence is typed, shift to "select" state
- ;; to allow users to select one from the candidates.
- (pinyin (shift select))
-
- ;; When anything else is typed, produce the current candidate (if
- ;; any), and re-handle the last input in "init" state.
- (nil (hide) (shift init)))
-
- (select
- ;; When a number is typed, select the corresponding canidate,
- ;; produce it, and shift to "init" state.
- (choose (hide) (shift init))
-
- ;; When anything else is typed, produce the current candidate,
- ;; and re-handle the last input in "init" state.
- (nil (hide) (shift init))))
+<input-method> <tags>..</tags>
+<title>"拼"</title>
+
+<map-list>
+ <map id="map-starter">
+<!-- The initial character of Pinyin.-->
+ <rule><keyseq keys="a"/></rule>
+ <rule><keyseq keys="b"/></rule>
+ : :
+ <rule><keyseq keys="z"/></rule>
+ </map>
+ <map id="map-pinyon">
+<!-- Big table of Pinyin vs the corresponding Chinese characters.-->
+ <rule><keyseq keys="bei"/>
+ <insert><candidates>被北备背悲辈杯倍贝碑... </candidates>...</insert></rule>
+ <rule><keyseq keys="hao"/>
+ <insert><candidates>好号毫豪浩耗皓嚎昊郝... </candidates>...</insert></rule>
+ <rule><keyseq keys="jing"/>
+ <insert><candidates>经京精境警竟静惊景敬... </candidates>...</insert></rule>
+ <rule><keyseq keys="ni"/>
+ <insert><candidates>你呢尼泥逆倪匿拟腻妮... </candidates>...</insert></rule>
+ </map>
+ <map id="map-choose">
+<!-- Typing 1, 2, ..., 0 selects the 0th, 1st, ..., 9th candidate.-->
+ <rule><keyseq keys="1"/><select index="0"/></rule>
+ <rule><keyseq keys="2"/><select index="1"/></rule>
+ : :
+ <rule><keyseq keys="9"/><select index="8"/></rule>
+ <rule><keyseq keys="0"/><select index="9"/></rule>
+ </map>
+</map-list>
+
+<state-list>
+ <state id="state-init">
+<!-- When an initial character of Pinyin is typed, re-handle it in
+ "state-main" state. Anything else is just produced as is. -->
+ <branch branch-selecting-map="map-starter">
+ <show-candidates/>
+ <pushback-n-events n="1"/>
+ <shift-to id="state-main"/>
+ </branch>
+ </state>
+
+ <state id="state-main">
+<!-- When a complete Pinyin sequence is typed, shift to "state-select" state
+ to allow users to select one from the candidates. -->
+ <branch branch-selecting-map="map-pinyin">
+ <shift-to id="state-select"/>
+ </branch>
+<!-- When anything else is typed, produce the current candidate (if
+ any), and re-handle the last input in "state-init" state. -->
+ <catch-all-branch>
+ <hide-candidates/>
+ <shift-to id="state-init"/>
+ </catch-all-branch>
+ </state>
+
+ <state id="state-select">
+<!-- When a number is typed, select the corresponding canidate,
+ produce it, and shift to "init" state. -->
+ <branch branch-selectiong-map="map-choose">
+ <hide-candidates/>
+ <shift-to id="state-init"/>
+ </branch>
+
+<!-- When anything else is typed, produce the current candidate,
+ and re-handle the last input in "init" state. -->
+ <catch-all-branch>
+ <hide-candidates/>
+ <shift-to id="state-init"/>
+ </catch-all-branch>
+ </state>
+ </state-list>
+</input-method>
+
@endverbatim
@elseif FOR-LATEX