From: handa Date: Mon, 5 Oct 2009 13:09:20 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=efe6dfe872c15b2bde9efb4f07ec639547710d10;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MInputMethod.cs b/MInputMethod.cs index da100dc..9f7a420 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -506,15 +506,20 @@ namespace M17N.Input 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 () { @@ -579,22 +584,15 @@ namespace M17N.Input 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); } } @@ -852,68 +850,47 @@ namespace M17N.Input } } - 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 predefined_selectors; + static new Dictionary selectors; static Selector () { - predefined_selectors = new Dictionary (); + selectors = new Dictionary (); MSymbol[] symlist = new MSymbol[] { "@<", "@=", "@>", "@-", "@+", "@[", "@]" }; foreach (MSymbol s in symlist) - predefined_selectors[s] = new Predefined (s); + selectors[s] = new Selector (s); } } @@ -942,7 +919,7 @@ namespace M17N.Input 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) { @@ -1750,26 +1727,77 @@ namespace M17N.Input 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 list = new List (); + 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) @@ -1779,7 +1807,7 @@ namespace M17N.Input 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; @@ -1787,7 +1815,13 @@ namespace M17N.Input 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) { @@ -1801,8 +1835,8 @@ namespace M17N.Input 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); } @@ -2102,6 +2136,7 @@ namespace M17N.Input private MText status; internal MText preedit; internal int cursor_pos; + internal Dictionary markers; internal Candidates candidates; private int candidate_from, candidate_to; private bool candidate_show; @@ -2120,7 +2155,6 @@ namespace M17N.Input 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 (); @@ -2429,7 +2463,7 @@ namespace M17N.Input { state = state_list.Last (); if (state_list.Count > 1) - state_list.RemoveAt (state_list.Count - 1) + state_list.RemoveAt (state_list.Count - 1); } else { @@ -2505,13 +2539,13 @@ namespace M17N.Input 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); diff --git a/XmlExpr.cs b/XmlExpr.cs index 2b4481d..60a2008 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -1692,6 +1692,12 @@ namespace System.Xml.Expression } } + public Term (Domain domain, Symbol vname) + { + intval = 0; + objval = domain.GetVar (vname, true); + } + public Term (Domain domain, Symbol fname, Term[] args) { intval = 0;