From 50a3588238d0139dd3b73acb6d1dd927ec3ee9aa Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 25 Feb 2010 13:09:30 +0000 Subject: [PATCH] *** empty log message *** --- global.mimx | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xex.js | 469 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 860 insertions(+), 65 deletions(-) create mode 100644 global.mimx diff --git a/global.mimx b/global.mimx new file mode 100644 index 0000000..fcc5959 --- /dev/null +++ b/global.mimx @@ -0,0 +1,456 @@ + + + + t + nil + global + + + 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. + + + + + 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. + + 10 + + + + 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. + + nil + + + + + + Commit +Commit the preedit text + + + + Return + + + + + Linefeed + + + + + + Convert +Convert the preedit text + + + + ? + + + + + Henkan + + + + + + Revert +Revert the conversion + + + + Escape + + + + + + Previous candidate +Spot the previous candidate + + + + Left + + + + + C-B + + + + + + Next candidate +Spot the next candidate + + + + Right + + + + + C-F + + + + + ? + + + + + + First candidate +Spot the first candidate in the current group + + + + C-A + + + + + + Last candidate +Spot the last candidate in the current group + + + + C-E + + + + + + Previous candidate group +Move to the previous candidate group + + + + Up + + + + + C-P + + + + + + Next candidate group +Move to the next candidate group + + + + Down + + + + + C-N + + + + + + Select the 1st candidate +Select the first candidate in the current group + + + + ?1 + + + + + + Select the 2nd candidate +Select the second candidate in the current group + + + + ?2 + + + + + + Select the 3rd candidate +Select the third candidate in the current group + + + + ?3 + + + + + + Select the 4th candidate +Select the fourth candidate in the current group + + + + ?4 + + + + + + Select the 5th candidate +Select the fifth candidate in the current group + + + + ?5 + + + + + + Select the 6th candidate +Select the sixth candidate in the current group + + + + ?6 + + + + + + Select the 7th candidate +Select the seventh candidate in the current group + + + + ?7 + + + + + + select the 8th candidate +Select the eighth candidate in the current group + + + + ?8 + + + + + + Select the 9th candidate +Select the ninth candidate in the current group + + + + ?9 + + + + + + Select the 10th candidate +Select the tenth candidate in the current group + + + + ?0 + + + + + + Previous character +Move to the previous character in the preedit text + + + + Left + + + + + C-B + + + + + + Next character +Move to the next character in the preedit text + + + + Right + + + + + C-F + + + + + + Fist character +Move to the first character in the preedit text + + + + C-A + + + + + + Last character +Move to the last character in the preedit text + + + + C-E + + + + + + Delete char backward +Delete the previous character in the preedit text + + + + Backspace + + + + + + Delete char +Delete the following character in the preedit text + + + + Delete + + + + + + Previous segment +Move to the previous segment in the preedit text + + + + Left + + + + + C-B + + + + + + Next segment +Move to the next segment in the preedit text + + + + Right + + + + + C-F + + + + + + First segment +Move to the first segment in the preedit text + + + + C-A + + + + + + Last segment +Move to the last segment in the preedit text + + + + C-E + + + + + + Extend segment +Extend the current segment length to the tail + + + + S-Right + + + + + C-O + + + + + + Shrink segment +Shrink the current segment length from the tail + + + + S-Left + + + + + C-I + + + + + + 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. + + + + M-Return + + + + + diff --git a/xex.js b/xex.js index 5b07325..a86a5b2 100644 --- a/xex.js +++ b/xex.js @@ -37,29 +37,34 @@ Xex.Variable = function (domain, name, desc, val, range) 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; @@ -96,7 +101,6 @@ Xex.SpecialForm.prototype.Call = function (domain, vari, 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; @@ -150,7 +154,6 @@ Xex.Lambda.prototype.Call = function (domain, vari, 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; @@ -327,7 +330,7 @@ Xex.Domain.prototype = { 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, @@ -337,14 +340,14 @@ Xex.Domain.prototype = { { 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) @@ -385,7 +388,12 @@ Xex.Domain.prototype = { { 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) @@ -416,7 +424,11 @@ Xex.Term.prototype = { if (this.val != undefined) return '<' + this.type + '>' + this.val + ''; 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 () @@ -504,7 +516,7 @@ Node.prototype.nextElement = 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; @@ -530,7 +542,7 @@ Node.prototype.nextElement = function () if (node.nodeName == 'defun') domain.Defun (name, args, null); else - domain.Defmacor (name, args, null); + domain.Defmacro (name, args, null); return name; } @@ -543,7 +555,7 @@ Node.prototype.nextElement = function () 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) @@ -558,26 +570,31 @@ Node.prototype.nextElement = function () 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 @@ -633,7 +650,7 @@ Xex.Funcall = function (func, vari, args) 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']; @@ -736,6 +753,7 @@ Xex.IntTerm = function (num) { this.val = num; }; (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) @@ -753,6 +771,7 @@ Xex.StrTerm = function (str) { this.val = str; }; (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) @@ -838,13 +857,80 @@ Xex.LstTerm = function (list) { this.val = list; }; 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); } @@ -856,7 +942,7 @@ Xex.LstTerm = function (list) { this.val = list; }; var result = args[i].Eval (domain); if (domain.Thrown ()) return result; - if (! result.IsTrue) + if (! result.IsTrue ()) return Xex.Zero; } return Xex.One; @@ -884,6 +970,59 @@ Xex.LstTerm = function (list) { this.val = list; }; 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; @@ -1004,14 +1143,67 @@ Xex.LstTerm = function (list) { this.val = list; }; 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); @@ -1026,6 +1218,7 @@ Xex.LstTerm = function (list) { this.val = list; }; Xex.Zero = new Xex.IntTerm (0); Xex.One = new Xex.IntTerm (1); +Xex.nil = new Xex.SymTerm ('nil'); Xex.Load = function (server, file) { @@ -1034,7 +1227,6 @@ Xex.Load = function (server, file) obj.open ('GET', url, false); obj.overrideMimeType ('text/xml'); obj.send (''); - alert (file); return obj.responseXML.firstChild; } @@ -1235,7 +1427,7 @@ var MIM = { 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); } @@ -1517,10 +1709,10 @@ MIM.State = function (name) { 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') @@ -1567,6 +1759,35 @@ MIM.im_domain.DefType (MIM.State.prototype); 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; @@ -1581,10 +1802,73 @@ MIM.im_domain.DefType (MIM.State.prototype); 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); }) (); @@ -1596,6 +1880,40 @@ MIM.im_domain.DefType (MIM.State.prototype); 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) @@ -1621,19 +1939,23 @@ MIM.im_domain.DefType (MIM.State.prototype); } 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) { @@ -1641,27 +1963,40 @@ MIM.im_domain.DefType (MIM.State.prototype); } 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; } @@ -1699,19 +2034,21 @@ MIM.im_domain.DefType (MIM.State.prototype); 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 (); @@ -1983,7 +2320,7 @@ MIM.im_domain.DefType (MIM.State.prototype); Candidates.prototype.Select = function (selector) { - if (selector instanceof MIM.Selector) + if (selector.type == 'selector') { switch (selector.val) { @@ -2012,12 +2349,12 @@ MIM.im_domain.DefType (MIM.State.prototype); } 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++; @@ -2223,6 +2560,7 @@ MIM.im_domain.DefType (MIM.State.prototype); del: function (pos) { + var deleted = pos - this.cursor_pos; if (pos < 0) { this.DelSurroundText (pos); @@ -2239,6 +2577,7 @@ MIM.im_domain.DefType (MIM.State.prototype); else this.preedit = (this.preedit.substring (0, this.cursor_pos) + this.predit.substring (pos)); + return deleted; }, show: function () @@ -2339,7 +2678,7 @@ MIM.im_domain.DefType (MIM.State.prototype); 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; @@ -2622,7 +2961,7 @@ MIM.keydown = function (event) 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); } @@ -2727,7 +3066,7 @@ MIM.select_menu = function (event) 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 ("'")); -- 1.7.10.4