public virtual void Reset () { val = Zero; }
- public virtual string Description { get { return null; } }
-
public Term Value
{
get { return val; }
public override void Reset () { val = default_val; }
- public override string Description { get { return desc; } }
+ public string Description {
+ get { return desc; }
+ set { desc = value; }
+ }
}
public class Int : Typed
vari = new Variable (this, name, Zero);
variables[name] = vari;
}
- Console.WriteLine (vari);
return vari;
}
Variable.Int intvari = vari as Variable.Int;
if (intvari == null)
throw new Exception ("Variable type mismatch: " + name);
- if (range == null)
- range = intvari.Range;
- else if (! intvari.IsSubrange (range))
- throw new Exception ("Variable range mismatch: " + name);
- if (desc == null)
- desc = vari.Description;
+ if (range != null)
+ {
+ if (! intvari.IsSubrange (range))
+ throw new Exception ("Variable range mismatch: " + name);
+ intvari.Range = range;;
+ }
+ if (desc != null)
+ intvari.Description = desc;
+ }
+ else
+ {
+ vari = new Variable.Int (this, name, n, desc, range);
+ variables[name] = vari;
}
- vari = new Variable.Int (this, name, n, desc, range);
- variables[name] = vari;
return vari;
}
Variable.Str strvari = vari as Variable.Str;
if (strvari == null)
throw new Exception ("Variable type mismatch: " + name);
- if (range == null)
- range = strvari.Range;
- else if (! strvari.IsSubrange (range))
- throw new Exception ("Variable range mismatch: " + name);
- if (desc == null)
- desc = vari.Description;
+ if (range != null)
+ {
+ if (! strvari.IsSubrange (range))
+ throw new Exception ("Variable range mismatch: " + name);
+ strvari.Range = range;
+ }
+ if (desc != null)
+ strvari.Description = desc;
+ }
+ else
+ {
+ vari = new Variable.Str (this, name, str, desc, range);
+ variables[name] = vari;
}
- vari = new Variable.Str (this, name, str, desc, range);
- variables[name] = vari;
return vari;
}
Variable.Sym symvari = vari as Variable.Sym;
if (symvari == null)
throw new Exception ("Variable type mismatch: " + name);
- if (range == null)
- range = symvari.Range;
- else if (! symvari.IsSubrange (range))
- throw new Exception ("Variable range mismatch: " + name);
- if (desc == null)
- desc = vari.Description;
+ if (range != null)
+ {
+ if (! symvari.IsSubrange (range))
+ throw new Exception ("Variable range mismatch: " + name);
+ symvari.Range = range;
+ }
+ if (desc != null)
+ symvari.Description = desc;
+ }
+ else
+ {
+ vari = new Variable.Sym (this, name, sym, desc, range);
+ variables[name] = vari;
}
- vari = new Variable.Sym (this, name, sym, desc, range);
- variables[name] = vari;
return vari;
}
return str;
}
- internal void DebugWrite (bool head, string fmt, params string[] arg)
+ internal void DebugWrite (string fmt, params string[] arg)
{
if (debug_depth > depth)
{
- if (head)
- {
- Console.WriteLine ();
- for (int i = 0; i < depth; i++)
- Console.Write (" ");
- }
- Console.Write (fmt, arg);
+ for (int i = 0; i < depth; i++)
+ Console.Write (" ");
+ Console.WriteLine (fmt, arg);
}
}
if (result.IsTrue)
{
for (int i = 1; i < list.Count; i++)
- result = list[i].Eval (domain);
+ {
+ domain.depth++;
+ result = list[i].Eval (domain);
+ domain.depth--;
+ if (domain.Thrown)
+ return result;
+ }
return result;
}
}
public override Term Eval (Domain domain)
{
- domain.DebugWrite (true, ToString ());
+ domain.DebugWrite (ToString ());
domain.depth++;
Term result = func.Call (domain, vari, args);
domain.depth--;
- domain.DebugWrite (true, " ==> {0}", result.ToString ());
+ domain.DebugWrite ("=> {0}", result.ToString ());
return result;
}
return str + "/>";
str += ">";
if (func is Function.SpecialForm)
- str += String.Format ("({0})...", args.Length);
+ {
+ for (int i = 0; i < args.Length; i++)
+ str += ".";
+ }
else
foreach (Term e in args)
str += e;
public static void Main(string[] args)
{
// M17n.debug = true;
- // Xex.DebugDepth = 10;
int argc = 0;
- if (args[0] == "xml")
+ string appdir = "/usr/local/share/m17n";
+ int debug_depth = 0;
+
+ while (argc < args.Length && args[argc][0] == '-')
{
- MDatabase.ApplicationDir = "/usr/local/share/m17n-xml";
+ if (args[argc] == "-debug")
+ debug_depth = 10;
+ else if (args[argc] == "-xml")
+ appdir = "/usr/local/share/m17n-xml";
argc++;
}
- else
- MDatabase.ApplicationDir = "/usr/local/share/m17n";
+ if (argc + 2 >= args.Length)
+ {
+ Console.WriteLine ("Usage: mono [--debug] input.exe"
+ + " [-debug] [-xml] LANG NAME KEY-SEQUECE");
+ return;
+ }
+
+ Xex.DebugDepth = debug_depth;
+ MDatabase.ApplicationDir = appdir;
MInputMethod im = MInputMethod.Find (args[argc], args[argc + 1]);
MText mt = new MText ();
MInputMethod.Session session = new MInputMethod.Session (im, mt, 0);
MInputMethod.Key key = new MInputMethod.Key (str[i]);
session.HandleKey (key);
int pos = session.CurrentPos;
- Console.WriteLine ("{0} -> \"{1}|{2}|{3}\"",
- str[i, i + 1],
- mt[0, pos],
- session.Preedit,
- mt[pos, mt.Length]);
+ MText head = mt[0, pos];
+ MText preedit = session.Preedit;
+ MText tail = mt[pos, mt.Length];
+ Console.Write ("{0} -> \"{1}|{2}|{3}\" (",
+ str[i, i + 1], head, preedit, tail);
+ for (int j = 0; j < head.Length; j++)
+ Console.Write ("{0}U+{1:X4}", j == 0 ? "(" : " ", head[j]);
+ Console.Write ("|");
+ for (int j = 0; j < preedit.Length; j++)
+ Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", preedit[j]);
+ Console.Write ("|");
+ for (int j = 0; j < tail.Length; j++)
+ Console.Write ("{0}U+{1:X4}", j == 0 ? "" : " ", tail[j]);
+ Console.WriteLine (")");
}
}
}