From: handa Date: Sat, 27 Feb 2010 00:33:56 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~43 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=713a77c067f8074eefd184866e46d6eac8437f6e;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.js b/xex.js index 4fda842..3b54b3c 100644 --- a/xex.js +++ b/xex.js @@ -404,7 +404,9 @@ Xex.Domain.prototype = { var vari = this.variables[name]; vari.val = values[name]; } - } + }, + + Trace: function () {} }; Xex.Term = function (type) { this.type = type; } @@ -664,7 +666,15 @@ Xex.Funcall = function (func, vari, args) proto.Eval = function (domain) { - return this.func.Call (domain, this.vari, this.args); + domain.Trace (this); + domain.depth++; + try { + var result = this.func.Call (domain, this.vari, this.args); + } finally { + domain.depth--; + domain.Trace (' => ' + result + "\n"); + } + return result; } proto.Clone = function () @@ -1723,6 +1733,224 @@ MIM.State = function (name) MIM.State.prototype = proto; }) (); +(function () { + function Block (index, term) + { + this.Index = index; + if (term.IsStr) + this.Data = term.val; + else if (term.IsList) + { + this.Data = new Array (); + for (var i = 0; i < term.val.length; i++) + this.Data.push (term.val[i].val); + } + } + + Block.prototype.Count = function () { return this.Data.length; } + Block.prototype.get = function (i) + { + return (this.Data instanceof Array ? this.Data[i] : this.Data.charAt (i)); + } + + MIM.Candidates = function (candidates, column) + { + this.column = column; + this.row = 0; + this.index = 0; + this.total = 0; + this.blocks = new Array (); + + for (var i = 0; i < candidates.length; i++) + { + var block = new Block (this.total, candidates[i]); + this.blocks.push (block); + this.total += block.Count (); + } + } + + function get_col () + { + return (this.column > 0 ? this.index % this.column + : this.index - this.blocks[this.row].Index); + } + + function prev_group () + { + var col = get_col.call (this); + var nitems; + if (this.column > 0) + { + this.index -= this.column; + if (this.index >= 0) + nitems = this.column; + else + { + var lastcol = (this.total - 1) % this.column; + this.index = (col < lastcol ? this.total - lastcol + col + : this.total - 1); + this.row = this.blocks.length - 1; + nitems = lastcol + 1; + } + while (this.blocks[this.row].Index > this.index) + this.row--; + } + else + { + this.row = this.row > 0 ? this.row - 1 : this.blocks.length - 1; + nitems = this.blocks[this.row].Count (); + this.index = (this.blocks[this.row].Index + + (col < nitems ? col : nitems - 1)); + } + return nitems; + } + + function next_group () + { + var col = get_col.call (this); + var nitems; + if (this.column > 0) + { + this.index += this.column - col; + if (this.index < this.total) + { + if (this.index + col >= this.total) + { + nitems = this.total - this.index; + this.index = this.total - 1; + } + else + { + nitems = this.column; + this.index += col; + } + } + else + { + this.index = col; + this.row = 0; + } + while (this.blocks[this.row].Index > this.index) + this.row++; + } + else + { + this.row = this.row < this.blocks.length - 1 ? this.row + 1 : 0; + nitems = this.blocks[this.row].Count (); + this.index = (this.blocks[this.row].Index + + (col < nitems ? col : nitems - 1)); + } + return nitems; + } + + function prev () + { + if (this.index == 0) + { + this.index = this.total - 1; + this.row = this.blocks.length - 1; + } + else + { + this.index--; + if (this.blocks[this.row].Index > this.index) + this.row--; + } + } + + function next () + { + this.index++; + if (this.index == this.total) + { + this.index = 0; + this.row = 0; + } + else + { + var b = this.blocks[this.row]; + if (this.index == b.Index + b.Count ()) + this.row++; + } + } + + function first () + { + this.index -= get_col.call (this); + while (this.blocks[this.row].Index > this.index) + this.row--; + } + + function last () + { + var b = this.blocks[this.row]; + if (this.column > 0) + { + if (this.index + 1 < this.total) + { + this.index += this.column - get_col.call (this) + 1; + while (b.Index + b.Count () <= this.index) + b = this.blocks[++this.row]; + } + } + else + this.index = b.Index + b.Count () - 1; + } + + MIM.Candidates.prototype.Current = function () + { + var b = this.blocks[this.row]; + return b.get (this.index - b.Index); + } + + MIM.Candidates.prototype.Select = function (selector) + { + if (selector.type == 'selector') + { + switch (selector.val) + { + case '@<': first.call (this); break; + case '@>': last.call (this); break; + case '@-': prev.call (this); break; + case '@+': next.call (this); break; + case '@[': prev_group.call (this); break; + case '@]': next_group.cal (this); break; + default: break; + } + return this.Current (); + } + var col, start, end + if (this.column > 0) + { + col = this.index % this.column; + start = this.index - col; + end = start + this.column; + } + else + { + start = this.blocks[this.row].Index; + col = this.index - start; + end = start + this.blocks[this.row].Count; + } + if (end > this.total) + end = this.total; + this.index += selector.val - col; + if (this.index >= end) + this.index = end - 1; + if (this.column > 0) + { + if (selector.val > col) + while (this.blocks[this.row].Index + this.blocks[this.row].Count + < this.index) + this.row++; + else + while (this.blocks[this.row].Index > this.index) + this.row--; + } + return this.Current (); + } +}) (); + MIM.im_domain = new Xex.Domain ('input-method', null, null); MIM.im_domain.DefType (MIM.KeySeq.prototype); MIM.im_domain.DefType (MIM.Marker.prototype); @@ -1731,6 +1959,13 @@ MIM.im_domain.DefType (MIM.Rule.prototype); MIM.im_domain.DefType (MIM.Map.prototype); MIM.im_domain.DefType (MIM.State.prototype); +MIM.im_domain.Trace = function (arg) +{ + var node = document.getElementById ('log'); + if (node) + node.value = "" + arg + node.value; +}; + (function () { var im_domain = MIM.im_domain; @@ -2099,265 +2334,6 @@ MIM.im_domain.DefType (MIM.State.prototype); this.table.length = 0; } - function Block (index, term) - { - this.Index = index; - if (term.IsStr) - this.Data = term.val; - else if (term.IsList) - { - this.Data = new Array (); - for (var i = 0; i < term.val.length; i++) - this.Data.push (term.val[i].val); - } - } - - Block.prototype.Count = function () { return this.Data.length; } - Block.prototype.get = function (i) - { - return (this.Data instanceof Array ? this.Data[i] : this.Data.charAt (i)); - } - - function fill_group (start) - { - var nitems = this.group.length; - var r = this.row; - var b = this.blocks[r]; - - if (start < b.Index) - while (start < b.Index) - b = this.blocks[--r]; - else - while (start >= b.Index + b.Count ()) - b = this.blocks[++r]; - this.row = r; - - var count = b.Count (); - start -= b.Index; - for (var i = 0; i < nitems; i++, start++) - { - if (start >= count) - { - r++; - if (r == this.blocks.Length) - return i; - b = this.blocks[r]; - count = b.Count (); - start = 0; - } - this.group[i] = b.get (start); - } - return nitems; - } - - function Candidates (candidates, column) - { - this.column = column; - this.row = 0; - this.index = 0; - this.total = 0; - this.blocks = new Array (); - - for (var i = 0; i < candidates.length; i++) - { - var block = new Block (this.total, candidates[i]); - this.blocks.push (block); - this.total += block.Count (); - } - } - - Candidates.prototype.Column = function () - { - return (this.column > 0 ? this.index % this.column - : this.index - this.blocks[this.row].Index); - } - - Candidates.prototype.GroupLength = function () - { - if (this.column > 0) - { - var start = this.index - (this.index % this.column); - return (start + this.column <= this.total ? this.column - : this.total - start); - } - return this.blocks[this.row].Count; - } - - Candidates.prototype.Current = function () - { - var b = this.blocks[this.row]; - return b.get (this.index - b.Index); - } - - Candidates.prototype.PrevGroup = function () - { - var col = this.Column (); - var nitems; - if (this.column > 0) - { - this.index -= this.column; - if (this.index >= 0) - nitems = this.column; - else - { - var lastcol = (this.total - 1) % this.column; - this.index = (col < lastcol ? this.total - lastcol + col - : this.total - 1); - this.row = this.blocks.length - 1; - nitems = lastcol + 1; - } - while (this.blocks[this.row].Index > this.index) - this.row--; - } - else - { - this.row = this.row > 0 ? this.row - 1 : this.blocks.length - 1; - nitems = this.blocks[this.row].Count (); - this.index = (this.blocks[this.row].Index - + (col < nitems ? col : nitems - 1)); - } - return nitems; - } - - Candidates.prototype.NextGroup = function () - { - var col = this.Column (); - var nitems; - if (this.column > 0) - { - this.index += this.column - col; - if (this.index < this.total) - { - if (this.index + col >= this.total) - { - nitems = this.total - this.index; - this.index = this.total - 1; - } - else - { - nitems = this.column; - this.index += col; - } - } - else - { - this.index = col; - this.row = 0; - } - while (this.blocks[this.row].Index > this.index) - this.row++; - } - else - { - this.row = this.row < this.blocks.length - 1 ? this.row + 1 : 0; - nitems = this.blocks[this.row].Count (); - this.index = (this.blocks[this.row].Index - + (col < nitems ? col : nitems - 1)); - } - return nitems; - } - - Candidates.prototype.Prev = function () - { - if (this.index == 0) - { - this.index = this.total - 1; - this.row = this.blocks.length - 1; - } - else - { - this.index--; - if (this.blocks[this.row].Index > this.index) - this.row--; - } - } - - Candidates.prototype.Next = function () - { - this.index++; - if (this.index == this.total) - { - this.index = 0; - this.row = 0; - } - else - { - var b = this.blocks[this.row]; - if (this.index == b.Index + b.Count ()) - this.row++; - } - } - - Candidates.prototype.First = function () - { - this.index -= this.Column (); - while (this.blocks[this.row].Index > this.index) - this.row--; - } - - Candidates.prototype.Last = function () - { - var b = this.blocks[this.row]; - if (this.column > 0) - { - if (this.index + 1 < this.total) - { - this.index += this.column - this.Column () + 1; - while (b.Index + b.Count () <= this.index) - b = this.blocks[++this.row]; - } - } - else - this.index = b.Index + b.Count () - 1; - } - - Candidates.prototype.Select = function (selector) - { - if (selector.type == 'selector') - { - switch (selector.val) - { - case '@<': this.First (); break; - case '@>': this.Last (); break; - case '@-': this.Prev (); break; - case '@+': this.Next (); break; - case '@[': this.PrevGroup (); break; - case '@]': this.NextGroup (); break; - default: break; - } - return this.Current (); - } - var col, start, end - if (this.column > 0) - { - col = this.index % this.column; - start = this.index - col; - end = start + this.column; - } - else - { - start = this.blocks[this.row].Index; - col = this.index - start; - end = start + this.blocks[this.row].Count; - } - if (end > this.total) - end = this.total; - this.index += selector.val - col; - if (this.index >= end) - this.index = end - 1; - if (this.column > 0) - { - if (selector.val > col) - while (this.blocks[this.row].Index + this.blocks[this.row].Count - < this.index) - this.row++; - else - while (this.blocks[this.row].Index > this.index) - this.row--; - } - return this.Current (); - } - function detach_candidates (ic) { ic.candidate_table.clear (); @@ -2398,18 +2374,19 @@ MIM.im_domain.DefType (MIM.State.prototype); var sub = out.map; var branch_actions = this.state.keymap.actions; - MIM.log ('handling ' + this.keys.val[this.key_head] - + ' in ' + this.state.name + ':' + this.keymap.name); + this.domain.Trace ('handling ' + this.keys.val[this.key_head] + + ' in ' + this.state.name + ':' + + this.keymap.name + "\n"); this.key_head = out.index; if (sub != this.keymap) { restore_state.call (this); this.keymap = sub; - MIM.log ('submap found'); + this.domain.Trace ('submap found\n'); if (this.keymap.actions) { - MIM.log ('taking map actions:'); + this.domain.Trace ('taking map actions:\n'); if (! this.take_actions (this.keymap.actions)) return false; }