for (var keystring in mapdef)
add_keystring (this.keymap, keystring, mapdef[keystring]);
}
+
+ this.load_map_node = function ()
+ {
+ this.keymap = new Array ();
+ var maps = this.body.getElementsByTagName ('map');
+ var map = maps[0];
+ var rules = map.getElementsByTagName ('rule');
+ for (var i = 0; i < rules.length; i++)
+ {
+ var rule = rules[i];
+ var keyseq_elm = MIM.first_element (rule);
+ var keystring = keyseq_elm.attributes[0].nodeValue;
+ var insert_elm = MIM.next_element (rule);
+ var str = insert_elm.attributes[0].nodeValue;
+ add_keystring (this.keymap, keystring, str);
+ }
+ }
};
MIM.error_return = function (msg, ret)
for (var i = 0; i < states.length; i++)
if (! MIM.check_state (im, states[i]))
MIM.error_return ('Unsupported directive in state', false);
+ im.load_map_node ();
return true;
}
if (! obj)
alert ("XMLHttpRequest not supported");
- if (true)
- {
- obj.open ('GET', im.url, false);
- im.status = 1; /* loading */
+ obj.open ('GET', 'latn-post.mimx', false);
+ obj.overrideMimeType ('text/xml');
obj.send ("");
- try {
- eval (obj.responseText);
- im.status = 2; /* loaded */
- } catch (e) {
- alert ("load error:" + e.message + " at " + e.lineNumber
- + " " + obj.responseText);
- im.status = -1; /* load fail */
- };
- }
-
- if (true) {
- obj.open ('GET', 'latn-post.mimx', false);
- obj.overrideMimeType ('text/xml');
- obj.send ("");
- im.body = obj.responseXML;
- document.AnXml = im.body;
- if (! MIM.parse (im))
- {
- alert (im.parse_error);
- return false;
- }
- } else {
- var doc = document.implementation.createDocument ("", "", null);
- doc.async = false;
- doc.contentType = "text/xml";
- doc.load ('latn-post.mimx');
- document.AnXml = doc;
- im.body = doc;
- MIM.parse (im);
- }
- return im;
+ im.body = obj.responseXML;
+ document.AnXml = im.body;
+ if (MIM.parse (im))
+ return im;
+ alert (im.parse_error);
+ return false;
};
MIM.load = function (im)
--- /dev/null
+// -* coding: utf-8; -*
+
+var XEX = {};
+
+XEX.Variable = function (domain, name, val)
+{
+ this.domain = domain;
+ this.name = name;
+ this.val = val;
+}
+
+XEX.Variable.prototype = {
+ value: function () { return this.val; },
+ set_value: function (val) {
+ this.val = val;
+ return val;
+ },
+ clone: function () {
+ {
+ return new XEX.Variable (this.domain, this.name, this.value);
+ }
+ }
+}
+
+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) {
+ this.prototype = new XEX.Function (name, with_var, min_args, max_args);
+ this.builtin = builtin;
+};
+
+XEX.Subrountine.prototype.Call = function (domain, vari, args)
+{
+ newargs = new Array ();
+ for (var i = 0; i < args.length; i++)
+ {
+ newargs[i] = args[i].Eval (domain);
+ if (domain.Thrown ())
+ return newargs[i];
+ }
+ return this.builtin (domain, vari, newargs)
+}
+
+XEX.SpecialForm = function (builtin, name, with_var, min_args, max_args)
+{
+ this.prototype = new XEX.Function (name, with_var, min_args, max_args);
+ this.builtin = builtin;
+}
+
+XEX.SpecialForm.prototype.Call = function (domain, vari, args)
+{
+ return this.builtin (domain, vari, args)
+}
+
+XEX.Lambda = function (name, min_args, max_args, args, body)
+{
+ this.prototype = new XEX.Function (name, false, min_args, max_args);
+ this.args = args;
+ this.body = body;
+}
+
+XEX.Lambda.prototype.Call = function (domain, vari, args)
+{
+ var current = domain.bindings;
+ var result = XEX.Term.zero;
+ var limit = max_args >= 0 ? args.length : args.length - 1;
+ var i;
+
+ try {
+ for (i = 0; i < limit; i++)
+ {
+ result = args[i].Eval (domain);
+ if (domain.Thrown ())
+ return result;
+ domain.Bind (this.args[i], result);
+ }
+ if (max_args < 0)
+ {
+ var list = new Array ();
+ for (i = 0; i < args[limit].length; i++)
+ {
+ result = args[limit].Eval (domain);
+ if (domain.Thrown ())
+ return result;
+ list[i] = result;
+ }
+ domain.Bind (this.args[limit], list);
+ }
+ try {
+ domain.Catch (XEX.CatchTag.Return);
+ for (var term in this.body)
+ {
+ result = term.Eval (domain);
+ if (domain.Thrown ())
+ return result;
+ }
+ } finally {
+ domain.Uncatch ();
+ }
+ } finally {
+ domain.UnboundTo (current);
+ }
+ return result;
+}
+
+XEX.Macro = function (name, min_args, max_args, args, body)
+{
+ this.prototype = new XEX.Function (name, false, min_args, max_args);
+ this.args = args;
+ this.body = body;
+}
+
+XEX.Macro.prototype.Call = function (domain, vari, args)
+{
+ var current = domain.bindings;
+ var result = XEX.Term.Zero;
+ var i;
+
+ try {
+ for (i = 0; i < args.length; i++)
+ domain.Bind (this.args[i], args[i]);
+ try {
+ domain.Catch (XEX.CatchTag.Return);
+ for (var term in body)
+ {
+ result = term.Eval (domain);
+ if (domain.Thrown ())
+ break;
+ }
+ } finally {
+ domain.Uncatch ();
+ }
+ } finally {
+ domain.UnboundTo (current);
+ }
+ return result;
+}
+
+XEX.EvalConstant = function (domain)
+{
+ if (this.nodeName == 'integer')
+ alert ("integer:" + this.attributes[0].nodeValue);
+ else if (this.nodeName == 'string')
+ alert ("string:" + this.firstChild.nodeValue);
+ return this;
+};
+
+XEX.EvalFuncall = function (domain)
+{
+ try {
+ domain.CallStackPush (this);
+ } catch (e) {
+ alert (e);
+ }
+}
+
+var obj = new XMLHttpRequest ();
+obj.open ('GET', 'xex.xml', false);
+obj.send ('');
+var body = obj.responseXML.firstChild;
+for (var i = body.childNodes.length - 1; i >= 0 ; i--)
+ {
+ var node = body.childNodes[i];
+ if (node.nodeType == 1)
+ node.Eval = XEX.EvalConstant;
+ else
+ body.removeChild (node);
+ }
+for (var i = 0; i < body.childNodes.length; i++)
+ {
+ var node = body.childNodes[i];
+ node.Eval ();
+ }
+
+