internal class KeySeq : Xex.TermValue
{
+ private static Xex.Symbol name = "keyseq";
+ public static Xex.Symbol Name { get { return name; } }
+
public List<Key> keyseq = new List<Key> ();
public override Xex.TermValue Clone ()
}
}
- public static Xex.TermValue parser (Xex.Domain domain, XmlNode node)
+ public static Xex.TermValue Parser (Xex.Domain domain, XmlNode node)
{
Xex.Term term = new Xex.Term (domain, node.FirstChild).Eval (domain);
return (term.IsStr ? new KeySeq ((MText) term.Strval)
if (node.Name == "description")
description = parse_description (node);
else if (node.Name == "keyseq")
- keys.Add ((KeySeq) KeySeq.parser (null, node));
+ keys.Add ((KeySeq) KeySeq.Parser (null, node));
}
}
internal abstract class Marker : Xex.TermValue
{
- private MSymbol name;
+ private static Xex.Symbol name = "marker";
+ public static Xex.Symbol Name { get { return name; } }
+
+ private MSymbol mname;
- private Marker (MSymbol name)
+ private Marker (MSymbol mname)
{
- this.name = name;
+ this.mname = mname;
}
public abstract int Position (Context ic);
public virtual void Mark (Context ic)
{
- throw new Exception ("Can't set predefined marker: " + name);
+ throw new Exception ("Can't set predefined marker: " + mname);
}
public virtual int CharAt (Context ic)
{
public override string ToString ()
{
- return "<marker>" + name.Name + "</marker>";
+ return "<marker>" + mname + "</marker>";
}
- public static Xex.TermValue parser (Xex.Domain domain, XmlNode node)
+ public static Xex.TermValue Parser (Xex.Domain domain, XmlNode node)
{
return Get ((MSymbol) node.InnerText);
}
public class Named : Marker
{
- public Named (MSymbol name) : base (name) { }
+ public Named (MSymbol mname) : base (mname) { }
public override int Position (Context ic)
{
- MPlist p = ic.marker_positions.Find (name);
+ MPlist p = ic.marker_positions.Find (mname);
return (p == null ? 0 : p.Integer);
}
public override void Mark (Context ic)
{
- ic.marker_positions.Put (name, ic.cursor_pos);
+ ic.marker_positions.Put (mname, ic.cursor_pos);
}
}
{
private int pos;
- public PredefinedAbsolute (MSymbol name) : base (name)
+ public PredefinedAbsolute (MSymbol mname) : base (mname)
{
- if (! int.TryParse (((string) name).Substring (1), out pos))
- throw new Exception ("Invalid marker name: " + name);
+ if (! int.TryParse (((string) mname).Substring (1), out pos))
+ throw new Exception ("Invalid marker name: " + mname);
}
public override int Position (Context ic)
{
private int distance;
- public PredefinedSurround (MSymbol name) : base (name)
+ public PredefinedSurround (MSymbol mname) : base (mname)
{
if (! int.TryParse (((string) name).Substring (1), out distance))
- throw new Exception ("Invalid marker name: " + name);
+ throw new Exception ("Invalid marker name: " + mname);
if (distance > 0)
distance--;
}
= new Predefined (']');
}
- public static Marker Get (MSymbol name)
+ public static Marker Get (MSymbol mname)
{
- string str = name.Name;
+ string str = mname.Name;
if (str[0] == '@')
{
Predefined pred;
- if (predefineds.TryGetValue (name, out pred))
+ if (predefineds.TryGetValue (mname, out pred))
return pred;
if (str.Length == 1)
- throw new Exception ("Invalid marker name: " + name);
+ throw new Exception ("Invalid marker name: " + mname);
if (Char.IsDigit (str[1]))
- return new PredefinedAbsolute (name);
- if (str.Length == 2 || name == Mat_minus_zero
+ return new PredefinedAbsolute (mname);
+ if (str.Length == 2 || mname == Mat_minus_zero
|| ! (str[1] == '-' || str[1] == '+'))
- throw new Exception ("Invalid marker name: " + name);
- return new PredefinedSurround (name);
+ throw new Exception ("Invalid marker name: " + mname);
+ return new PredefinedSurround (mname);
}
- return new Named (name);
+ return new Named (mname);
}
}
internal class Selector : Xex.TermValue
{
+ private static Xex.Symbol name = "selector";
+ public static Xex.Symbol Name { get { return name; } }
+
static new Dictionary<MSymbol, Selector> selectors;
static Selector ()
private Selector (char tag) { this.tag = tag; }
- public static Xex.TermValue parser (Xex.Domain domain, XmlNode node)
+ public static Xex.TermValue Parser (Xex.Domain domain, XmlNode node)
{
return Get ((MSymbol) node.InnerText);
}
static MInputMethod ()
{
- im_domain.DefTerm ("keyseq", KeySeq.parser);
- im_domain.DefTerm ("marker", Marker.parser);
- im_domain.DefTerm ("selector", Selector.parser);
+ im_domain.DefType (typeof (KeySeq));
+ im_domain.DefType (typeof (Marker));
+ im_domain.DefType (typeof (Selector));
im_domain.DefSubr (Finsert, "insert", false, 1, 1);
im_domain.DefSubr (Finsert_candidates, "insert-candidates", false, 1, -1);
XmlNode n = nd.FirstChild;
if (n.Name != Qkeyseq)
continue;
- KeySeq keyseq = (KeySeq) KeySeq.parser (domain, n);
+ KeySeq keyseq = (KeySeq) KeySeq.Parser (domain, n);
Xex.Term[] actions = Xex.ParseTerms (domain, n.NextSibling);
map.entries.Add (new Map.Entry (domain, keyseq, actions));
}
public object context;
public int depth = 0;
- internal Dictionary<Symbol, TermType> termtypes
- = new Dictionary<Symbol, TermType> ();
+ internal Dictionary<Symbol, MethodInfo> termtypes
+ = new Dictionary<Symbol, MethodInfo> ();
internal Dictionary<Symbol, Function> functions
= new Dictionary<Symbol, Function> ();
internal Dictionary<Symbol, Variable> variables
public Domain (Symbol name, Domain parent, object context) : this (name)
{
- termtypes = new Dictionary<Symbol, TermType> (parent.termtypes);
+ termtypes = new Dictionary<Symbol, MethodInfo> (parent.termtypes);
functions = new Dictionary<Symbol, Function> (parent.functions);
variables = new Dictionary<Symbol, Variable> (parent.variables);
this.context = context;
}
}
- public void DefTerm (Symbol name, TermParser parser)
- {
- if (termtypes.ContainsKey (name)
- || functions.ContainsKey (name))
- throw new Exception ("already defined: " + name);
- termtypes[name] = new TermType (name, parser);
- }
-
public void DefType (Type type)
{
if (! type.IsSubclassOf (typeof (TermValue)))
throw new Exception ("Not a subclass of TermValue: " + type);
BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic;
FieldInfo finfo = type.GetField ("name", flags);
- if (finfo == null)
- throw new Exception ("No \"name\" field: " + type);
- Type[] types = new Type[] { typeof (Domain), typeof (XmlNode),
- typeof (TermValue) };
- MethodInfo minfo = type.GetMethod ("Parser");
- if (minfo == null)
- throw new Exception ("No \"Parser\" method: " + type);
+ if (finfo == null || finfo.FieldType != typeof (Symbol))
+ throw new Exception ("No \"name\" field of string type: " + type);
+ Symbol name = (Symbol) finfo.GetValue (null);
+ if (termtypes.ContainsKey (name)
+ || functions.ContainsKey (name))
+ throw new Exception ("already defined: " + name);
+ Type[] types = new Type[] { typeof (Domain), typeof (XmlNode) };
+ MethodInfo minfo = type.GetMethod ("Parser", types);
+ if (minfo == null || minfo.ReturnType != typeof (TermValue))
+ throw new Exception ("No \"Parser\" method of correct type: " + type);
+ termtypes[name] = minfo;
}
public void DefSubr (Builtin builtin, string str, bool setvar,
static Xexpression ()
{
- basic.DefTerm ("funcall", Funcall.parser);
- basic.DefTerm ("varref", Varref.parser);
+ basic.DefType (typeof (Varref));
basic.DefType (typeof (Funcall));
basic.DefSubr (Fset, "set", true, 1, 1, "=");
public delegate TermValue TermParser (Domain domain, XmlNode node);
- public class TermType
- {
- private readonly Symbol name;
- private readonly TermParser parser;
-
- public TermType (Symbol name, TermParser parser)
- {
- this.name = name;
- this.parser = parser;
- }
-
- public Symbol Name { get { return name; } }
- internal TermParser Parser { get { return parser; } }
- }
-
public abstract class TermValue
{
public virtual Term Eval (Domain domain) { return new Term (this); }
private class Varref : TermValue
{
+ private static Symbol name = "varref";
+ public static Symbol Name { get { return name; } }
+
private Symbol vname;
private Variable vari;
return vari.Value;
}
- internal static TermValue parser (Domain domain, XmlNode node)
+ public static TermValue Parser (Domain domain, XmlNode node)
{
return new Varref ((Symbol) node.Attributes[Qvname].Value);
}
public static TermValue Parser (Domain domain, XmlNode node)
{
- return null;
- }
+ Symbol fname = node.Name;
+ XmlAttribute attr;
- internal static TermValue parser (Domain domain, XmlNode node)
- {
- Symbol fname = node.Name;
- XmlAttribute attr;
-
- if (fname == Qfuncall)
- fname = node.Attributes[Qfname].Value;
- Function func = domain.GetFunc (fname);
- Variable vari;
- attr = node.Attributes[Qvname];
- vari = attr == null ? null : domain.GetVar (attr.Value, true);
- XmlNodeList nlist = node.ChildNodes;
- int nargs = nlist.Count;
- Term[] args = new Term[nargs];
- for (int i = 0; i < nargs; i++)
- args[i] = new Term (domain, nlist[i]);
- return new Funcall (func, vari, args);
- }
+ if (fname == Qfuncall)
+ fname = node.Attributes[Qfname].Value;
+ Function func = domain.GetFunc (fname);
+ Variable vari;
+ attr = node.Attributes[Qvname];
+ vari = attr == null ? null : domain.GetVar (attr.Value, true);
+ XmlNodeList nlist = node.ChildNodes;
+ int nargs = nlist.Count;
+ Term[] args = new Term[nargs];
+ for (int i = 0; i < nargs; i++)
+ args[i] = new Term (domain, nlist[i]);
+ return new Funcall (func, vari, args);
+ }
public override Term Eval (Domain domain)
{
}
else
{
- TermType term_type;
+ MethodInfo minfo;
- if (domain.termtypes.TryGetValue (name, out term_type))
- objval = term_type.Parser (domain, node);
+ if (domain.termtypes.TryGetValue (name, out minfo))
+ objval = (TermValue) minfo.Invoke (null, new Object[] { domain, node});
else
{
- Funcall funcall = (Funcall) Funcall.parser (domain, node);
+ Funcall funcall = (Funcall) Funcall.Parser (domain, node);
if (funcall.func is Function.Macro)
{
Term result = funcall.Eval (domain);