From: handa Date: Thu, 28 Jan 2010 12:30:27 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: load_sync~1 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66ec6cf2695620e68bd628f1099b6df8d5ee2e76;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/index.html b/index.html index 62462a4..794f865 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@ --> M17N Input Method by JavaScript + diff --git a/mim.js b/mim.js index 09d7587..25d59e4 100644 --- a/mim.js +++ b/mim.js @@ -74,6 +74,23 @@ MIM.im = function (lang, name, filename) 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) @@ -148,6 +165,7 @@ MIM.parse = function (im) 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; } @@ -204,42 +222,15 @@ MIM.load_sync = function (im) 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) diff --git a/xex.js b/xex.js new file mode 100644 index 0000000..91135b2 --- /dev/null +++ b/xex.js @@ -0,0 +1,180 @@ +// -* 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 (); + } + + diff --git a/xex.xml b/xex.xml new file mode 100644 index 0000000..bcadbbc --- /dev/null +++ b/xex.xml @@ -0,0 +1,5 @@ + + + + This is a test +