From: handa Date: Sat, 12 Sep 2009 02:54:59 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=afe3801feabfee031ad8522d7758e94e8da949cf;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/Makefile b/Makefile index d4ffc59..71478bd 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ M17N_SRC = M17N.cs CORE_SRC = MSymbol.cs MPlist.cs MCharTable.cs MText.cs MDatabase.cs EXPR_SRC = MExpression.cs INPUT_SRC = MInputMethod.cs -DLL = M17N.dll M17NCore.dll M17NExpr.dll M17NIM.dll +XEX_SRC = XmlExpr.cs +DLL = M17N.dll M17NCore.dll M17NExpr.dll M17NIM.dll XmlExpr.dll EXAMPLE = symbol.exe plist.exe chartab.exe text.exe textprop.exe database.exe \ expr.exe TEST = rearsticky.exe frontsticky.exe bothsticky.exe \ @@ -28,12 +29,18 @@ M17NExpr.dll: M17N.dll M17NCore.dll ${EXPR_SRC} M17NIM.dll: ${INPUT_SRC} M17N.dll M17NCore.dll M17NExpr.dll $(RUNCS) -out:$@ -t:library -r:M17N.dll -r:M17NCore.dll -r:M17NExpr.dll ${INPUT_SRC} +XmlExpr.dll: ${XEX_SRC} + $(RUNCS) -out:$@ -t:library ${XEX_SRC} + input.exe: input.cs ${DLL} $(RUNCS) -r:M17N.dll -r:M17NCore -r:M17NExpr -r:M17NIM.dll $< expr.exe: expr.cs $(RUNCS) -r:M17N.dll -r:M17NCore -r:M17NExpr $< +xex.exe: xex.cs XmlExpr.dll + $(RUNCS) -r:XmlExpr.dll $< + %.exe: %.cs $(RUNCS) -r:M17N.dll -r:M17NCore $< diff --git a/XmlExpr.cs b/XmlExpr.cs index bfd48e7..4c42cbd 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -8,7 +8,7 @@ namespace System.Xml.Expression { public class Xex { - public struct Name + public struct Name : IEquatable { private static NameTable nt = new NameTable (); @@ -19,31 +19,11 @@ namespace System.Xml.Expression name = nt.Add (str); } - public Name (XmlAttribute attr) - { - name = nt.Add (attr.Value); - } - - public Name (XmlNode node) - { - name = node.Name; - } - public static implicit operator Name (string str) { return new Name (str); } - public static implicit operator Name (XmlAttribute attr) - { - return new Name (attr); - } - - public static implicit operator Name (XmlNode node) - { - return new Name (node); - } - public static implicit operator string (Name name) { return name.name; @@ -54,19 +34,14 @@ namespace System.Xml.Expression return (object) n1.name == (object) n2.name; } - public static bool operator== (Name n1, string n2) - { - return (object) n1.name == (object) n2; - } - - public static bool operator== (string n1, Name n2) + public static bool operator!= (Name n1, Name n2) { - return (object) n1 == (object) n2.name; + return (object) n1.name != (object) n2.name; } - public static bool operator!= (Name n1, Name n2) + public static bool operator== (Name n1, string n2) { - return (object) n1.name != (object) n2.name; + return (object) n1.name == (object) n2; } public static bool operator!= (Name n1, string n2) @@ -74,15 +49,20 @@ namespace System.Xml.Expression return (object) n1.name != (object) n2; } - public static bool operator!= (string n1, Name n2) - { - return (object) n1 != (object) n2.name; - } + public bool Equals (Name name) + { + Console.WriteLine ("Equals ({0}, {1})", this, name); + bool result = Object.ReferenceEquals (this.name, name.name); + Console.WriteLine (result); + return result; + } - public override bool Equals (object other) + public override bool Equals (object obj) { - Console.WriteLine ("Equals (object)"); - return Object.ReferenceEquals (this, other); + Console.WriteLine ("Equals ({0}, {1})", this, obj); + bool result = Object.ReferenceEquals (this.name, obj); + Console.WriteLine (result); + return result; } public override int GetHashCode () @@ -91,8 +71,13 @@ namespace System.Xml.Expression } public static NameTable Table { get { return nt; } } + + public override string ToString () { return name; } } + private static Name Nexpr = "expr"; + private static Name Nargs = "args"; + private static Name Ninteger = "integer"; private static Name Nstring = "string"; private static Name Nboolean = "boolean"; @@ -124,7 +109,7 @@ namespace System.Xml.Expression XmlNodeList body = node.ChildNodes; int idx = 0; - if (body[0].Name == "args") + if (Nargs == body[0].Name) { XmlNodeList args = body[0].ChildNodes; if (this.args == null) @@ -329,6 +314,7 @@ namespace System.Xml.Expression } } +#if false internal class ThrowException : Exception { Name tag; @@ -340,6 +326,7 @@ namespace System.Xml.Expression this.value = value; } } +#endif public class Domain { @@ -354,7 +341,10 @@ namespace System.Xml.Expression internal Domain () { } - public Domain (object context) : this (basic, context) { } + public Domain (object context) : this (basic, context) + { + Console.WriteLine (basic); + } public Domain (Domain parent, object context) { @@ -402,7 +392,7 @@ namespace System.Xml.Expression public void Defun (XmlNode node) { - Name name = node.Attributes["id"]; + Name name = node.Attributes["id"].Value; Function func; if (functions.TryGetValue (name, out func)) @@ -474,7 +464,9 @@ namespace System.Xml.Expression str += ") (variabls"; foreach (KeyValuePair kv in variables) str += " " + kv.Key; - str += " " + bindings; + str += ")"; + if (bindings != null) + str += " " + bindings; if (context != null) str += " (" + context + ")"; str += ">"; @@ -498,31 +490,56 @@ namespace System.Xml.Expression basic.Defun ("||", or, 1, -1, false); basic.Defun ("not", not, 1, 1, false); basic.Defun ("!", not, 1, 1, false); + basic.Defun ("add", add, 2, -1, false); basic.Defun ("+", add, 2, -1, false); + basic.Defun ("mul", mul, 2, -1, false); basic.Defun ("*", mul, 2, -1, false); + basic.Defun ("sub", sub, 1, -1, false); basic.Defun ("-", sub, 1, -1, false); + basic.Defun ("div", div, 2, -1, false); basic.Defun ("/", div, 2, -1, false); + basic.Defun ("mod", mod, 2, 2, false); basic.Defun ("%", mod, 2, 2, false); + basic.Defun ("logior", logior, 2, -1, false); basic.Defun ("|", logior, 2, -1, false); + basic.Defun ("logand", logand, 2, -1, false); basic.Defun ("&", logand, 2, -1, false); + basic.Defun ("add-set", add_set, 2, -1, true); basic.Defun ("+=", add_set, 2, -1, true); + basic.Defun ("mul-set", mul_set, 2, -1, true); basic.Defun ("*=", mul_set, 2, -1, true); + basic.Defun ("sub-set", sub_set, 2, -1, true); basic.Defun ("-=", sub_set, 2, -1, true); + basic.Defun ("div-set", div_set, 2, -1, true); basic.Defun ("/=", div_set, 2, -1, true); + basic.Defun ("mod-set", mod_set, 2, 2, true); basic.Defun ("%=", mod_set, 2, 2, true); + basic.Defun ("logior-set", logior_set, 2, -1, true); basic.Defun ("|=", logior_set, 2, -1, true); + basic.Defun ("logand-set", logand_set, 2, -1, true); basic.Defun ("&=", logand_set, 2, -1, true); + basic.Defun ("lsh", lsh, 2, 2, false); basic.Defun ("<<", lsh, 2, 2, false); + basic.Defun ("rsh", rsh, 2, 2, false); basic.Defun (">>", rsh, 2, 2, false); + basic.Defun ("lsh-set", lsh_set, 2, 2, true); basic.Defun ("<<=", lsh_set, 2, 2, true); + basic.Defun ("rsh-set", rsh_set, 2, 2, true); basic.Defun (">>=", rsh_set, 2, 2, true); + basic.Defun ("eq", eq, 2, -1, false); basic.Defun ("==", eq, 2, -1, false); + basic.Defun ("noteq", noteq, 2, 2, false); basic.Defun ("!=", noteq, 2, 2, false); + basic.Defun ("lt", less_than, 2, -1, false); basic.Defun ("<", less_than, 2, -1, false); + basic.Defun ("le", less_eq, 2, -1, false); basic.Defun ("<=", less_eq, 2, -1, false); + basic.Defun ("gt", greater_than, 2, -1, false); basic.Defun (">", greater_than, 2, -1, false); + basic.Defun ("ge", greater_eq, 2, -1, false); basic.Defun (">=", greater_eq, 2, -1, false); basic.Defun ("progn", progn_clause, 0, -1, true); + basic.Defun ("expr", progn_clause, 0, -1, true); basic.Defun ("if", if_clause, 2, -1, true); basic.Defun ("when", when_clause, 1, -1, true); basic.Defun ("while", while_clause, 1, -1, true); @@ -887,10 +904,7 @@ namespace System.Xml.Expression return xex; } - // EXPR = SYMBOL | MTEXT | INTEGER | FUNCALL | PROGN - // FUNCALL = '(' SYMBOL EXPR* ')' - // PROGN = '(' EXPR * ')' - public Xex (XmlNode node, Domain domain) + private void Setup (XmlNode node, Domain domain) { Name name = node.Name; @@ -959,6 +973,37 @@ namespace System.Xml.Expression } } + public Xex (string url, Domain domain) + { + XmlDocument doc = new XmlDocument (Name.Table); + XmlNode node; + + using (XmlTextReader reader = new XmlTextReader (url, Name.Table)) + { + do { + reader.Read (); + } while (reader.NodeType != XmlNodeType.None + && (reader.NodeType != XmlNodeType.Element + || (object) Nexpr != (object) reader.Name)); + if (reader.NodeType != XmlNodeType.None) + throw new Exception ("Node not found"); + Console.WriteLine (doc.ReadNode (reader).OuterXml); + node = doc.ReadNode (reader); + Console.WriteLine ("node read:" + node.OuterXml); + } + + Setup (node, domain); + } + + + // EXPR = SYMBOL | MTEXT | INTEGER | FUNCALL | PROGN + // FUNCALL = '(' SYMBOL EXPR* ')' + // PROGN = '(' EXPR * ')' + public Xex (XmlNode node, Domain domain) + { + Setup (node, domain); + } + private int parse_integer (string str) { int len = str.Length; diff --git a/xex.cs b/xex.cs new file mode 100644 index 0000000..8acfc5a --- /dev/null +++ b/xex.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using System.Xml.Expression; + +public class Test +{ + public static void Main() + { + Xex.Domain domain = new Xex.Domain (null); + Xex xex = new Xex ("xex.xml", domain); + + Console.WriteLine (xex); + Console.WriteLine (xex.Eval (domain)); + } +}