public class Named : Marker
{
- int pos;
+ public Named (MSymbol name) : base (name) { }
- public Named (MSymbol name) : this (name, 0) { }
-
- private Named (MSymbol name, int p) : base (name) { pos = p; }
-
- public override int Position (Context ic) { return pos; }
+ public override int Position (Context ic)
+ {
+ int pos;
+ if (ic.markers.TryGetValue (name, out pos))
+ return pos;
+ return 0;
+ }
- public override void Mark (Context ic) { pos = ic.cursor_pos; }
+ public override void Mark (Context ic)
+ {
+ ic.markers[name] = ic.cursor_pos;
+ }
public override Xex.TermValue Clone ()
{
predefined_markers[s] = new Predefined (s);
}
- public static Marker Get (Context ic, MSymbol name)
+ public static Marker Get (MSymbol name)
{
Predefined pred;
- Marker m;
if (predefined_markers.TryGetValue (name, out pred))
return pred;
if (name.Name[0] == '@')
throw new Exception ("Invalid marker name: " + name);
- m = (Marker) ic.markers.Get (name);
- if (m == null)
- {
- m = new Named (name);
- ic.markers.Put (name, m);
- }
- return m;
+ return new Named (name);
}
}
}
}
- internal abstract class Selector : Xex.TermValue
+ internal class Selector : Xex.TermValue
{
- private Selector () { }
-
- public abstract void Select (Candidates candidates);
-
public static Xex.TermValue parser (Xex.Domain domain, XmlNode node)
{
- MSymbol name = node.InnerText;
+ return Get ((MSymbol) node.InnerText);
+ }
+
+ public static Xex.TermValue Get (MSymbol name)
+ {
Predefined pred;
- if (predefined_selectors.TryGetValue (name, out pred))
- return pred;
- if (name.Name[0] == '@')
- throw new Exception ("Invalid selector name: " + name);
- int index;
- if (! Int32.TryParse (node.InnerText, out index))
+ if (! predefined_selectors.TryGetValue (name, out pred))
throw new Exception ("Invalid selector name: " + name);
- return new Numbered (index);
+ return pred;
}
public override Xex.TermValue Clone () { return this; }
- public class Numbered : Selector
- {
- int index;
-
- public Numbered (int index) { this.index = index; }
-
- public override void Select (Candidates can) { can.Select (index); }
- }
-
- public class Predefined : Selector
+ public void Select (Candidates candidates)
{
- private char tag;
-
- internal Predefined (MSymbol sym) { this.tag = sym.Name[1]; }
-
- public override void Select (Candidates candidates)
- {
- switch (tag)
- {
- case '<': candidates.First (); break;
- case '>': candidates.Last (); break;
- case '-': candidates.Prev (); break;
- case '+': candidates.Next (); break;
- case '[': candidates.PrevGroup (); break;
- case ']': candidates.NextGroup (); break;
- default: break;
- }
- }
+ switch (tag)
+ {
+ case '<': candidates.First (); break;
+ case '>': candidates.Last (); break;
+ case '-': candidates.Prev (); break;
+ case '+': candidates.Next (); break;
+ case '[': candidates.PrevGroup (); break;
+ case ']': candidates.NextGroup (); break;
+ default: break;
+ }
}
- static new Dictionary<MSymbol, Predefined> predefined_selectors;
+ static new Dictionary<MSymbol, Selector> selectors;
static Selector ()
{
- predefined_selectors = new Dictionary<MSymbol, Predefined> ();
+ selectors = new Dictionary<MSymbol, Selector> ();
MSymbol[] symlist = new MSymbol[] { "@<", "@=", "@>", "@-", "@+",
"@[", "@]" };
foreach (MSymbol s in symlist)
- predefined_selectors[s] = new Predefined (s);
+ selectors[s] = new Selector (s);
}
}
this.actions = actions;
}
- public Xex.Term Lookup (KeySeq keys, ref index)
+ public Xex.Term Lookup (KeySeq keys, ref int index)
{
if (index < keys.keyseq.Count)
{
private Xex.Term parse_insert (MPlist plist)
{
+ Xex.Term[] args;
+ Xex.Term arg;
if (plist.IsSymbol)
- {
- Xex.Variable vari = domain.GetVar (Xex.Name (plist.Symbol.Name),
- true);
- Xex.Term[] args = Xex.Term[1];
- args[0] = new Xex.Term (vari);
- terms[i] = new Xex.Term (domain, Ninsert, args);
- }
+ arg = new Xex.Term (domain, (Xex.Symbol) plist.Symbol.Name);
else if (plist.IsMText)
- {
- Xex.Term[] args = Xex.Term[1];
- args[0] = new Xex.Term ((string) plist.Text);
- terms[i] = new Xex.Term (domain, Ninsert, args);
- }
+ arg = new Xex.Term ((string) plist.Text);
else if (plist.IsInteger)
+ arg = new Xex.Term (plist.Integer);
+ else if (plist.IsPlist)
{
- Xex.Term[] args = Xex.Term[1];
- args[0] = new Xex.Term (plist.Integer);
- terms[i] = new Xex.Term (domain, Ninsert, args);
+ MPlist pl = plist.Plist;
+ args = new Xex.Term[pl.Count];
+ int i;
+ for (i = 0; ! pl.IsEmpty; i++, pl = pl.next)
+ {
+ if (pl.IsMText)
+ args[i] = new Xex.Term ((string) pl.Text);
+ else if (pl.IsPlist)
+ {
+ List<Xex.Term> list = new List<Xex.Term> ();
+ for (MPlist p = pl.Plist; ! p.IsEmpty; p = p.next)
+ {
+ if (p.IsMText)
+ list.Add (new Xex.Term ((string) p.Text));
+ else
+ throw new Exception ("Invalid candidates: " + p);
+ }
+ }
+ else
+ throw new Exception ("Invalid candidates: " + pl);
+ }
+
}
+ else
+ throw new Exception ("Invalid arg to insert: " + plist);
+ args = new Xex.Term[1];
+ args[0] = arg;
+ return new Xex.Term (domain, Ninsert, args);
+ }
+
+ private Xex.Term parse_select (MPlist plist)
+ {
+ Xex.Term[] args = new Xex.Term[1];
+ if (plist.IsInteger)
+ args[0] = new Xex.Term (plist.Integer);
+ else if (! plist.IsSymbol)
+ throw new Exception ("Invalid arg to select: " + plist);
+ else if (plist.Symbol.Name[0] == '@')
+ args[0] = new Xex.Term (Selector.Get (plist.Symbol));
+ else
+ args[0] = new Xex.Term (domain, (Xex.Symbol) plist.Symbol.Name);
+ return new Xex.Term (domain, Nselect, args);
+ }
+
+ private Xex.Term parse_funcall_with_marker (MPlist plist, MSymbol func)
+ {
+ Xex.Term[] args = new Xex.Term[1];
+ if (plist.IsInteger && func != Nmark)
+ args[0] = new Xex.Term (plist.Integer);
+ else if (plist.IsSymbol)
+ args[0] = new Xex.Term (Marker.Get (plist.Symbol));
+ else
+ throw new Exception ("Invalid arg to " + func + ": " + plist);
+ return new Xex.Term (domain, (Xex.Symbol) func.Name, args);
+ }
+
+ private Xex.Term parse_char_at (MSymbol name)
+ {
+ Xex.Term[] args = new Xex.Term[1];
+ args[0] = Maker.Get (name);
+ return new Xex.Term (domain, Nchar_at, args);
}
private Xex.Term parse_action (MPlist plist)
MPlist p = plist.Plist;
if (p.IsMText || p.IsPlist)
- return parse_integer (p);
+ return parse_insert (p);
if (! p.IsSymbol)
throw new Exception ("Invalid action: " + p);
MSymbol name = p.Symbol;
if (name == Mcond)
return parse_cond (p);
if (name == Minsert)
- return parse_integer (p);
+ return parse_insert (p);
+ if (name == Mselect)
+ return parse_select (p);
+ if (name == Mdelete || name == Mmove || name == Mmark)
+ return parse_funcall_with_marker (p, name);
+ if (name.Name[0] == '@')
+ return parse_char_at (name);
if (name == Mset || name == Madd || name == Msub
|| name == Mmul || name == Mdiv)
{
return new Xex.Term (domain, (Xex.Symbol) name.Name,
parse_actions (p));
}
- else if (plist.MText || plist.Integer || plist.IsSymbol)
- retunr parse_insert (plist);
+ else if (plist.IsMText || plist.IsInteger || plist.IsSymbol)
+ return parse_insert (plist);
else
throw new Exception ("Invalid action: " + plist);
}
private MText status;
internal MText preedit;
internal int cursor_pos;
+ internal Dictionary<Xex.Symbol, int> markers;
internal Candidates candidates;
private int candidate_from, candidate_to;
private bool candidate_show;
private int commit_key_head;
private MText state_preedit;
private int state_pos;
- internal MPlist markers = new MPlist ();
internal MText preceding_text = new MText ();
internal MText following_text = new MText ();
{
state = state_list.Last ();
if (state_list.Count > 1)
- state_list.RemoveAt (state_list.Count - 1)
+ state_list.RemoveAt (state_list.Count - 1);
}
else
{
return active;
}
- public bool UnhandledKey (out const Key key)
+ public bool UnhandledKey (out Key key)
{
key = unhandled_key;
return key_unhandled;
}
- public bool Produced (out const MText mt)
+ public bool Produced (out MText mt)
{
mt = produced;
return (produced.Length > 0);