From: handa Date: Sat, 27 Feb 2010 02:11:25 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~42 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=c5b053d3de19768369a237ac06a8d3d831d2d848;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.js b/xex.js index 3b54b3c..564a943 100644 --- a/xex.js +++ b/xex.js @@ -1,6 +1,17 @@ // -* coding: utf-8; -* -var Xex = {}; +var Xex = { + LogNode: null, + Log: function (indent, arg) + { + if (! Xex.LogNode) + return; + var str = ''; + for (var i = 0; i < indent; i++) + str += ' '; + Xex.LogNode.value = str + arg + "\n" + Xex.LogNode.value; + } +}; Xex.Error = { UnknownError: "unknown-error", @@ -388,12 +399,7 @@ Xex.Domain.prototype = { { values = {}; for (var elt in this.variables) - { - //if (! this.variables[elt].val) - //alert ('unknown value of ' + elt); - //else - values[elt] = this.variables[elt].val.Clone (); - } + values[elt] = this.variables[elt].val.Clone (); return values; }, RestoreValues: function (values) @@ -404,9 +410,7 @@ Xex.Domain.prototype = { var vari = this.variables[name]; vari.val = values[name]; } - }, - - Trace: function () {} + } }; Xex.Term = function (type) { this.type = type; } @@ -616,6 +620,7 @@ Xex.Varref = function (vname) { if (! this.vari || this.vari.domain != domain) this.vari = domain.GetVarCreate (this.val); + Xex.Log (domain.depth, this.ToString () + '=>' + this.vari.val); return this.vari.val; } @@ -624,6 +629,11 @@ Xex.Varref = function (vname) return new Xex.Varref (node.attributes['vname'].nodeValue); } + proto.ToString = function () + { + return ''; + } + Xex.Varref.prototype = proto; }) (); @@ -666,13 +676,12 @@ Xex.Funcall = function (func, vari, args) proto.Eval = function (domain) { - domain.Trace (this); - domain.depth++; + Xex.Log (domain.depth++, this); + var result; try { - var result = this.func.Call (domain, this.vari, this.args); + result = this.func.Call (domain, this.vari, this.args); } finally { - domain.depth--; - domain.Trace (' => ' + result + "\n"); + Xex.Log (--domain.depth, this + ' => ' + result); } return result; } @@ -694,11 +703,14 @@ Xex.Funcall = function (func, vari, args) { var arglist = '' var len = this.args.length; + var str = '<' + this.func.name; + if (this.vari) + str += ' vname="' + this.vari.name + '"'; if (len == 0) - return '<' + this.func.name + '/>'; + return str + '/>'; for (var i = 0; i < len; i++) arglist += this.args[i].toString (); - return '<' + this.func.name + '>' + arglist + ''; + return str + '>' + arglist + ''; } Xex.Funcall.prototype = proto; @@ -1146,8 +1158,6 @@ 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"); @@ -1428,10 +1438,8 @@ var MIM = { MIM.Marker.prototype.CharAt = function (ic) { var p = this.Position (ic); - if (p < 0) - return ic.GetSurroundingChar (p); - else if (p >= ic.preedit.length) - return ic.GetSurroundingChar (p - ic.preedit.length); + if (p < 0 || p >= ic.preedit.length) + return 0; return ic.preedit.charCodeAt (p); } @@ -1505,6 +1513,17 @@ var MIM = { { return ic.cursor_pos + this.distance; } + MIM.SurroundMarker.prototype.CharAt = function (ic) + { + if (this.name == '@-0') + return -1; + var p = this.Position (ic); + if (p < 0) + return ic.GetSurroundingChar (p); + else if (p >= ic.preedit.length) + return ic.GetSurroundingChar (p - ic.preedit.length); + return ic.preedit.charCodeAt (p); + } MIM.Marker.prototype.Parser = function (domain, node) { @@ -1959,13 +1978,6 @@ 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; @@ -2014,7 +2026,7 @@ MIM.im_domain.Trace = function (arg) function Fchar_at (domain, vari, args) { - return new Xex.Term (args[0].CharAt (domain.context)); + return new Xex.IntTerm (args[0].CharAt (domain.context)); } function Fmove (domain, vari, args) @@ -2374,37 +2386,36 @@ MIM.im_domain.Trace = function (arg) var sub = out.map; var branch_actions = this.state.keymap.actions; - this.domain.Trace ('handling ' + this.keys.val[this.key_head] - + ' in ' + this.state.name + ':' - + this.keymap.name + "\n"); + Xex.Log ('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; - this.domain.Trace ('submap found\n'); + Xex.Log ('submap found\n'); if (this.keymap.actions) { - this.domain.Trace ('taking map actions:\n'); + Xex.Log ('taking map actions:\n'); if (! this.take_actions (this.keymap.actions)) return false; } else if (this.keymap.submaps) { - MIM.log ('no map actions'); + Xex.Log ('no map actions'); for (var i = this.state_key_head; i < this.key_head; i++) { - MIM.log ('inserting key:' + this.keys.val[i].key); + Xex.Log ('inserting key:' + this.keys.val[i].key); this.insert (this.keys.val[i].key, null); } } if (! this.keymap.submaps) { - MIM.log ('terminal:'); + Xex.Log ('terminal:'); if (this.keymap.branch_actions != null) { - MIM.log ('branch actions:'); + Xex.Log ('branch actions:'); if (! this.take_actions (branch_actions)) return false; } @@ -2414,24 +2425,24 @@ MIM.im_domain.Trace = function (arg) } else { - MIM.log ('no submap'); + Xex.Log ('no submap'); var current_state = this.state; var map = this.keymap; if (branch_actions) { - MIM.log ('branch actions'); + Xex.Log ('branch actions'); if (! this.take_actions (this.keymap.branch_actions)) return false; } if (map == this.keymap) { - MIM.log ('no state change'); + Xex.Log ('no state change'); if (map == this.initial_state.keymap && this.key_head < this.keys.val.length) { - MIM.log ('unhandled'); + Xex.Log ('unhandled'); return false; } if (this.keymap != current_state.keymap) @@ -2493,9 +2504,10 @@ MIM.im_domain.Trace = function (arg) GetSurroundingChar: function (pos) { - if (pos < 0 ? this.caret_pos < - pos : this.target.value.length < pos) + pos += this.caret_pos; + if (pos < 0 || pos >= this.target.value.length) return 0; - return this.target.value.charCodeAt (this.caret_pos + pos); + return this.target.value.charCodeAt (pos); }, adjust_markers: function (from, to, inserted) @@ -2624,13 +2636,13 @@ MIM.im_domain.Trace = function (arg) { if (state == null) { - MIM.log ("shifting back to previous"); + Xex.Log ("shifting back to previous"); if (this.prev_state == null) return; state = this.prev_state; } else - MIM.log ("shifting to " + state.name); + Xex.Log ("shifting to " + state.name); if (state == this.initial_state) { @@ -2805,12 +2817,6 @@ MIM.add_event_listener = function (e) { listener.call (target, e || window.event); }; }); -MIM.log = function (msg) -{ - var node = document.getElementById ('log'); - node.value = msg + "\n" + node.value; -} - MIM.debug_print = function (event, ic) { if (! MIM.debug) @@ -2888,7 +2894,7 @@ MIM.set_caret = function (target, ic) if (range[0] != ic.spot || range[1] - range[0] != ic.preedit.length || target.value.substring (range[0], range[1]) != ic.preedit) { - MIM.log ('reset:' + ic.spot + '-' + (ic.spot + ic.preedit.length) + Xex.Log ('reset:' + ic.spot + '-' + (ic.spot + ic.preedit.length) + '/' + range[0] + '-' + range[1]); ic.reset (); } @@ -2930,7 +2936,7 @@ MIM.keydown = function (event) var ic = target.mim_ic; if (! ic || ic.im != MIM.current) { - MIM.log ('creating IC'); + Xex.Log ('creating IC'); ic = new MIM.IC (MIM.current, target); target.mim_ic = ic; MIM.add_event_listener (target, 'blur', MIM.reset_ic); @@ -2961,7 +2967,7 @@ MIM.keypress = function (event) return; } - MIM.log ("filtering " + ic.key); + Xex.Log ("filtering " + ic.key); var result = ic.Filter (ic.key); MIM.update (event.target, ic); if (! ic.key_unhandled) @@ -2991,7 +2997,7 @@ MIM.select_im = function (event) if (im && im != MIM.current) { MIM.current = im; - MIM.log ('select IM: ' + im.name); + Xex.Log ('select IM: ' + im.name); } }; @@ -3069,5 +3075,6 @@ MIM.init = function () MIM.init_debug = function () { MIM.debug = true; + Xex.LogNode = document.getElementById ('log'); MIM.init (); };