From: handa Date: Fri, 24 Jul 2009 13:12:14 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f6fd905d8745bc38a6e814f28f227b22de95fa0;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MCharset.cs b/MCharset.cs new file mode 100644 index 0000000..8963a6d --- /dev/null +++ b/MCharset.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.IO; +using M17N; +using M17N.Core; + +namespace M17N.Core +{ + public class MCharset + { + } + + public partial class MDatabase : IComparable + { + + + + } +} diff --git a/MExpression.cs b/MExpression.cs index ccc4878..959ea1d 100644 --- a/MExpression.cs +++ b/MExpression.cs @@ -11,26 +11,26 @@ namespace M17N.Core { public delegate object Evaluator (object[] args, MPlist bindings); - internal delegate void PrettyPrinter (MFunction func, - string indent, object[] args); + internal delegate void PrettyPrinter (Function func, + string indent, object[] args); - internal class MFunction + internal class Function { - internal MSymbol name; + internal readonly MSymbol name; internal readonly Evaluator eval; - internal int min_arg; - internal int max_arg; - internal Type[] arg_types; + internal readonly int min_arg; + internal readonly int max_arg; + internal readonly Type[] arg_types; internal object[] data; public PrettyPrinter pp; private static PrettyPrinter default_pretty_printer; private static PrettyPrinter set_pretty_printer; - internal static MFunction literal, varref, block, defun; + internal static Function literal, varref, block, defun; - public MFunction (MSymbol name, Evaluator eval, - int min_arg, int max_arg, params Type[] arg_types) + public Function (MSymbol name, Evaluator eval, + int min_arg, int max_arg, params Type[] arg_types) { this.name = name; this.eval = eval; @@ -43,7 +43,7 @@ namespace M17N.Core pp = default_pretty_printer; } - static MFunction () + static Function () { default_pretty_printer = new PrettyPrinter (default_pp); set_pretty_printer = new PrettyPrinter (set_pp); @@ -133,7 +133,7 @@ namespace M17N.Core // Commonly used pretty-printers. - public static void default_pp (MFunction func, + public static void default_pp (Function func, string indent, object[] args) { Console.Write ("(" + func.name); @@ -146,7 +146,7 @@ namespace M17N.Core Console.Write (")"); } - private static void set_pp (MFunction func, string indent, object[] args) + private static void set_pp (Function func, string indent, object[] args) { Console.Write ("(" + func.name + " " + (MSymbol) args[0] + " "); ((MExpression) args[1]).pp (indent); @@ -424,7 +424,7 @@ namespace M17N.Core return result; } - private static void block_pp (MFunction func, + private static void block_pp (Function func, string indent, object[] args) { bool first = true; @@ -442,19 +442,27 @@ namespace M17N.Core Console.Write (")"); } + private static bool check_condition (MExpression e, MPlist bindings) + { + object result = e.Eval (bindings); + return (! (result is int) || (int) result != 0); + } + private static object cond (object[] args, MPlist bindings) { foreach (MExpression[] elist in args) - { - int i = (int) elist[0].Eval (bindings); - if (i != 0) - return progn ((object[]) elist, bindings); - } + if (check_condition (elist[0], bindings)) + { + object result = 0; + for (int i = 1; i < elist.Length; i++) + result = elist[i].Eval (bindings); + return result; + } return 0; } - private static void cond_pp (MFunction func, - string indent, object[] args) + private static void cond_pp (Function func, + string indent, object[] args) { Console.Write ("(cond"); indent += " "; @@ -479,7 +487,7 @@ namespace M17N.Core { object result = 0; - if ((int) ((MExpression) args[0]).Eval (bindings) != 0) + if (check_condition ((MExpression) args[0], bindings)) result = ((MExpression) args[1]).Eval (bindings); else for (int i = 2; i < args.Length; i++) @@ -487,39 +495,33 @@ namespace M17N.Core return result; } - private static void if_pp (MFunction func, + private static void if_pp (Function func, string indent, object[] args) { Console.Write ("(if "); ((MExpression) args[0]).pp (indent + " "); Console.Write ("\n" + indent + " "); ((MExpression) args[1]).pp (indent + " "); - bool first = true; indent += " "; for (int i = 2; i < args.Length; i++) { - if (first) - { - Console.Write ("\n" + indent); - first = false; - } - else - Console.Write (" "); + Console.Write ("\n" + indent); ((MExpression) args[i]).pp (indent); } + Console.Write (")"); } private static object whileclause (object[] args, MPlist bindings) { object result = 0; - while ((int) ((MExpression) args[0]).Eval (bindings) != 0) + while (check_condition ((MExpression) args[0], bindings)) for (int i = 1; i < args.Length; i++) result = ((MExpression) args[i]).Eval (bindings); return result; } - private static void while_pp (MFunction func, + private static void while_pp (Function func, string indent, object[] args) { Console.Write ("(while "); @@ -537,6 +539,7 @@ namespace M17N.Core Console.Write (" "); ((MExpression) args[i]).pp (indent); } + Console.Write (")"); } private static object define_function (object[] args, MPlist bindings) @@ -551,14 +554,14 @@ namespace M17N.Core for (int i = 3; i < args.Length; i++) data[i - 2] = args[i]; - MFunction func = new MFunction (sym, null, nargs, nargs, - typeof (MExpression)); + Function func = new Function (sym, null, nargs, nargs, + typeof (MExpression)); table.table[sym] = func; func.data = data; return null; } - private static void defun_pp (MFunction func, + private static void defun_pp (Function func, string indent, object[] args) { Console.Write ("(defun " + args[1] + " " + args[2]); @@ -575,13 +578,14 @@ namespace M17N.Core Console.Write (" "); ((MExpression) args[i]).pp (indent); } + Console.Write (")"); } } public class FunctionTable { - internal Dictionary table - = new Dictionary (); + internal Dictionary table + = new Dictionary (); } private static FunctionTable basic_table = new FunctionTable (); @@ -590,34 +594,34 @@ namespace M17N.Core Evaluator evaluator, int min_arg, int max_arg, params Type[] arg_types) { - MFunction func = Defun (name, evaluator, min_arg, max_arg, arg_types); + Function func = Defun (name, evaluator, min_arg, max_arg, arg_types); table.table[func.name] = func; } - private static MFunction Defun (string name, Evaluator evaluator, - int min_arg, int max_arg, - params Type[] arg_types) + private static Function Defun (string name, Evaluator evaluator, + int min_arg, int max_arg, + params Type[] arg_types) { MSymbol sym = MSymbol.Of (name); - MFunction func = new MFunction (sym, evaluator, min_arg, max_arg, + Function func = new Function (sym, evaluator, min_arg, max_arg, arg_types); basic_table.table[sym] = func; return func; } - private static MFunction Defun (string name, Evaluator evaluator, + private static Function Defun (string name, Evaluator evaluator, int min_arg, int max_arg) { return Defun (name, evaluator, min_arg, max_arg, typeof (MExpression)); } - private static MFunction Find (MSymbol name, FunctionTable table) + private static Function Find (MSymbol name, FunctionTable table) { if (name == MSymbol.integer || name == MSymbol.mtext) - return MFunction.literal; + return Function.literal; - MFunction func; + Function func; if ((table == null || ! table.table.TryGetValue (name, out func)) && ! basic_table.table.TryGetValue (name, out func)) @@ -632,10 +636,11 @@ namespace M17N.Core private void invalid_argument (object o) { - throw new Exception ("Invalid argument: " + o); + throw new Exception (String.Format ("Invalid argument to {0}: {1}", + function.name, o)); } - private MFunction function; + private Function function; private object[] args; public MExpression (MSymbol function_name, object[] args, @@ -645,7 +650,7 @@ namespace M17N.Core int nargs = args.Length; if (nargs < function.min_arg || (function.max_arg >= 0 && nargs > function.max_arg)) - throw new Exception ("Invalid number of arguments: " + args); + throw new Exception (String.Format ("Invalid number of arguments to {0}: {1}", function.name, nargs)); this.args = (object[]) args.Clone (); } @@ -681,7 +686,7 @@ namespace M17N.Core // EXPRLIST: PLIST = EXPR ... public MExpression (MPlist plist, FunctionTable table) { - function = MFunction.block; + function = Function.block; args = expression_list (plist, table); } @@ -695,7 +700,9 @@ namespace M17N.Core int nargs = arg_list.Count; if (nargs < function.min_arg || (function.max_arg >= 0 && nargs > function.max_arg)) - throw new Exception ("Invalid number of arguments: " + nargs); + throw new Exception (String.Format + ("Invalid number of arguments to {0}: {1}", + function.name, nargs)); int i = 0; Type arg_type = typeof (MExpression); @@ -750,20 +757,20 @@ namespace M17N.Core else args[i++] = p.val; } - if (function == MFunction.defun) + if (function == Function.defun) function.Call (args, null); } public MExpression (MSymbol sym) { - function = MFunction.varref; + function = Function.varref; args = new object[1]; args[0] = sym; } public MExpression (object obj) { - function = MFunction.literal; + function = Function.literal; args = new object[1]; args[0] = obj; } @@ -775,8 +782,8 @@ namespace M17N.Core private void pp (string indent) { - if (function == MFunction.varref - || function == MFunction.literal) + if (function == Function.varref + || function == Function.literal) { if (args[0] is MText) Console.Write ("\"{0}\"", args[0]); diff --git a/MInputMethod.cs b/MInputMethod.cs new file mode 100644 index 0000000..cfd6d7f --- /dev/null +++ b/MInputMethod.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using M17N; +using M17N.Core; +using M17N.Input; + +namespace M17N.Input +{ + public class MInputMethod + { + private class MInputAction + { + MExpression[] expr_list; + } + + private class MInputMethodMap + { + public MSymbol name; + private MSymbol[] keys; + private MInputAction[] actions; + } + + private class MInputMethodBranch + { + public MSymbol name; + private MInputAction[] actions; + } + + private class MInputMethodState + { + public MText title; + public MSymbol name; + public MInputMethodBranch[] branches; + } + + public readonly MSymbol language; + public readonly MSymbol name; + public readonly MSymbol subname; + + private MDatabase mdb; + private MText description; + private MText title; + private MPlist commands; + private MPlist variables; + private MPlist maps; + private MPlist states; + private MPlist macros; + private MPlist externals; + + public MInputMethod (MSymbol language, MSymbol name, MSymbol extra) + { + MDatabase.Tag tag = new MDatabase.Tag (language, name, extra); + + mdb = MDatabase.Find (tag); + if (mdb == null) + throw new Exception (String.Format ("Input method {0} not available", + tag)); + MPlist plist = (MPlist) mdb.Load (); + } + } +} diff --git a/Makefile b/Makefile index 4a039fe..8185c20 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,13 @@ CS=gmcs M17N_SRC = M17N.cs CORE_SRC = MSymbol.cs MPlist.cs MCharTable.cs MText.cs MDatabase.cs EXPR_SRC = MExpression.cs -EXAMPLE = symbol.exe plist.exe chartab.exe text.exe textprop.exe database.exe +DLL = M17N.dll M17NCore.dll M17NExpr.dll +EXAMPLE = symbol.exe plist.exe chartab.exe text.exe textprop.exe database.exe \ + expr.exe TEST = rearsticky.exe frontsticky.exe bothsticky.exe \ sensitive.exe frontsensitive.exe rearsensitive.exe -all: ${EXAMPLE} ${TEST} +all: ${DLL} ${EXAMPLE} ${TEST} M17N.dll: ${M17N_SRC} $(CS) -out:$@ -t:library ${M17N_SRC} diff --git a/eval.txt b/eval.txt index dbb567b..d1517ed 100644 --- a/eval.txt +++ b/eval.txt @@ -13,7 +13,7 @@ (set Y "abc") (+= Y "def")) (while (> X 7) - (/= X 2)) + (/= X 2) (+= X 1)) (set Y "ABC") (set Z (+ Y "def"))) (insert "kkk")