From: handa Date: Tue, 10 Nov 2009 02:19:12 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=7e9120e82093e8c321f5cfdf05fcbfbd51cb0adc;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MDatabase.cs b/MDatabase.cs index 01d5755..bf232e4 100644 --- a/MDatabase.cs +++ b/MDatabase.cs @@ -256,6 +256,7 @@ namespace M17N.Core public MDatabaseInfo () { + Description = null; Format = Schema = MSymbol.nil; } @@ -275,9 +276,8 @@ namespace M17N.Core return ((major << 16) | (minor << 8) | release); } - public MDatabaseInfo (MPlist plist) + public MDatabaseInfo (MPlist plist) : this () { - Format = MSymbol.nil; if (plist.IsMText) { Format = MSymbol.plist; diff --git a/MInputMethod.cs b/MInputMethod.cs index 8b2e7f8..c27af0a 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -1030,7 +1030,7 @@ namespace M17N.Input private static Xex.Symbol name = "selector"; public static Xex.Symbol Name { get { return name; } } - static new Dictionary selectors; + static Dictionary selectors; static Selector () { diff --git a/MText.cs b/MText.cs index b281808..14a0696 100644 --- a/MText.cs +++ b/MText.cs @@ -115,7 +115,7 @@ namespace M17N.Core private int cache_idx; private MPlist intervals; private MPlist default_property; - private bool read_only; + private bool read_only = false; private static UTF8Encoding utf8 = new UTF8Encoding (); diff --git a/Makefile b/Makefile index e0f22ef..ccf25d3 100644 --- a/Makefile +++ b/Makefile @@ -29,16 +29,16 @@ XmlExpr.dll: ${XEX_SRC} $(RUNCS) -out:$@ -t:library ${XEX_SRC} input.exe: input.cs M17NIM.dll XmlExpr.dll - $(RUNCS) -r:M17N.dll -r:M17NCore -r:XmlExpr -r:M17NIM.dll $< + $(RUNCS) -r:M17N.dll -r:M17NCore.dll -r:XmlExpr.dll -r:M17NIM.dll $< expr.exe: expr.cs - $(RUNCS) -r:M17N.dll -r:M17NCore -r:M17NExpr $< + $(RUNCS) -r:M17N.dll -r:M17NCore.dll -r:M17NExpr.dll $< xex.exe: xex.cs XmlExpr.dll $(RUNCS) -r:XmlExpr.dll $< %.exe: %.cs ${DLL} - $(RUNCS) -r:M17N.dll -r:M17NCore $< + $(RUNCS) -r:M17N.dll -r:M17NCore.dll $< clean: rm -f $(DLL) *.exe diff --git a/XmlExpr.cs b/XmlExpr.cs index 41501be..4d2f76b 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -971,7 +971,7 @@ namespace System.Xml domain.functions[kv.Key] = kv.Value; } - public Variable GetVar (Symbol name) + public Variable GetVarCreate (Symbol name) { Variable vari; @@ -980,6 +980,15 @@ namespace System.Xml return vari; } + public Variable GetVar (Symbol name) + { + Variable vari; + + if (! variables.TryGetValue (name, out vari)) + return null; + return vari; + } + public override string ToString () { string str = "<(functions"; @@ -1633,7 +1642,7 @@ namespace System.Xml public virtual bool Matches (TermValue other) { return Equals (other); } public override abstract bool Equals (object obj); public override abstract int GetHashCode (); - public abstract string ToString (bool detail); + public virtual string ToString (bool detail) { return ToString (); } } private class Varref : TermValue @@ -1649,7 +1658,7 @@ namespace System.Xml public override Term Eval (Domain domain) { if (vari == null || vari.domain != domain) - vari = domain.GetVar (vname); + vari = domain.GetVarCreate (vname); return vari.Value; } @@ -1681,6 +1690,7 @@ namespace System.Xml { private static Symbol name = "funcall"; public static Symbol Name { get { return name; } } + private static Term[] null_args = new Term[0]; internal Function func; internal Variable vari; @@ -1688,8 +1698,9 @@ namespace System.Xml public Funcall (Function func, Variable vari, Term[] args) { + if (args == null) + args = null_args; int nargs = args.Length; - if (nargs < func.min_args || (func.max_args >= 0 && nargs > func.max_args)) throw new Error (Error.WrongArgument, @@ -1714,7 +1725,7 @@ namespace System.Xml Function func = domain.GetFunc (fname); Variable vari; attr = node.Attributes[Qvname]; - vari = attr == null ? null : domain.GetVar (attr.Value); + vari = attr == null ? null : domain.GetVarCreate (attr.Value); XmlNodeList nlist = node.ChildNodes; int nargs = nlist.Count; Term[] args = new Term[nargs]; @@ -1957,7 +1968,7 @@ namespace System.Xml intval = 0; Function func = domain.GetFunc (fname); - Variable vari = vname == Qnull ? null : domain.GetVar (vname); + Variable vari = vname == Qnull ? null : domain.GetVarCreate(vname); Funcall funcall = new Funcall (func, vari, args); if (func is Function.Macro) { @@ -2472,6 +2483,11 @@ namespace System.Xml return Parse (domain, node.FirstChild, null); } + public static Term Eval (Domain domain, Term term) + { + return Eval (domain, new Term[] { term }); + } + public static Term Eval (Domain domain, Term[] terms) { Term result = Zero; diff --git a/mtext.cs b/mtext.cs deleted file mode 100644 index bc8dad5..0000000 --- a/mtext.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using M17N.Core; - -public class Test -{ - public static void Main() - { - String str = "a𝄀あc"; - MText mt = new MText (str), mt2; - - Console.WriteLine (str + mt); - Console.WriteLine (mt + str); - Console.WriteLine (mt + 'a'); - mt2 = mt.Dup (); - mt2 += str; - Console.WriteLine (mt2); - - Console.WriteLine ("{0}, Length={1}", mt, mt.Length); - foreach (int c in mt) - Console.WriteLine ("U+{0:X4}", c); - Console.WriteLine (mt + new MText ("漢字")); - Console.WriteLine (mt[2,4]); - mt[0] = '日'; // == mt.Del (0, 1); mt.Ins (0, char) - Console.WriteLine (mt); - mt[1,3] = new MText ('本'); // == mt.Del (1, 3); mt.Ins (1, mt) - Console.WriteLine (mt); - mt[1,2] = null; // == mt.Del (1, 2) - Console.WriteLine (mt); - // explicit casting (MText -> string) - string str2 = " " + (string) mt + (string) ((MText) "abc").Cat ('a'); - Console.WriteLine (str2); - // implicit casting (string -> MText) - mt2 = "abc"; - mt2.Cat ("def"); - mt2 += "ghi"; - Console.WriteLine (mt2); - } -} diff --git a/text.cs b/text.cs index 5610dbd..bc8dad5 100644 --- a/text.cs +++ b/text.cs @@ -20,5 +20,20 @@ public class Test foreach (int c in mt) Console.WriteLine ("U+{0:X4}", c); Console.WriteLine (mt + new MText ("漢字")); + Console.WriteLine (mt[2,4]); + mt[0] = '日'; // == mt.Del (0, 1); mt.Ins (0, char) + Console.WriteLine (mt); + mt[1,3] = new MText ('本'); // == mt.Del (1, 3); mt.Ins (1, mt) + Console.WriteLine (mt); + mt[1,2] = null; // == mt.Del (1, 2) + Console.WriteLine (mt); + // explicit casting (MText -> string) + string str2 = " " + (string) mt + (string) ((MText) "abc").Cat ('a'); + Console.WriteLine (str2); + // implicit casting (string -> MText) + mt2 = "abc"; + mt2.Cat ("def"); + mt2 += "ghi"; + Console.WriteLine (mt2); } }