--- /dev/null
+<?xml version='1.0'?>
+<input-method xmlns="http://www.m17n.org/MIM">
+ <tags>
+ <language>t</language>
+ <name>nil</name>
+ <extra-id>global</extra-id>
+ </tags>
+ <description>
+ <gettext>Global variable and command definitions.
+This is actually not an input method, but provides documents,
+default values of global variables, and default key-bindings of
+global commands.</gettext>
+ </description>
+ <variable-list>
+ <defvar vname="candidates-group-size">
+ <description>
+ <gettext>Maxmum number of candidates in a candidate group.
+Value must be an integer.
+If the value is not positive, number of candidates in a group is decided
+by how candiates are grouped in an input method source file.</gettext>
+ </description>
+ <integer>10</integer>
+ </defvar>
+ <defvar vname="candidates-charset">
+ <description>
+ <gettext>Character set to limit candidates.
+Value must be a symbol representing a charater set, or nil.
+If the value is not nil, a candidate containing a character not belonging
+to the specified character set is ignored.</gettext>
+ </description>
+ <symbol>nil</symbol>
+ </defvar>
+ </variable-list>
+ <command-list>
+ <defcmd cname="command-commit">
+ <description>
+ <gettext>Commit
+Commit the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Return</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>Linefeed</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-convert">
+ <description>
+ <gettext>Convert
+Convert the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>? </integer>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>Henkan</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-revert">
+ <description>
+ <gettext>Revert
+Revert the conversion</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Escape</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-prev-candidate">
+ <description>
+ <gettext>Previous candidate
+Spot the previous candidate</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Left</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-B</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-next-candidate">
+ <description>
+ <gettext>Next candidate
+Spot the next candidate</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Right</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-F</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <integer>? </integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-first-candidate">
+ <description>
+ <gettext>First candidate
+Spot the first candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-A</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-last-candidate">
+ <description>
+ <gettext>Last candidate
+Spot the last candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-E</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-prev-candidate-group">
+ <description>
+ <gettext>Previous candidate group
+Move to the previous candidate group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Up</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-P</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-next-candidate-group">
+ <description>
+ <gettext>Next candidate group
+Move to the next candidate group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Down</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-N</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-1">
+ <description>
+ <gettext>Select the 1st candidate
+Select the first candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?1</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-2">
+ <description>
+ <gettext>Select the 2nd candidate
+Select the second candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?2</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-3">
+ <description>
+ <gettext>Select the 3rd candidate
+Select the third candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?3</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-4">
+ <description>
+ <gettext>Select the 4th candidate
+Select the fourth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?4</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-5">
+ <description>
+ <gettext>Select the 5th candidate
+Select the fifth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?5</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-6">
+ <description>
+ <gettext>Select the 6th candidate
+Select the sixth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?6</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-7">
+ <description>
+ <gettext>Select the 7th candidate
+Select the seventh candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?7</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-8">
+ <description>
+ <gettext>select the 8th candidate
+Select the eighth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?8</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-9">
+ <description>
+ <gettext>Select the 9th candidate
+Select the ninth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?9</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-candidate-10">
+ <description>
+ <gettext>Select the 10th candidate
+Select the tenth candidate in the current group</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <integer>?0</integer>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-prev-char">
+ <description>
+ <gettext>Previous character
+Move to the previous character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Left</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-B</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-next-char">
+ <description>
+ <gettext>Next character
+Move to the next character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Right</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-F</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-first-char">
+ <description>
+ <gettext>Fist character
+Move to the first character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-A</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-last-char">
+ <description>
+ <gettext>Last character
+Move to the last character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-E</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-backward-delete-char">
+ <description>
+ <gettext>Delete char backward
+Delete the previous character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Backspace</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-delete-char">
+ <description>
+ <gettext>Delete char
+Delete the following character in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Delete</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-prev-segment">
+ <description>
+ <gettext>Previous segment
+Move to the previous segment in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Left</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-B</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-next-segment">
+ <description>
+ <gettext>Next segment
+Move to the next segment in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>Right</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-F</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-first-segment">
+ <description>
+ <gettext>First segment
+Move to the first segment in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-A</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-last-segment">
+ <description>
+ <gettext>Last segment
+Move to the last segment in the preedit text</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>C-E</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-extend-segment">
+ <description>
+ <gettext>Extend segment
+Extend the current segment length to the tail</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>S-Right</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-O</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command-shrink-segment">
+ <description>
+ <gettext>Shrink segment
+Shrink the current segment length from the tail</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>S-Left</symbol>
+ </list>
+ </keyseq>
+ <keyseq>
+ <list>
+ <symbol>C-I</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ <defcmd cname="command--reload">
+ <description>
+ <gettext>Reload input method
+Reload the input method (and configulation if any) and freshly start it.
+Note that the length of key-sequence bound for this command must be 1.
+This is one of special commands reserved by the m17n library, and
+should not be used in a map of an input method.</gettext>
+ </description>
+ <keyseq>
+ <list>
+ <symbol>M-Return</symbol>
+ </list>
+ </keyseq>
+ </defcmd>
+ </command-list>
+</input-method>
this.range = range;
}
-Xex.Variable.prototype.clone = function () {
+Xex.Variable.prototype.clone = function ()
+{
return new Xex.Variable (this.domain, this.name, this.desc,
this.val, this.range);
}
-Xex.Variable.prototype.Equals = function (obj) {
+Xex.Variable.prototype.Equals = function (obj)
+{
return ((obj instanceof Xex.Variable)
&& obj.name == this.name);
}
-Xex.Variable.prototype.SetValue = function (term) {
+Xex.Variable.prototype.SetValue = function (term)
+{
this.val = term;
return term;
}
-Xex.Function = function (name, with_var, min_args, max_args) {
+Xex.Function = function (name, with_var, min_args, max_args)
+{
this.name = name;
this.with_var = with_var;
this.min_args = min_args;
this.max_args = max_args;
};
-Xex.Subrountine = function (builtin, name, with_var, min_args, max_args) {
+Xex.Subrountine = function (builtin, name, with_var, min_args, max_args)
+{
this.name = name;
this.with_var = with_var;
this.min_args = min_args;
Xex.Lambda = function (name, min_args, max_args, args, body)
{
this.name = name;
- this.with_var = with_var;
this.min_args = min_args;
this.max_args = max_args;
this.args = args;
Xex.Macro = function (name, min_args, max_args, args, body)
{
this.name = name;
- this.with_var = with_var;
this.min_args = min_args;
this.max_args = max_args;
this.args = args;
this.functions[name] = new Xex.Lambda (name, min_args, max_args,
args, body);
},
- DefunByFunc: function (func) { this.functions[func.Name] = func; },
+ DefunByFunc: function (func) { this.functions[func.name] = func; },
Defmacro: function (name, min_args, max_args, args, body)
{
this.functions[name] = new Xex.Macro (name, min_args, max_args,
{
var func = this.functions[fname];
+ if (! func)
+ throw new Xex.ErrTerm (Xex.Error.UnknownFunction, fname);
if (this.termtypes[alias])
throw new Xex.ErrTerm (Xex.Error.FunctionConflict,
"Already defined as a term type: " + alias);
if (this.functions[alias])
throw new Xex.ErrTerm (Xex.Error.FunctionConflict,
"Already defined as a function: " + alias);
- if (! func)
- throw new Xex.ErrTerm (Xex.Error.UnknownFunction, fname);
this.functions[alias] = func;
},
Defvar: function (name, desc, val, range)
{
values = {};
for (var elt in this.variables)
- values[elt] = this.variables[elt].val.Clone ();
+ {
+ if (! this.variables[elt].val)
+ alert ('unknown value of ' + elt);
+ else
+ values[elt] = this.variables[elt].val.Clone ();
+ }
return values;
},
RestoreValues: function (values)
if (this.val != undefined)
return '<' + this.type + '>' + this.val + '</' + this.type + '>';
return '<' + this.type + '/>';
- }
+ },
+ Intval: function () { throw new Xex.ErrTerm (Xex.Error.WrongType,
+ "Not an integer"); },
+ Strval: function () { throw new Xex.ErrTerm (Xex.Error.WrongType,
+ "Not a string"); }
};
Node.prototype.firstElement = function ()
var args = new Array ();
var nfixed = 0, noptional = 0, nrest = 0;
- node = ndoe.firstElement ();
+ node = node.firstElement ();
if (node && node.nodeName == 'args')
{
var n;
if (node.nodeName == 'defun')
domain.Defun (name, args, null);
else
- domain.Defmacor (name, args, null);
+ domain.Defmacro (name, args, null);
return name;
}
if (node.nodeName != 'description' && node.nodeName != 'args')
break;
body = Xex.Term.Parse (domain, node, null);
- func.SetBody (body);
+ func.body = body;
}
Xex.Term.Parse = function (domain, node, stop)
if (name == 'defun' || name == 'defmacro')
{
name = parse_defun_head (domain, node);
+ MIM.log ('defmacro:' + name);
parse_defun_body (domain, node);
return new Xex.StrTerm (name);
}
if (name == 'defvar')
- {
- name = parse_defvar (domain, node);
- return new Xex.StrTerm (name);
- }
+ {
+ name = parse_defvar (domain, node);
+ MIM.log ('defvar:' + name);
+ return new Xex.StrTerm (name);
+ }
return new Xex.Funcall.prototype.Parser (domain, node);
}
for (var n = node; n && n != stop; n = n.nextElement ())
{
if (n.nodeName == 'defun' || n.nodeName == 'defmacro')
- Xex.parse_defun_head (domain, n);
+ {
+ var name = parse_defun_head (domain, n);
+ MIM.log ('defmacro:' + name);
+ }
}
var terms = null;
for (var n = node; n && n != stop; n = n.nextElement ())
{
if (n.nodeName == 'defun' || n.nodeName == 'defmacro')
- Xex.parse_defun_body (domain, n);
+ parse_defun_body (domain, n);
else if (n.nodeName == 'defvar')
parse_defvar (domain, n);
else
var attr;
if (fname == 'funcall')
- fname = node.attributes['fname']
+ fname = node.attributes['fname'].nodeValue;
var func = domain.GetFunc (fname);
var vari;
attr = node.attributes['vname'];
(function () {
var proto = new Xex.Term ('integer');
proto.IsInt = true;
+ proto.Intval = function () { return this.val; };
proto.IsTrue = function () { return this.val != 0; }
proto.Clone = function () { return new Xex.IntTerm (this.val); }
proto.Parser = function (domain, node)
(function () {
var proto = new Xex.Term ('string');
proto.IsStr = true;
+ proto.Strval = function () { return this.val; };
proto.IsTrue = function () { return this.val.length > 0; }
proto.Clone = function () { return new Xex.StrTerm (this.val); }
proto.Parser = function (domain, node)
return args[0];
}
+ function maybe_set_intvar (vari, n)
+ {
+ var term = new IntTerm (n);
+ if (vari)
+ vari.SetValue (term);
+ return term;
+ }
+
function Fadd (domain, vari, args)
{
- var n = vari ? vari.val.val : 0;
+ var n = vari ? vari.val.Intval () : 0;
var len = args.length;
for (var i = 0; i < len; i++)
- n += args[i].val;
+ n += args[i].Intval ();
+ return maybe_set_intvar (vari, n);
+ }
+
+ function Fmul (domain, vari, args)
+ {
+ var n = vari ? vari.val.Intval () : 1;
+ for (var i = 0; i < args.length; i++)
+ n *= arg.Intval ();
+ return maybe_set_intvar (vari, n);
+ }
+
+ function Fsub (domain, vari, args)
+ {
+ var n, i;
+
+ if (! vari)
+ {
+ n = args[0].Intval ();
+ i = 1;
+ }
+ else
+ {
+ n = vari.val.Intval ();
+ i = 0;
+ }
+ while (i < args.length)
+ n -= args[i++].Intval ();
+ return maybe_set_intvar (vari, n);
+ }
+
+ function Fdiv (domain, vari, args)
+ {
+ var n, i;
+
+ if (! vari == null)
+ {
+ n = args[0].Intval ();
+ i = 1;
+ }
+ else
+ {
+ n = vari.val.Intval ();
+ i = 0;
+ }
+ while (i < args.length)
+ n /= args[i++].Intval ();
+ return maybe_set_intvar (vari, n);
+ }
+
+ function Fmod (domain, vari, args)
+ {
+ return maybe_set_intvar (vari, args[0].Intval () % args[1].Intval ());
+ }
+
+ function Flogior (domain, vari, args)
+ {
+ var n = vari == null ? 0 : vari.val;
+ for (var i = 0; i < args.length; i++)
+ n |= args[i].val;
return maybe_set_intvar (vari, n);
}
var result = args[i].Eval (domain);
if (domain.Thrown ())
return result;
- if (! result.IsTrue)
+ if (! result.IsTrue ())
return Xex.Zero;
}
return Xex.One;
return Xex.One;
}
+ function Flt (domain, vari, args)
+ {
+ var n = args[0].Intval;
+
+ for (var i = 1; i < args.length; i++)
+ {
+ var n1 = args[i].Intval;
+ if (n >= n1)
+ return Xex.Zero;
+ n = n1;
+ }
+ return Xex.One;
+ }
+
+ function Fle (domain, vari, args)
+ {
+ var n = args[0].Intval;
+ for (var i = 1; i < args.length; i++)
+ {
+ var n1 = args[i].Intval;
+ if (n > n1)
+ return Xex.Zero;
+ n = n1;
+ }
+ return Xex.One;
+ }
+
+ function Fgt (domain, vari, args)
+ {
+ var n = args[0].Intval;
+ for (var i = 1; i < args.length; i++)
+ {
+ var n1 = args[i].Intval;
+ if (n <= n1)
+ return Xex.Zero;
+ n = n1;
+ }
+ return Xex.One;
+ }
+
+ function Fge (domain, vari, args)
+ {
+ var n = args[0].Intval;
+ for (var i = 1; i < args.Length; i++)
+ {
+ var n1 = args[i].Intval;
+ if (n < n1)
+ return Xex.Zero;
+ n = n1;
+ }
+ return Xex.One;
+ }
+
function Fprogn (domain, vari, args)
{
var result = Xex.One;
Xex.BasicDomain = basic;
basic.DefSubr (Fset, "set", true, 1, 1);
+ if (basic.functions['='])
+ alert (basic.functions['=']);
+ basic.DefAlias ("=", "set");
+ //basic.DefSubr (Fnot, "not", false, 1, 1);
+ //basic.DefAlias ("!", "not");
basic.DefSubr (Fadd, "add", true, 1, -1);
+ basic.DefSubr (Fmul, "mul", true, 1, -1);
+ basic.DefAlias ("*", "mul");
+ basic.DefSubr (Fsub, "sub", true, 1, -1);
+ basic.DefAlias ("-", "sub");
+ basic.DefSubr (Fdiv, "div", true, 1, -1);
+ basic.DefAlias ("/", "div");
+ basic.DefSubr (Fmod, "mod", true, 1, 2);
+ basic.DefAlias ("%", "mod");
+ basic.DefSubr (Flogior, "logior", true, 1, -1);
+ basic.DefAlias ('|', "logior");
+ //basic.DefSubr (Flogand, "logand", true, 1, -1);
+ //basic.DefAlias ("&", "logand");
+ //basic.DefSubr (Flsh, "lsh", true, 1, 2);
+ //basic.DefAlias ("<<", "lsh");
+ //basic.DefSubr (Frsh, "rsh", true, 1, 2);
+ //basic.DefAlias (">>", "rsh");
+ basic.DefSubr (Feq, "eq", false, 2, -1);
+ basic.DefAlias ("==", "eq");
+ //basic.DefSubr (Fnoteq, "noteq", false, 2, 2);
+ //basic.DefAlias ("!=", "noteq");
+ basic.DefSubr (Flt, "lt", false, 2, -1);
+ basic.DefAlias ("<", "lt");
+ basic.DefSubr (Fle, "le", false, 2, -1);
+ basic.DefAlias ("<=", "le");
+ basic.DefSubr (Fgt, "gt", false, 2, -1);
+ basic.DefAlias (">", "gt");
+ basic.DefSubr (Fge, "ge", false, 2, -1);
+ basic.DefAlias (">=", "ge");
basic.DefSubr (Fthrow, "throw", false, 1, 2);
+ //basic.DefSubr (Fappend, "append", true, 0, -1);
+ //basic.DefSubr (Fconcat, "concat", true, 0, -1);
+ //basic.DefSubr (Fnth, "nth", false, 2, 2);
+ //basic.DefSubr (Fcopy, "copy", false, 1, 1);
+ //basic.DefSubr (Fins, "ins", true, 2, 2);
+ //basic.DefSubr (Fdel, "del", true, 2, 2);
+ //basic.DefSubr (Feval, "eval", false, 1, 1);
+ //basic.DefSubr (Fbreak, "break", false, 0, 1);
+ //basic.DefSubr (Freturn, "return", false, 0, 1);
+ //basic.DefSubr (Fthrow, "throw", false, 1, 2);
+
basic.DefSpecial (Fand, "and", false, 1, -1);
+ basic.DefAlias ("&&", "and");
basic.DefSpecial (For, "or", false, 1, -1);
- basic.DefAlias ("=", "set");
+ basic.DefAlias ("||", "or");
basic.DefSpecial (Fprogn, "progn", false, 1, -1);
+ basic.DefAlias ("expr", "progn");
basic.DefSpecial (Fif, "if", false, 2, 3);
+ //basic.DefSpecial (Fwhen, "when", false, 1, -1);
+ //basic.DefSpecial (Floop, "loop", false, 1, -1);
+ //basic.DefSpecial (Fwhile, "while", false, 1, -1);
+ basic.DefSpecial (Fcond, "cond", false, 1, -1);
+ //basic.DefSpecial (Fforeach, "foreach", true, 2, -1);
+ //basic.DefSpecial (Fquote, "quote", false, 1, 1);
+ //basic.DefSpecial (Ftype, "type", false, 1, 1);
basic.DefSpecial (Fcatch, "catch", true, 2, -1);
basic.DefType (Xex.Funcall.prototype);
Xex.Zero = new Xex.IntTerm (0);
Xex.One = new Xex.IntTerm (1);
+Xex.nil = new Xex.SymTerm ('nil');
Xex.Load = function (server, file)
{
obj.open ('GET', url, false);
obj.overrideMimeType ('text/xml');
obj.send ('');
- alert (file);
return obj.responseXML.firstChild;
}
var p = this.Position (ic);
if (p < 0)
return ic.GetSurroundingChar (p);
- else if (pos >= ic.preedit.length)
+ else if (p >= ic.preedit.length)
return ic.GetSurroundingChar (p - ic.preedit.length);
return ic.preedit.charCodeAt (p);
}
{
var n = node.firstElement ();
if (node.nodeName == 'branch')
- {
- state.keymap.Add (map_list[node.attributes['mname'].nodeValue]);
- state.keymap.actions = Xex.Term.Parse (domain, n, null);
- }
+ {
+ state.keymap.Add (map_list[node.attributes['mname'].nodeValue]);
+ state.keymap.actions = Xex.Term.Parse (domain, n, null);
+ }
else if (node.nodeName == 'state-hook')
state.enter_actions = Xex.Term.Parse (domain, n, null);
else if (node.nodeName == 'catch-all-branch')
return args[0];
}
+ function Fdelete (domain, vari, args)
+ {
+ var ic = domain.context;
+ var pos = args[0].IsInt ? args[0].Intval : args[0].Position (ic);
+ ic.del (pos);
+ return new Xex.Term (ic.del (pos));
+ }
+
+ function Fselect (domain, vari, args)
+ {
+ var ic = domain.context;
+ var can = ic.candidates;
+
+ if (can)
+ {
+ var candidate = can.Current ();
+
+ ic.del (ic.cursor_pos - candidate.length);
+ candidate = can.Select (args[0]);
+ ic.insert (candidate, can);
+ }
+ return args[0];
+ }
+
+ function Fchar_at (domain, vari, args)
+ {
+ return new Xex.Term (args[0].CharAt (domain.context));
+ }
+
function Fmove (domain, vari, args)
{
var ic = domain.context;
return args[0];
}
+ function Fpushback (domain, vari, args)
+ {
+ var arg = (args[0].IsInt ? args[0].Intval
+ : args[0].IsStr ? new KeySeq (args[0])
+ : args[0]);
+ domain.context.pushback (arg)
+ return args[0];
+ }
+
+ function Fundo (domain, vari, args)
+ {
+ var ic = domain.context;
+ var n = args.length == 0 ? -2 : args[0].val;
+ if (n < 0)
+ ic.keys.val.splice (ic.keys.length + n, -n);
+ else
+ ic.keys.val.splice (n, ic.keys.length);
+ ic.reset ();
+ return Xex.nil;
+ }
+
+ function Fcommit (domain, vari, args)
+ {
+ domain.context.commit ();
+ return Xex.nil;
+ }
+
+ function Funhandle (domain, vari, args)
+ {
+ domain.context.commit ();
+ return Xex.Fthrow (domain, vari, Xex.CatchTag._mimtag);
+ }
+
+ function Fshift (domain, vari, args)
+ {
+ var ic = domain.context;
+ var state_name = args[0].val;
+ var state = ic.im.state_list[state_name];
+ if (! state)
+ throw ("Unknown state: " + state_name);
+ ic.shift (state);
+ return args[0];
+ }
+
+ function Fsurrounding_flag (domain, vari, args)
+ {
+ return new Xex.IntTerm (-1);
+ }
+
im_domain.DefSubr (Finsert, "insert", false, 1, 1);
im_domain.DefSubr (Finsert_candidates, "insert-candidates", false, 1, 1);
+ im_domain.DefSubr (Fdelete, "delete", false, 1, 1);
+ im_domain.DefSubr (Fselect, "select", false, 1, 1);
+ //im_domain.DefSubr (Fshow, "show-candidates", false, 0, 0);
+ //im_domain.DefSubr (Fhide, "hide-candidates", false, 0, 0);
im_domain.DefSubr (Fmove, "move", false, 1, 1);
im_domain.DefSubr (Fmark, "mark", false, 1, 1);
+ im_domain.DefSubr (Fpushback, "pushback", false, 1, 1);
+ //im_domain.DefSubr (Fpop, "pop", false, 0, 0);
+ im_domain.DefSubr (Fundo, "undo", false, 0, 1);
+ im_domain.DefSubr (Fcommit, "commit", false, 0, 0);
+ im_domain.DefSubr (Funhandle, "unhandle", false, 0, 0);
+ im_domain.DefSubr (Fshift, "shift", false, 1, 1);
+ //im_domain.DefSubr (Fshiftback, "shiftback", false, 0, 0);
+ im_domain.DefSubr (Fchar_at, "char-at", false, 1, 1);
+ //im_domain.DefSubr (Fkey_count, "key-count", false, 0, 0);
+ im_domain.DefSubr (Fsurrounding_flag, "surrounding-text-flag", false, 0, 0);
}) ();
return MIM.im_global.domain.variables[vname];
}
+ function include (node)
+ {
+ node = node.firstElement ();
+ if (node.nodeName != 'tags')
+ return null;
+
+ var lang = null, name = null, extra = null;
+ for (node = node.firstElement (); node; node = node.nextElement ())
+ {
+ if (node.nodeName == 'language')
+ lang = node.firstChild.nodeValue;
+ else if (node.nodeName == 'name')
+ name = node.firstChild.nodeValue;
+ else if (node.nodeName == 'extra-id')
+ extra = node.firstChild.nodeValue;
+ }
+ if (! lang || ! MIM.imlist[lang])
+ return null;
+ if (! extra)
+ {
+ if (! name || ! (im = MIM.imlist[lang][name]))
+ return null;
+ }
+ else
+ {
+ if (! (im = MIM.imextra[lang][extra]))
+ return null;
+ }
+ if (im.load_status != MIM.LoadStatus.Loaded
+ && (im.load_status != MIM.LoadStatus.NotLoaded || ! im.Load ()))
+ return null;
+ return im;
+ }
+
var parsers = { };
parsers['description'] = function (node)
}
parsers['macro-list'] = function (node)
{
- for (node = node.firstElement (); node; node = node.nextElement ())
- {
- if (node.nodeName == 'xi:include')
- {
- var im = include (node);
- if (! im)
- continue;
+ for (var n = node.firstElement (); n; n = n.nextElement ())
+ if (n.nodeName == 'xi:include')
+ {
+ var im = include (n);
+ if (! im)
+ alert ('inclusion fail');
+ else
for (var macro in im.domain.functions)
- im.domain.CopyFunc (this.domain, macro);
- }
- else
- Xex.Term.Parse (node);
- }
+ {
+ var func = im.domain.functions[macro];
+ if (func instanceof Xex.Macro)
+ im.domain.CopyFunc (this.domain, macro);
+ }
+ n = n.previousSibling;
+ node.removeChild (n.nextSibling);
+ }
+ Xex.Term.Parse (this.domain, node.firstElement (), null);
}
parsers['title'] = function (node)
{
}
parsers['map-list'] = function (node)
{
- for (node = node.firstChild; node; node = node.nextSibling)
+ for (node = node.firstElement (); node; node = node.nextElement ())
{
- if (node.nodeType != 1 || node.nodeName != 'map')
- continue;
- var map = Xex.Term.Parse (this.domain, node);
- this.map_list[map.name] = map;
+ if (node.nodeName == 'xi:include')
+ {
+ var im = include (node);
+ if (! im)
+ {
+ alert ('inclusion fail');
+ continue;
+ }
+ for (var mapname in im.map_list)
+ this.map_list[mapname] = im.map_list[mapname];
+ }
+ else
+ {
+ var map = Xex.Term.Parse (this.domain, node);
+ this.map_list[map.name] = map;
+ }
}
}
parsers['state-list'] = function (node)
{
this.domain.map_list = this.map_list;
- for (node = node.firstChild; node; node = node.nextSibling)
+ for (node = node.firstElement (); node; node = node.nextElement ())
{
- if (node.nodeType != 1 || node.nodeName != 'state')
- continue;
- var state = Xex.Term.Parse (this.domain, node);
- if (! state.title)
- state.title = this.title;
- if (! this.initial_state)
- this.initial_state = state;
- this.state_list[state.name] = state;
+ if (node.nodeName == 'state')
+ {
+ var state = Xex.Term.Parse (this.domain, node);
+ if (! state.title)
+ state.title = this.title;
+ if (! this.initial_state)
+ this.initial_state = state;
+ this.state_list[state.name] = state;
+ }
}
delete this.domain.map_list;
}
parser.call (this, node);
}
this.load_status = MIM.LoadStatus.Loaded;
+ MIM.log ('loading done: ' + this.lang + '-' + this.name + '-' + this.extra_id);
return true;
}
}
MIM.IM.prototype = proto;
- MIM.IC = function (im)
+ MIM.IC = function (im, target)
{
if (im.load_status == MIM.LoadStatus.NotLoaded)
im.Load ();
if (im.load_status != MIM.LoadStatus.Loaded)
alert ('im:' + im.name + ' error:' + im.load_status);
this.im = im;
+ this.target = target;
this.domain = new Xex.Domain ('context', im.domain, this);
this.active = true;
this.reset ();
Candidates.prototype.Select = function (selector)
{
- if (selector instanceof MIM.Selector)
+ if (selector.type == 'selector')
{
switch (selector.val)
{
}
if (end > this.total)
end = this.total;
- this.index += selector - col;
+ this.index += selector.val - col;
if (this.index >= end)
this.index = end - 1;
if (this.column > 0)
{
- if (selector > col)
+ if (selector.val > col)
while (this.blocks[this.row].Index + this.blocks[this.row].Count
< this.index)
this.row++;
del: function (pos)
{
+ var deleted = pos - this.cursor_pos;
if (pos < 0)
{
this.DelSurroundText (pos);
else
this.preedit = (this.preedit.substring (0, this.cursor_pos)
+ this.predit.substring (pos));
+ return deleted;
},
show: function ()
this.prev_state = this.state;
}
if (state != this.state && state.enter_actions)
- take_actions.call (state.enter_actions);
+ this.take_actions (state.enter_actions);
if (! this.state || this.state.title != state.title)
this.changed |= MIM.ChangedStatus.StateTitle;
this.state = state;
if (! ic || ic.im != MIM.current)
{
MIM.log ('creating IC');
- ic = new MIM.IC (MIM.current);
+ ic = new MIM.IC (MIM.current, target);
target.mim_ic = ic;
MIM.add_event_listener (target, 'blur', MIM.reset_ic);
}
MIM.test = function ()
{
var im = MIM.imlist['t']['latn-post'];
- var ic = new MIM.IC (im);
+ var ic = new MIM.IC (im, null);
ic.Filter (new MIM.Key ('a'));
ic.Filter (new MIM.Key ("'"));