return mst.ReadInteger (out to);
}
- private MCharTable load_char_table (MCharTable table)
+ private void load_char_table (MCharTable table)
{
MSymbol type = tag[1];
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);
}
}
}
}
}
- public delegate object Loader (Tag tag, object extra_info);
+ public delegate MPlist Loader (Tag tag, object extra_info);
internal class MDatabaseInfo
{
};
public Tag tag;
- public NameTable name_table = new NameTable ();
private Loader loader;
private object ExtraInfo;
// Directory of the database file.
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)
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 ();
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";
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;
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)
{
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;
+ }
}
}
}
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 {
{
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
{
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);
}
{
//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++)
<symbol>looptest-finished</symbol>
</defun>
+ <defmacro fname="temp">
+ <args><fixed vname="x"/></args>
+ <if>
+ <lt><eval><varref vname="x"/></eval><integer>10</integer></lt>
+ <varref vname="x"/>
+ </if>
+ </defmacro>
+
<set vname="x"><integer>10</integer></set>
<set vname="str"><string>ABC</string></set>
<append>
</eval>
<concat><integer>?a</integer><integer>?b</integer></concat>
<quote><add><varref vname="x"/><integer>1</integer></add></quote>
+ <integer>100</integer>
+ <temp><add vname="y"><integer>5</integer></add></temp>
</append>
</expr>