From: handa Date: Mon, 28 Sep 2009 06:12:32 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=8e50033918bee037d940226406c87b9bc97779da;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MInputMethod.cs b/MInputMethod.cs index e75f5bc..a6c8552 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -34,15 +34,12 @@ namespace M17N.Input private static MSymbol Mvariable = "variable"; private static MSymbol Mcommand = "command"; private static MSymbol Mmodule = "module"; - private static MSymbol Mmodule_list = "module-list"; private static MSymbol Mtitle = "title"; private static MSymbol Minclude = "include"; private static MSymbol Mmacro = "macro"; - private static MSymbol Mmacro_list = "macro-list"; private static MSymbol Mmap = "map"; private static MSymbol Mmap_list = "map-list"; private static MSymbol Mstate = "state"; - private static MSymbol Mstate_list = "state-list"; internal static MSymbol Mcandidates = "candidates"; private static MSymbol Minsert = "insert"; private static MSymbol Mdelete = "delete"; @@ -70,28 +67,6 @@ namespace M17N.Input internal static MInputMethod im_global = null; - // Sub classes - private class Exception : System.Exception - { - bool error; - - public Exception (string msg) : base (msg) - { - error = true; - } - - public Exception (string fmt, params object[] args) - : base (String.Format (fmt, args)) - { - error = true; - } - - public Exception (string msg, bool error) : base (msg) - { - this.error = error; - } - } - [FlagsAttribute] private enum LoadStatus { @@ -857,11 +832,7 @@ namespace M17N.Input List list = MDatabase.List (tag); M17n.DebugPrint ("Found {0} input methods\n", list.Count); foreach (MDatabase mdb in list) - { - im_table[mdb.tag] = new MInputMethod (mdb.tag); - } - tag = new MDatabase.Tag (Minput_method, MSymbol.t, MSymbol.nil, "global"); - im_global = im_table[tag]; + im_table[mdb.tag] = new MInputMethod (mdb.tag); } // Constructor @@ -1335,6 +1306,19 @@ namespace M17N.Input } } + private Xex.Variable get_global_var (Xex.Symbol name) + { + if (im_global == null || this != im_global) + { + tag = new MDatabase.Tag (Minput_method, MSymbol.t, MSymbol.nil, + "global"); + im_global = im_table[tag]; + if (! im_global.Open ()) + throw new Exception ("Failed to load global"); + } + return im_global.domain.GetVar (name, false); + } + private void parse_variables (MPlist plist) { var_names = new Xex.Symbol[plist.Count]; @@ -1349,8 +1333,7 @@ namespace M17N.Input var_names[i] = name; p = p.next; string desc = (string) parse_description (p); - Xex.Variable vari - = im_global != null ? im_global.domain.GetVar (name, false) : null; + Xex.Variable vari = get_global_var (name); if (vari != null) domain.Defvar (vari); if (desc != null) @@ -1377,8 +1360,7 @@ namespace M17N.Input for (int i = 0; i < node_list.Count; i++) { Xex.Symbol name = node_list[i].Attributes[0].Value; - Xex.Variable vari = im_global.domain.GetVar (name, false); - + Xex.Variable vari = get_global_var (name); if (vari != null) domain.Defvar (vari); else @@ -1870,17 +1852,13 @@ namespace M17N.Input private MText produced; private bool active; private MText status; - private bool status_changed; internal MText preedit; - private bool preedit_changed; internal int cursor_pos; - private bool cursor_pos_changed; private Candidates candidates; private MPlist candidate_group; private int candidate_index; private int candidate_from, candidate_to; private bool candidate_show; - private bool candidate_changed; private Stack states; internal MInputMethod.KeySeq keys; @@ -1897,6 +1875,25 @@ namespace M17N.Input internal Xex.Domain domain; + [FlagsAttribute] + public enum ChangedStatus + { + None = 0x00, + StateTitle = 0x01, + Preedit = 0x02, + CursorPos = 0x04, + CandidateList = 0x08, + CandidateIndex = 0x10, + CandidateShow = 0x20, + } + + private static ChangedStatus CandidateAll = (ChangedStatus.CandidateList + | ChangedStatus.CandidateIndex + | ChangedStatus.CandidateShow); + private ChangedStatus changed; + + public ChangedStatus Changed { get { return changed; } } + public MInputContext (MInputMethod im) { this.im = im; @@ -1949,8 +1946,7 @@ namespace M17N.Input preedit_replace (cursor_pos, cursor_pos, arg.Intval); else preedit_replace (cursor_pos, cursor_pos, new MText (arg.Strval)); - preedit_changed = true; - cursor_pos_changed = true; + changed |= ChangedStatus.Preedit | ChangedStatus.CursorPos; } private class Candidates @@ -2070,9 +2066,8 @@ namespace M17N.Input { ic.preedit.PopProp (0, ic.preedit.Length, MInputMethod.Mcandidates); ic.candidates = null; - ic.preedit_changed = true; - ic.cursor_pos_changed = true; - ic.candidate_changed = true; + ic.changed |= (ChangedStatus.Preedit | ChangedStatus.CursorPos + | CandidateAll); } // Fill the array "group" by candidates stating from INDEX. @@ -2225,9 +2220,8 @@ namespace M17N.Input preedit.PushProp (candidate_from, candidate_to, MInputMethod.Mcandidates, this); cursor_pos = candidate_from; - preedit_changed = true; - cursor_pos_changed = true; - candidate_changed = true; + changed |= (ChangedStatus.Preedit | ChangedStatus.CursorPos + | CandidateAll); } internal void insert_candidates (Xex.Term arg) @@ -2368,20 +2362,19 @@ namespace M17N.Input preedit_replace (pos, cursor_pos, null); else preedit_replace (cursor_pos, pos, null); - preedit_changed = true; - cursor_pos_changed = true; + changed |= ChangedStatus.Preedit | ChangedStatus.CursorPos; } internal void show () { candidate_show = true; - candidate_changed = true; + changed |= ChangedStatus.CandidateShow; } internal void hide () { candidate_show = false; - candidate_changed = true; + changed |= ChangedStatus.CandidateShow; } internal void move (int pos) @@ -2393,7 +2386,7 @@ namespace M17N.Input if (pos != cursor_pos) { cursor_pos = pos; - preedit_changed = true; + changed |= ChangedStatus.Preedit; } } @@ -2454,7 +2447,7 @@ namespace M17N.Input { produced.Cat (preedit); preedit.Del (); - preedit_changed = true; + changed |= ChangedStatus.Preedit; } internal void shift (MSymbol sym) @@ -2493,7 +2486,7 @@ namespace M17N.Input status = state.title; if (status == null) status = im.title; - status_changed = true; + changed |= ChangedStatus.StateTitle; Xex on_entry = (Xex) state.branches.Get (MSymbol.t); if (on_entry != null) @@ -2532,9 +2525,12 @@ namespace M17N.Input internal void HandleKey () { - MInputMethod.State state = states.Peek (); + } - + public bool Toggle () + { + active = ! active; + return active; } } } diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..0e626ce --- /dev/null +++ b/input.txt @@ -0,0 +1,49 @@ +INPUT-METHOD = + '' + TAGS + DESCRIPTION ? + TITLE ? + VARLIST ? + CMDLIST ? + MODULELIST ? + MACROLIST ? + MAPLIST ? + STATELIST ? + '' + +VARLIST = '' DEFVAR * '' +CMDLIST = '' COMMAND * '' +MODULELIST = '' MODULE * '' +MACROLIST = '' DEFUN * '' +MAPLIST = '' MAP * '' +STATELIST = '' STATE * '' + +MODULE = '' DEFUN-NAME + '' +DEFUN-NAME = '' + +MAP = '' RULE * '' + +RULE = '' [ KEYSEQ | COMMAND-REF ] FUNCALL * '' + +STATE = '' BRANCH * '' + +BRANCH = ... + +TERM += MIM-TERM +PREDEFINED += MIM-PREDEFEIND + +MIM-TERM = KEYSEQ MARKER + +KEYSEQ = '' [ INTTERM | STRTERM | SYMTERM ] + '' +KEYSEQTERM = KEYSEQ | VAR (value is KEYSEQ) | FUNCALL (return KEYSEQ) + +MARKER = '' SYMTERM '' +MARKERTERM = MARKER | VAR (value is MARKER) | FUNCALL (return MARKER) + + +MIM-PREDEFINED = MARK MOVE PUSHBACK ... + +MOVE = '' [ MARKERTERM | INTTERM ] '' +MARK = '' MARKERTERM '' +PUSHBACK = '' [ KEYSEQTERM | INTTERM ] '' +... diff --git a/xex.txt b/xex.txt index 5426526..7069f4b 100644 --- a/xex.txt +++ b/xex.txt @@ -65,19 +65,18 @@ VAR = FUNCALL = '' TERM * '' - | '<' PREDEFINED '>' TERM * '' - | '<' PREDEFINED 'vname="' VNAME '">' TERM * '' + | PREDEFINED PREDEFINED = - 'set' - | 'and' | 'or' | 'not' - | 'lt' | 'le' | 'eq' | 'ge' | 'gt' | 'noteq' - | 'add' | 'sub' | 'mul' | 'div' | 'mod' - | 'logand' | 'logior' | 'logxor' | 'lsh' - | 'append' | 'concat' | 'length' | 'nth' | 'copy' | 'ins' | 'del' - | 'progn' | 'if' | 'when' | 'cond' - | 'loop' | 'while' | 'foreach' | 'break' | 'return' - | 'quote' | 'eval' | 'type' + SET + | AND | OR | NOT + | LT | LE | EQ | GE | GT | NOTEQ + | ADD | SUB | MUL | DIV | MOD + | LOGAND | LOGIOR | LOGXOR | LSH + | APPEND | CONCAT | LENGTH | NTH | COPY | INS | DEL + | PROGN | IF | WHEN | COND + | LOOP | WHILE | FOREACH | BREAK | RETURN + | QUOTE | EVAL | TYPE ;; TERM has a value, and is evaluated to a TERM as below. ;; INT has an integer value, and is evaluated to itself . @@ -91,56 +90,57 @@ PREDEFINED = INTTERM = INT | VAR (value is INT) | FUNCALL (return INT) STRTERM = STR | VAR (value is STR) | FUNCALL (return STR) +SYMTERM = SYMBOL | VAR (value is SYMBOL) | FUNCALL (return SYMBOL) LISTTERM = LIST | VAR (value is LIST) | FUNCALL (return LIST) ANYTERM = TERM ;; Here after, when an argument is TERM, it is given to a function ;; without being evaluted. Otherwise, an evaluated term is given. -'' ANYTERM '' -'' INTTERM + '' -'' INTTERM + '' -'' INTTERM + '' -'' INTTERM + '' -'' INTTERM + '' -'' INTTERM + '' -'
' INTTERM + '
' -'
' INTTERM + '
' -'' INTTERM INTTERM '' -'' INTTERM '' -' INTTERM + '' -'' INTTERM + '' -' INTTERM + '' -' vname="' VNAME '">' INTTERM + '' -' INTTERM + '' -' vname="' VNAME '">' INTTERM + '' -'' INTTERM INTTERM '' -'' INTTERM '' -'' INTTERM INTTERM '' -'' INTTERM INTTERM '' -'' INTTERM INTTERM '' -'' INTTERM INTTERM '' -'' INTTERM INTTERM '' -'' INTTERM INTTERM '' -'' ANYTERM + '' -'' [ INTTERM | STRTERM | LISTTERM ] + '' -'' [ STRTERM | LISTTERM ] '' -'' INTTERM [ STRTERM | LISTTERM ] '' -'' LISTTERM '' -'' INTTERM [ STRTERM | LISTTERM ] '' -'' INTTERM INTTERM '' -'' TERM + '' -'' TERM + '' -'' TERM '' -'' TERM * '' -'' TERM TERM TERM ? '' -'' TERM TERM * '' -'' LIST + '' -'' TERM + '' -'' TERM + '' -'' TERM + '' -'' ANYTERM ? '' -'' ANYTERM ? '' -'' TERM '' -'' TERM '' -'' ANYTERM '' +SET = '' ANYTERM '' +ADD = '' INTTERM + '' + | '' INTTERM + '' +SUB = '' INTTERM + '' + | '' INTTERM + '' +MUL = '' INTTERM + '' + | '' INTTERM + '' +DIB = '
' INTTERM + '
' + | '
' INTTERM + '
' +MOD = '' INTTERM INTTERM '' + | '' INTTERM '' +LOGAND = ' INTTERM + '' + | '' INTTERM + '' +LOGIOR = ' INTTERM + '' + | ' vname="' VNAME '">' INTTERM + '' +LOGXOR = ' INTTERM + '' + | ' vname="' VNAME '">' INTTERM + '' +LSH = '' INTTERM INTTERM '' + | '' INTTERM '' +LT = '' INTTERM INTTERM '' +LE = '' INTTERM INTTERM '' +EQ = '' INTTERM INTTERM '' +NOTEQ = '' INTTERM INTTERM '' +GE = '' INTTERM INTTERM '' +GT ='' INTTERM INTTERM '' +APPEND = '' ANYTERM + '' +CONCAT = '' [ INTTERM | STRTERM | LISTTERM ] + '' +LENGTH = '' [ STRTERM | LISTTERM ] '' +NTH = '' INTTERM [ STRTERM | LISTTERM ] '' +COPY = '' LISTTERM '' +INS = '' INTTERM [ STRTERM | LISTTERM ] '' +DEL = '' INTTERM INTTERM '' +AND = '' TERM + '' +OR = '' TERM + '' +NOT = '' TERM '' +PROGN = '' TERM * '' +IF = '' TERM TERM TERM ? '' +WHEN = '' TERM TERM * '' +COND = '' LIST + '' +LOOP = '' TERM + '' +WHILE = '' TERM + '' +FOREACH = '' TERM + '' +BREAK = '' ANYTERM ? '' +RETURN = '' ANYTERM ? '' +QUOTE = '' TERM '' +EVAL = '' TERM '' +TYPE = '' ANYTERM ''