// -* 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",
{
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)
var vari = this.variables[name];
vari.val = values[name];
}
- },
-
- Trace: function () {}
+ }
};
Xex.Term = function (type) { this.type = type; }
{
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;
}
return new Xex.Varref (node.attributes['vname'].nodeValue);
}
+ proto.ToString = function ()
+ {
+ return '<varref vname="' + this.val + '"/>';
+ }
+
Xex.Varref.prototype = proto;
}) ();
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;
}
{
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 + '</' + this.func.name + '>';
+ return str + '>' + arglist + '</' + this.func.name + '>';
}
Xex.Funcall.prototype = proto;
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");
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);
}
{
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)
{
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;
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)
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;
}
}
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)
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)
{
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)
{
= 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)
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 ();
}
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);
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)
if (im && im != MIM.current)
{
MIM.current = im;
- MIM.log ('select IM: ' + im.name);
+ Xex.Log ('select IM: ' + im.name);
}
};
MIM.init_debug = function ()
{
MIM.debug = true;
+ Xex.LogNode = document.getElementById ('log');
MIM.init ();
};