From e928b18ccdd85d02ad377a2ce9eab7098b1f8aaf Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 6 Oct 2009 00:04:20 +0000 Subject: [PATCH] *** empty log message *** --- MInputMethod.cs | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/MInputMethod.cs b/MInputMethod.cs index 9f7a420..b0736ea 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -42,6 +42,7 @@ namespace M17N.Input private static MSymbol Mstate = "state"; internal static MSymbol Mcandidates = "candidates"; private static MSymbol Minsert = "insert"; + internal static MSymbol Mselect = "select"; private static MSymbol Mdelete = "delete"; private static MSymbol Mmove = "move"; private static MSymbol Mmark = "mark"; @@ -59,6 +60,10 @@ namespace M17N.Input private static MSymbol Mkeyseq = "keyseq"; private static Xex.Symbol Nprogn = "progn"; + private static Xex.Symbol Ninsert = "insert"; + private static Xex.Symbol Ninsert_candidates = "insert-candidates"; + private static Xex.Symbol Nchar_at = "char-at"; + private static Xex.Term Tnil = new Xex.Term ((Xex.Symbol) "nil"); private static Xex.Term Tcatch_tag = new Xex.Term ((Xex.Symbol) "@mimtag"); @@ -496,6 +501,7 @@ namespace M17N.Input public abstract int Position (Context ic); public abstract void Mark (Context ic); + public abstract int CharAt (Context ic); public static Xex.TermValue parser (Xex.Domain domain, XmlNode node) { @@ -572,6 +578,24 @@ namespace M17N.Input } } + public class PredefinedPlusMinus : Marker + { + private int distance; + + public PredefinedPlusMinus (MSymbol name): base (name) + { + if (! int.TryParse (name.Name.Substring (2), out distance)) + throw new Exception ("Invalid marker name: " + name); + if (distance > 0) + distance--; + } + + public override int Position (Context ic) + { + return ic.cursor_pos + distance; + } + } + static internal Dictionary predefined_markers; static Marker () @@ -591,7 +615,16 @@ namespace M17N.Input if (predefined_markers.TryGetValue (name, out pred)) return pred; if (name.Name[0] == '@') - throw new Exception ("Invalid marker name: " + name); + { + int pos; + if (name.Name.Length >= 3 + && (name.Name[1] == '-' || name.Name[1] == '+') + && int.TryParse (name.Name.Substring (2), out pos) + && (pos > 0)) + return (predefined_markers[name] = new Predefined (name)); + else + throw new Exception ("Invalid marker name: " + name); + } return new Named (name); } } @@ -1020,7 +1053,7 @@ namespace M17N.Input im_domain.DefSubr (Fcommit, "commit", false, 0, 0); im_domain.DefSubr (Funhandle, "unhandle", false, 0, 0); im_domain.DefSubr (Fshift, "shift", false, 1, 1); - im_domain.DefSubr (Fshift_back, "shiftback", false, 0, 0); + im_domain.DefSubr (Fshiftback, "shiftback", false, 0, 0); im_domain.DefSubr (Fchar_at, "char-at", false, 1, 1); im_domain.DefSubr (Fkey_count, "key-count", false, 1, 1); im_domain.DefSubr (Fsurrounding_flag, "surrounding-text-flag", @@ -1758,7 +1791,7 @@ namespace M17N.Input else throw new Exception ("Invalid candidates: " + pl); } - + return new Xex.Term (domain, Ninsert_candidates, args); } else throw new Exception ("Invalid arg to insert: " + plist); @@ -1778,13 +1811,13 @@ namespace M17N.Input 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); + return new Xex.Term (domain, (Xex.Symbol) Mselect.Name, args); } private Xex.Term parse_funcall_with_marker (MPlist plist, MSymbol func) { Xex.Term[] args = new Xex.Term[1]; - if (plist.IsInteger && func != Nmark) + if (plist.IsInteger && func != Mmark) args[0] = new Xex.Term (plist.Integer); else if (plist.IsSymbol) args[0] = new Xex.Term (Marker.Get (plist.Symbol)); @@ -1796,7 +1829,7 @@ namespace M17N.Input private Xex.Term parse_char_at (MSymbol name) { Xex.Term[] args = new Xex.Term[1]; - args[0] = Maker.Get (name); + args[0] = new Xex.Term (Marker.Get (name)); return new Xex.Term (domain, Nchar_at, args); } @@ -2073,7 +2106,7 @@ namespace M17N.Input return args[0]; } - private static Xex.Term Fshift_back (Xex.Domain domain, Xex.Variable vari, + private static Xex.Term Fshiftback (Xex.Domain domain, Xex.Variable vari, Xex.Term[] args) { ((Context) domain.context).shift_back (); -- 1.7.10.4