From: handa Date: Fri, 16 Oct 2009 06:55:47 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=d427804c042b6ad4a5952cfbd2850d1a10e57770;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MCharTable.cs b/MCharTable.cs index 1d9adc7..845b6ee 100644 --- a/MCharTable.cs +++ b/MCharTable.cs @@ -341,7 +341,7 @@ namespace M17N.Core return mst.ReadInteger (out to); } - private MCharTable load_char_table (MCharTable table) + private void load_char_table (MCharTable table) { MSymbol type = tag[1]; @@ -392,16 +392,15 @@ namespace M17N.Core mst.ForwardLine (); } } - return table; } - public object Load (MCharTable table) + public void Load (MCharTable table) { if (loader != null || Info.Format != Mchar_table) throw new ArgumentException ("Not a database of CharTable type"); if (! update_status ()) throw new Exception ("Database invalid"); - return load_char_table (table); + load_char_table (table); } } } diff --git a/MDatabase.cs b/MDatabase.cs index afefa61..6ac8291 100644 --- a/MDatabase.cs +++ b/MDatabase.cs @@ -240,7 +240,7 @@ namespace M17N.Core } } - public delegate object Loader (Tag tag, object extra_info); + public delegate MPlist Loader (Tag tag, object extra_info); internal class MDatabaseInfo { @@ -417,7 +417,6 @@ namespace M17N.Core }; public Tag tag; - public NameTable name_table = new NameTable (); private Loader loader; private object ExtraInfo; // Directory of the database file. @@ -990,24 +989,14 @@ namespace M17N.Core return stream; } - public object Load () + private NameTable name_table = new NameTable (); + + public MPlist Load () { if (loader != null) return loader (tag, ExtraInfo); - if (Info.Format == Mxml) - { - XmlDocument doc = new XmlDocument (name_table); - try { - XmlTextReader reader - = new XmlTextReader (FileInfo.FullName, name_table); - doc.Load (reader); - LastLoaded = DateTime.Now; - } catch (Exception e) { - Console.WriteLine (e); - LastLoadStatus = LoadStatus.InvalidContents; - } - return doc; - } + if (Info.Format != MSymbol.plist) + throw new Exception ("Not a plist database"); FileStream stream = get_stream (); if (stream == null) @@ -1024,6 +1013,21 @@ namespace M17N.Core return plist; } + public void Load (XmlDocument doc) + { + if (Info.Format == Mxml) + throw new Exception ("Not an XML database"); + try { + XmlTextReader reader + = new XmlTextReader (FileInfo.FullName, doc.NameTable); + doc.Load (reader); + LastLoaded = DateTime.Now; + } catch (Exception e) { + Console.WriteLine (e); + LastLoadStatus = LoadStatus.InvalidContents; + } + } + public object Load (MSymbol key, MSymbol stop) { FileStream stream = get_stream (); diff --git a/XmlExpr.cs b/XmlExpr.cs index ba26919..bcd05c9 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -91,6 +91,7 @@ namespace System.Xml.Expression private static Symbol Qlist = "list"; private static Symbol Qdefun = "defun"; + private static Symbol Qdefmacro = "defmacro"; private static Symbol Qfname = "fname"; private static Symbol Qargs = "args"; private static Symbol Qfixed = "fixed"; @@ -102,7 +103,7 @@ namespace System.Xml.Expression private static Symbol Qdescription = "description"; private static Symbol Qrange = "range"; - internal abstract class Function + public abstract class Function { public Symbol name; public int min_arg, max_arg; @@ -252,12 +253,7 @@ namespace System.Xml.Expression Term result = Zero; try { - int i; - Term[] newargs = new Term[args.Length]; - for (i = 0; i < min_arg; i++) - newargs[i] = args[i].Eval (domain); - args = newargs; - for (i = 0; i < min_arg; i++) + for (int i = 0; i < min_arg; i++) domain.Bind (this.args[i], args[i]); if (body != null) { @@ -1798,7 +1794,17 @@ namespace System.Xml.Expression if (domain.termtypes.TryGetValue (name, out term_type)) objval = term_type.parser (domain, node); else - objval = Funcall.parser (domain, node); + { + Funcall funcall = (Funcall) Funcall.parser (domain, node); + if (funcall.func is Function.Macro) + { + Term result = funcall.Eval (domain); + intval = result.intval; + objval = result.objval; + } + else + objval = funcall; + } } } } @@ -1821,7 +1827,15 @@ namespace System.Xml.Expression Function func = domain.GetFunc (fname); Variable vari = vname == Qnull ? null : domain.GetVar (vname, true); - objval = new Funcall (func, vari, args); + Funcall funcall = new Funcall (func, vari, args); + if (func is Function.Macro) + { + Term result = funcall.Eval (domain); + intval = result.intval; + objval = result.objval; + } + else + objval = funcall; } public object Objval { @@ -2000,6 +2014,8 @@ namespace System.Xml.Expression { if (n.Name == Qdefun) domain.Defun (n, true); + else if (n.Name == Qdefmacro) + domain.Defmacro (n, true); else if (n.Name == Qdefvar) domain.Defvar (n); else @@ -2012,6 +2028,8 @@ namespace System.Xml.Expression { if (n.Name == Qdefun) domain.Defun (n, false); + else if (n.Name == Qdefmacro) + domain.Defmacro (n, false); else if (n.Name != Qdefvar) terms[i++]= new Term (domain, n); } diff --git a/input.cs b/input.cs index 5b3cf20..735febc 100644 --- a/input.cs +++ b/input.cs @@ -14,8 +14,9 @@ public class Test { //M17n.debug = true; Xex.debug_level = 10; - MDatabase.ApplicationDir = "/usr/local/share/m17n"; + MDatabase.ApplicationDir = "/usr/local/share/m17n-xml"; MInputMethod im = MInputMethod.Find ("vi", "telex"); + Console.WriteLine (im); MInputMethod.Context ic = new MInputMethod.Context (im); MText str = args[0]; for (int i = 0; i < str.Length; i++) diff --git a/xex.xml b/xex.xml index 4db06fb..3566ba7 100644 --- a/xex.xml +++ b/xex.xml @@ -23,6 +23,14 @@ looptest-finished + + + + 10 + + + + 10 ABC @@ -58,5 +66,7 @@ ?a?b 1 + 100 + 5