Exemple #1
0
        private int c_lines;            // 行の数

        /// <summary>
        /// MultilineString の新しいインスタンスを生成します。
        /// </summary>
        /// <param name="text">何行何列目と何文字目の対応を付ける文字列を指定します。</param>
        public MultilineString(string text)
        {
            Gen::List <int> lines = new Gen::List <int>();

            lines.Add(0);
            bool lineend = false, cr = false;

            for (int i = 0, iM = text.Length; i < iM; i++)
            {
                if (text[i] == '\n')
                {
                    if (lineend && !cr)
                    {
                        lines.Add(i);                                  // 前の文字=='\n'
                    }
                    cr      = false;
                    lineend = true;
                }
                else if (lineend)
                {
                    // 前の文字== '\n' | '\r'
                    lines.Add(i);
                    cr = lineend = text[i] == '\r';
                }
            }
            this.c_lines = lines.Count;

            // 文字列の末尾
            lines.Add(text.Length);
            this.i_lines = lines.ToArray();

            this.str = text;
        }
Exemple #2
0
        void DiscardOld(System.DateTime referenceTime)
        {
            System.DateTime dthresh = referenceTime - TIMEOUT;
            if (this.oldestInfoTime > dthresh)
            {
                return;
            }

            lock (sync_root){
                System.DateTime oldest = System.DateTime.MaxValue;

                Gen::List <string> remove_key = new Gen::List <string>();
                foreach (Gen::KeyValuePair <string, FileInfo> pair in this.dicattr)
                {
                    System.DateTime infotime = pair.Value.informationTime;
                    if (infotime < dthresh)
                    {
                        remove_key.Add(pair.Key);
                    }
                    else if (infotime < oldest)
                    {
                        oldest = infotime;
                    }
                }
                foreach (string k in remove_key)
                {
                    this.dicattr.Remove(k);
                }

                remove_key.Clear();
                foreach (Gen::KeyValuePair <string, DirEntries> pair in this.diclist)
                {
                    System.DateTime infotime = pair.Value.informationTime;
                    if (infotime < dthresh)
                    {
                        remove_key.Add(pair.Key);
                    }
                    else if (infotime < oldest)
                    {
                        oldest = infotime;
                    }
                }
                foreach (string k in remove_key)
                {
                    this.diclist.Remove(k);
                }

                this.oldestInfoTime = oldest;
            }
        }
Exemple #3
0
 //========================================================
 private void parseCommand(ref Gen::List <INode> list)
 {
     try{
         list.Add(this.ProcessCommand(scanner.CurrentWord, scanner.Value));
     }catch (RegexParseException e) {
         this.scanner.LetterReader.SetError(e.Message, 0, null);
     }
     this.scanner.ReadNext();
 }
Exemple #4
0
 public void Add(IClassHandler handler, bool isSubtract)
 {
     if (handler == null)
     {
         return;
     }
     list.Add(handler);
     issub_list.Add(isSubtract);
 }
Exemple #5
0
        //===========================================================
        //		乗除
        //===========================================================
        public static Member operator*(Member l, Member r)
        {
            Gen::List <Variable> vars = new Gen::List <Variable>();
            int il = 0, ilM = l.vars.Length;
            int ir = 0, irM = r.vars.Length;

            while (il < ilM && ir < irM)
            {
                int val = Variable.VariableOrderWithoutExp(l.vars[il], r.vars[ir]);
                if (val < 0)
                {
                    vars.Add(l.vars[il++]);
                }
                else if (val > 0)
                {
                    vars.Add(r.vars[ir++]);
                }
                else
                {
                    Variable v = l.vars[il++] * r.vars[ir++];
                    if (!v.IsConstant)
                    {
                        vars.Add(v);
                    }
                }
            }

            if (il < ilM)
            {
                do
                {
                    vars.Add(l.vars[il++]);
                }while(il < ilM);
            }
            else if (ir < irM)
            {
                do
                {
                    vars.Add(r.vars[ir++]);
                }while(ir < irM);
            }

            return(new Member(l.factor * r.factor, vars.ToArray()));
        }
Exemple #6
0
        public static Expression operator-(Expression l, Expression r)
        {
            Gen::List <Member> mems = new Gen::List <Member>();
            int il = 0, ilM = l.mems.Count;
            int ir = 0, irM = r.mems.Count;

            while (il < ilM && ir < irM)
            {
                int val = Member.MemberOrder(l.mems[il], r.mems[ir]);
                if (val < 0)
                {
                    mems.Add(l.mems[il++]);
                }
                else if (val > 0)
                {
                    mems.Add(-r.mems[ir++]);
                }
                else
                {
                    Member m = l.mems[il++] - r.mems[ir++];
                    if (!m.IsZero)
                    {
                        mems.Add(m);
                    }
                }
            }

            if (il < ilM)
            {
                do
                {
                    mems.Add(l.mems[il++]);
                }while(il < ilM);
            }
            else if (ir < irM)
            {
                do
                {
                    mems.Add(-r.mems[ir++]);
                }while(ir < irM);
            }

            return(new Expression(mems));
        }
Exemple #7
0
        /// <summary>
        /// path で指定したディレクトリの内容を読み取って、情報を更新します。
        /// </summary>
        /// <param name="rpath">目的のディレクトリを示すパスを指定します。</param>
        /// <exception cref="Tamir.SharpSsh.jsch.SftpException">
        /// 読み取りに失敗した場合に発生します。</exception>
        Gen::List <FileInfo> UpdateList(string rpath)
        {
            // 情報取得
            session.Message.Write(1, "$ ls {0}", rpath);
            java::util.Vector entries;
            try{
                entries = session.Sftp.noglob_ls(rpath);
            }catch (Tamir.SharpSsh.jsch.SftpException e) {
                switch ((Unix.SSH_ERROR)e.id)
                {
                case mwg.Unix.SSH_ERROR.NO_SUCH_FILE:
                case mwg.Unix.SSH_ERROR.NO_SUCH_PATH:
                    session.Message.Write(1, "! ls: not found {0}", rpath);
                    ficache.SetList(rpath, null); // "存在しない"
                    return(null);

                default:
                    throw;
                }
            }

            // 結果登録
            string dir = rpath;

            if (!dir.EndsWith("/"))
            {
                dir += "/";
            }

            System.DateTime      now  = System.DateTime.Now;
            Gen::List <FileInfo> list = new Gen::List <FileInfo>();

            foreach (Tamir.SharpSsh.jsch.ChannelSftp.LsEntry entry in entries)
            {
                //string filename=mwg.Unix.UnixPath.QuoteWildcard(entry.getFilename());
                string filename = entry.getFilename();
                if (filename == ".")
                {
                    string   filepath = rpath;
                    FileInfo info     = this.CreateFileInfo(filepath, entry.getAttrs(), now);
                    this.ficache.SetFile(info);
                }
                else if (filename == "..")
                {
                    continue;
                }
                else
                {
                    string   filepath = dir + filename;
                    FileInfo info     = this.CreateFileInfo(filepath, entry.getAttrs(), now);
                    list.Add(info);
                }
            }
            this.ficache.SetList(rpath, list);
            return(list);
        }
Exemple #8
0
        static ConnectionInfo CreateConnectionInfo(SshUserData data)
        {
            // create Authentication methods
            Gen::List <AuthenticationMethod> auth = new Gen::List <AuthenticationMethod>();

            if (data.pass != null && data.pass != "")
            {
                // Password based Authentication
                auth.Add(new PasswordAuthenticationMethod(data.user, data.pass));
            }
            if (data.useIdentityFile && data.idtt != "")
            {
                // Key Based Authentication (using keys in OpenSSH Format)
                auth.Add(new PrivateKeyAuthenticationMethod(data.user, new PrivateKeyFile[] {
                    new PrivateKeyFile(data.idtt, data.psph)
                }));
            }
            return(new ConnectionInfo(data.host, data.port, data.user, auth.ToArray()));
        }
Exemple #9
0
        public static int RegisterColor(string name, Color color)
        {
            name = name.ToLower();
            int index = c_names.Count;

            c_indices.Add(name, index);            // 重複があれば茲で例外
            c_names.Add(name);
            c_values.Add(color);
            return(index);
        }
Exemple #10
0
        public static Expression operator*(Member m, Expression x)
        {
            Gen::List <Member> list = new Gen::List <Member>();

            foreach (Member m1 in x.mems)
            {
                list.Add(m * m1);
            }
            list.Sort(Member.MemberOrderComparer);
            return(new Expression(list));
        }
Exemple #11
0
        //=================================================
        //		Preprocess Directives
        //=================================================
        private string PreprocessDirectives(string text)
        {
            Gen::Dictionary <int, string> errors = new Gen::Dictionary <int, string>();
            Gen::List <DefineMacro>       defs   = new Gen::List <DefineMacro>();

            DefineMacro def;
            string      text2 = reg_directive.Replace(text, delegate(System.Text.RegularExpressions.Match m){
                if (m.Groups["nspace"].Success)
                {
                    if (this.@namespace != null)
                    {
                        errors.Add(m.Index, "名前空間を複数指定する事は出来ません。");
                    }
                    this.@namespace = m.Groups["nspace"].Value;
                }
                else if (m.Groups["class"].Success)
                {
                    if (this.classname != null)
                    {
                        errors.Add(m.Index, "クラス名を複数指定する事は出来ません。");
                    }
                    this.classname = m.Groups["class"].Value;
                }
                else if (m.Groups["defname"].Success)
                {
                    def         = new DefineMacro();
                    def.name    = m.Groups["defname"].Value;
                    def.Content = m.Groups["defcontent"].Value;

                    // 引数リスト
                    System.Text.RegularExpressions.CaptureCollection capts = m.Groups["defarg"].Captures;
                    int iM   = capts.Count;
                    def.args = new string[capts.Count];
                    for (int i = 0; i < iM; i++)
                    {
                        def.args[i] = capts[i].Value;
                    }

                    defs.Add(def);
                }
                return(reg_remove.Replace(m.Value, ""));
            });

            foreach (DefineMacro define in defs)
            {
                define.Apply(ref text2);
            }

            return(text2);
        }
Exemple #12
0
            //========================================================
            /// <summary>
            /// '|' で区切られた候補達を読み取ります。
            /// </summary>
            /// <returns>読み取って出来たノードを返します。有効な正規表現指定が見つからなかった場合には null を返します。</returns>
            private INode Read()
            {
                Gen::List <INode> nodes = new Gen::List <INode>();

                while (true)
                {
                    switch (this.scanner.CurrentType.value)
                    {
                    case WordType.vInvalid:
                        goto ED_LOOP;

                    case WordType.vOperator:
                        if (scanner.CurrentWord == ")")
                        {
                            goto ED_LOOP;
                        }
                        else if (scanner.CurrentWord == "|")
                        {
                            this.scanner.ReadNext();
                            goto default;
                        }
                        else
                        {
                            goto default;
                        }

                    default:
                        INode node = this.ReadSequence();
                        if (node == null)
                        {
                            scanner.LetterReader.SetError("正規表現要素が一つもありません。", 0, null);
                            break;
                        }

                        nodes.Add(node);
                        break;
                    }
                }
ED_LOOP:
                if (nodes.Count == 0)
                {
                    return(null);
                }
                if (nodes.Count == 1)
                {
                    return(nodes[0]);
                }
                return(new OrNode(nodes.ToArray()));
            }
Exemple #13
0
        //--------------------------------------------------------------------------
        private void DiscardOld()
        {
            System.DateTime dthresh = System.DateTime.Now - TIMEOUT;
            if (this.dt_discard > dthresh)
            {
                return;
            }

            lock (sync_root){
                Gen::List <string> remove_key = new Gen::List <string>();
                foreach (Gen::KeyValuePair <string, SftpFileInfo> pair in this.dicattr)
                {
                    if (pair.Value.infodate < dthresh)
                    {
                        remove_key.Add(pair.Key);
                    }
                }
                foreach (string k in remove_key)
                {
                    this.dicattr.Remove(k);
                }

                remove_key.Clear();
                foreach (Gen::KeyValuePair <string, lsres_t> pair in this.diclist)
                {
                    if (pair.Value.date < dthresh)
                    {
                        remove_key.Add(pair.Key);
                    }
                }
                foreach (string k in remove_key)
                {
                    this.diclist.Remove(k);
                }
            }
        }
Exemple #14
0
        public void StopProcess()
        {
            if (locked_threads != null)
            {
                return;
            }

            locked_threads = new System.Collections.Generic.List <Thread>();
            foreach (ProcessThread th in this.process.Threads)
            {
                Thread thread = new Thread(th.Id);
                thread.Suspend();
                locked_threads.Add(thread);
            }
        }
Exemple #15
0
 //-----------------------------------------------------
 public void AddLine(Line line)
 {
     if (line.parent != null)
     {
         if (line.parent == this)
         {
             this.RotateU(line.index, lines.Count);
         }
         else
         {
             line.parent.RemoveLine(line);
         }
     }
     line.parent = this;
     line.index  = lines.Count;
     lines.Add(line);
 }
Exemple #16
0
        public string[] splitModifiers(string mod)
        {
            Gen::List <string> list = new Gen::List <string>();

            string[] cands = mod.Split('.');
            string   cand;

            for (int i = 0; i < cands.Length; i++)
            {
                cand = cands[i].Trim();
                if (cand != "")
                {
                    list.Add(cand);
                }
            }
            return(list.ToArray());
        }
Exemple #17
0
        /// <summary>
        /// 指定した file-directory 内の画像をこの ImageDirectory に登録します。
        /// </summary>
        /// <param name="dirpath">登録する画像を含んでいるディレクトリへの path を指定します。</param>
        public void AddFilesFromDirectory(string dirpath)
        {
            if (!System.IO.Directory.Exists(dirpath))
            {
                return;
            }

            System.IO.DirectoryInfo dir       = new System.IO.DirectoryInfo(dirpath);
            Gen::List <string>      filepaths = new Gen::List <string>();

            foreach (System.IO.FileInfo file in dir.GetFiles())
            {
                if (!exts.Contains(file.Extension.ToLower()))
                {
                    continue;
                }
                filepaths.Add(file.FullName);
            }
            if (filepaths.Count == 0)
            {
                return;
            }

            afh.Forms.ProgressDialog progress = new afh.Forms.ProgressDialog();
            progress.Title       = "画像を読込中 ...";
            progress.ProgressMax = filepaths.Count;
            progress.Show();
            // 読込
            foreach (string path in filepaths)
            {
                try{
                    progress.Description = "画像 " + path + " を読み込んでいます...";
                    this.AddFile(path);
                    progress.Progress++;
                    if (progress.IsCanceled)
                    {
                        break;
                    }
                }catch (System.Exception e) {
                    afh.File.__dll__.log.WriteError(e, path + " の読込に失敗しました。");
                }
            }
            progress.Close();
        }
Exemple #18
0
        /// <summary>
        /// 指定したパスを結合し、.. や . 等の指定を含む場合にはそれらを解決します。
        /// </summary>
        /// <param name="path1">先に来るパスを指定します。</param>
        /// <param name="path2">後にくるパスを指定します。</param>
        /// <returns>結合した後のパスを返します。</returns>
        public static string Combine(string path1, string path2)
        {
            string path0 = System.IO.Path.Combine(path1, path2);

            if (path0.IndexOf("..") < 0)
            {
                return(path0);
            }

            //-- 正規化
            string[]           paths  = path0.TrimEnd('\\', '/').Split('\\', '/');
            Gen::List <string> paths2 = new Gen::List <string>();

            System.Text.StringBuilder r = new System.Text.StringBuilder();
            for (int i = 0; i < paths.Length; i++)
            {
                if (paths[i] == "..")
                {
                    if (paths2.Count == 0)
                    {
                        r.Append(@"..\");
                    }
                    else
                    {
                        paths2.RemoveAt(paths2.Count - 1);
                    }
                }
                else if (paths[i] != ".")
                {
                    paths2.Add(paths[i]);
                }
            }
            foreach (string x in paths2.ToArray())
            {
                r.Append(x); r.Append(@"\");
            }
            ;

            string r2 = r.ToString();

            return(r2 == ""?".":r2.TrimEnd('\\'));
        }
Exemple #19
0
        public Gen::List <SftpFileInfo> SetList(string path, java::util.Vector entries)
        {
            string dir = path;

            if (!dir.EndsWith("/"))
            {
                dir += "/";
            }

            System.DateTime          dt   = System.DateTime.Now;
            Gen::List <SftpFileInfo> list = new Gen::List <SftpFileInfo>();

            foreach (jsch::ChannelSftp.LsEntry entry in entries)
            {
                string filename = entry.getFilename();
                if (filename == ".")
                {
                    string       filepath = path;
                    SftpFileInfo item     = new SftpFileInfo(operation, filepath, entry.getAttrs(), dt);
                    this.InternalSetAttr(item);
                }
                else if (filename == "..")
                {
                    continue;
                }
                else
                {
                    string       filepath = dir + filename;
                    SftpFileInfo item     = new SftpFileInfo(operation, filepath, entry.getAttrs(), dt);
                    list.Add(item);
                    this.InternalSetAttr(item);
                }
            }
            diclist[path] = new lsres_t(list, dt);

            this.DiscardOld();
            return(list);
        }
Exemple #20
0
        public void SetList(string path, Gen::IEnumerable <FileInfo> entries)
        {
            string dir = path;

            if (!dir.EndsWith("/"))
            {
                dir += "/";
            }

            System.DateTime now = System.DateTime.Now;
            lock (this.sync_root){
                Gen::List <FileInfo> list = null;
                if (entries != null)
                {
                    list = new Gen::List <FileInfo>();
                    foreach (FileInfo info in entries)
                    {
                        dicattr[info.InternalPath] = info;
                        if (info.InternalPath != path)
                        {
                            list.Add(info);
                        }
                        if (info.informationTime < this.oldestInfoTime)
                        {
                            this.oldestInfoTime = info.informationTime;
                        }
                    }
                }
                diclist[path] = new DirEntries(list, now);
                if (now < this.oldestInfoTime)
                {
                    this.oldestInfoTime = now;
                }
            }

            this.DiscardOld();
        }
Exemple #21
0
 public Arguments()
 {
     // 一個要素を追加
     args_rev.Add(null);
 }
Exemple #22
0
    public static string ProcessSource(string input, Argument _args)
    {
        string   output = input;
        Argument args   = _args;

        // directives の読み取り
        Gen::Dictionary <string, string> tokenmap = new Gen::Dictionary <string, string>();
        Gen::List <ReplaceData>          replaces = new Gen::List <ReplaceData>();

        output = reg_gzjs_directive.Replace(output, delegate(Rgx::Match m) {
            // 先頭以外に改行が入っている物は無効
            if (0 < m.Value.IndexOfAny("\r\n".ToCharArray()))
            {
                return(m.Value);
            }

            switch (m.Groups["dir"].Value)
            {
            case "outfile": {
                string dirname  = System.IO.Path.GetDirectoryName(args.OutputFile);
                args.OutputFile = System.IO.Path.Combine(dirname, ReadArg(m.Groups["arg1"]));
                if (args.Verbose)
                {
                    args.WriteLine("#> output-file was set to '" + args.OutputFile + "'");
                }
                return("\n");
            }

            case "tokenmap": {
                string before    = ReadArg(m.Groups["arg1"]);
                string after     = ReadArg(m.Groups["arg2"]);
                tokenmap[before] = after;
                if (args.Verbose)
                {
                    args.WriteLine("#> token-mapping registered: " + before + " -> " + after + "");
                }
                return("\n");
            }

            case "replace": {
                string before = ReadArg(m.Groups["arg1"]);
                string after  = ReadArg(m.Groups["arg2"]);
                replaces.Add(new ReplaceData(before, after));
                if (args.Verbose)
                {
                    args.WriteLine("#> replace registered: " + before + " -> " + after + "");
                }
                return("\n");
            }

            case "include": {
                if (args.Verbose)
                {
                    args.WriteLine("#gzjs-include");
                }
                return(Program.Include(ReadArg(m.Groups["arg1"]), args) ?? m.Value);
            }

            case "option": {
                string op = ReadArg(m.Groups["arg1"]);
                if (!args.ReadOption(op))
                {
                    args.WriteLine("#gzjs-option > '{0}' は認識できない option です", op);
                    return(m.Value);
                }
                return("\n");
            }

            default:
                return(m.Value);
            }
        });

        // コメント空白類の削除
        if (args.CutComment)
        {
            output = RegExp.CutComment(output);
        }

        // token 置き換え
        if (tokenmap.Count > 0)
        {
            string rex = null;
            foreach (string token in tokenmap.Keys)
            {
                if (rex == null)
                {
                    rex = token;
                }
                else
                {
                    rex += "|" + token;
                }
            }
            rex    = @"\b(?:" + rex + @")\b";
            output = new Rgx::Regex(rex).Replace(output, delegate(Rgx::Match m) {
                return(tokenmap[m.Value]);
            });
        }

        // #gzjs-replace 実行
        foreach (ReplaceData r in replaces)
        {
            output = r.Replace(output);
        }

        return(output);
    }
Exemple #23
0
            private System.Predicate <char> CreateHandler(
                bool positive, IClassHandler[] handlers, bool[] issub,
                out IClassHandler[] child
                )
            {
                int[] borders;
                {
                    Gen::List <int> borders_l = new System.Collections.Generic.List <int>();
                    bool            current   = true;
                    for (int i = 0; i < issub.Length; i++)
                    {
                        if (issub[i] == current)
                        {
                            continue;
                        }
                        borders_l.Add(i);                         // *
                        current = issub[i];
                    }
                    // issub: [F T T T F F T T F T F F F T T T ]
                    // brdrs:    *     *   *   * * *     *     @

                    borders_l.Add(issub.Length);                     // @
                    borders = borders_l.ToArray();
                }

                afh.Reflection.DynamicMethodCreater <CompiledClassHandler, System.Predicate <char> > gh
                    = new afh.Reflection.DynamicMethodCreater <CompiledClassHandler, System.Predicate <char> >("<generated>", false);

                Gen::List <IClassHandler> child_l = new Gen::List <IClassHandler>();

                Emit::Label label = gh.CreateLabel();

                for (int k = 0, kM = borders.Length - 1; k < kM; k++)
                {
                    for (int i = borders[k]; i < borders[k + 1]; i++)
                    {
                        //-- それぞれのハンドラに応じた処理
                        // 判定陽性 → goto label;
                        // 判定陰性 → その儘次へ流れる
                        if (!handlers[i].Emit(gh, label))
                        {
                            // child リストから呼び出す場合
                            int iChild = child_l.Count;
                            child_l.Add(handlers[i]);

                            // (s1)= this.child[iChild]
                            gh.EmitLdarg(0);
                            gh.EmitLdfld(typeof(CompiledClassHandler), "child", false, true);
                            gh.EmitLdc(iChild);
                            gh.EmitLdelem(typeof(IClassHandler));

                            // if((s1).Judge(c))goto label;
                            gh.EmitLdarg(1);
                            gh.EmitCall(handlers[i].GetType(), false, false, "Judge", typeof(char));
                            gh.EmitBrtrue(label);
                        }
                    }

                    // もう終わる時
                    if (k + 1 == kM)
                    {
                        break;
                    }
                    else
                    {
                        Emit::Label newlabel = gh.CreateLabel();
                        gh.EmitBr(newlabel);
                        gh.MarkLabel(label);
                        label = newlabel;

                        positive = !positive;
                    }
                }
                gh.EmitLdc(!positive);
                gh.EmitRet();
                gh.MarkLabel(label);
                gh.EmitLdc(positive);
                gh.EmitRet();

                child = child_l.ToArray();

                return(gh.Instantiate(this));
            }
Exemple #24
0
 public void AddDelim(string d)
 {
     delims.Add(d);
     args_rev.Add(null);
     index++;
 }
Exemple #25
0
        private static void initialize_judgeNest()
        {
            //----------------------------------------------------------------------
            // 親要素になる事の出来ない要素のリストを作成します。
            //----------------------------------------------------------------------
            judgeNest_denyList.Add("meta");
            judgeNest_denyList.Add("link");
            judgeNest_denyList.Add("br");
            judgeNest_denyList.Add("hr");
            judgeNest_denyList.Add("img");
            judgeNest_denyList.Add("col");
            judgeNest_denyList.Add("embed");
            judgeNest_denyList.Add("param");
            judgeNest_denyList.Add("area");
            judgeNest_denyList.Add("keygen");
            judgeNest_denyList.Add("source");
            judgeNest_denyList.Add("base");

            //----------------------------------------------------------------------
            // 子要素として持つ事が出来ない要素のリストを作成します。
            //----------------------------------------------------------------------
            // block element
            System.Collections.Generic.List <string> blockElements = new System.Collections.Generic.List <string>(new string[] {
                "p", "div", "h1", "h2", "h3", "h4", "h5", "h6",
                "dl", "ol", "ul", "table", "address", "blockquote", "center",
                "pre", "xmp", "listing", "plaintext"
            });
            judgeNest_denyTable.Add("p", blockElements);
            judgeNest_denyTable.Add("h1", blockElements);
            judgeNest_denyTable.Add("h2", blockElements);
            judgeNest_denyTable.Add("h3", blockElements);
            judgeNest_denyTable.Add("h4", blockElements);
            judgeNest_denyTable.Add("h5", blockElements);
            judgeNest_denyTable.Add("h6", blockElements);
            judgeNest_denyTable.Add("address", blockElements);

            judgeNest_denyTable.Add("li", new Gen::List <string>(new string[] { "li" }));

            // dictionary element
            Gen::List <string> list = new Gen::List <string> {
                "dt", "dd"
            };

            list.AddRange(blockElements);
            judgeNest_denyTable.Add("dt", list);
            judgeNest_denyTable.Add("dd", list);

            // table element
            list = new System.Collections.Generic.List <string>(new string[] { "thead", "tbody", "tfoot" });
            judgeNest_denyTable.Add("thead", list);
            judgeNest_denyTable.Add("tbody", list);
            judgeNest_denyTable.Add("tfoot", list);
            list = new System.Collections.Generic.List <string>(new string[] { "tr", "thead", "tbody", "tfoot" });
            judgeNest_denyTable.Add("tr", list);
            judgeNest_denyTable.Add("caption", list);
            list = new System.Collections.Generic.List <string>(new string[] { "td", "th", "tr", "thead", "tbody", "tfoot" });
            judgeNest_denyTable.Add("td", list);
            judgeNest_denyTable.Add("th", list);

            // ruby element
            list = new System.Collections.Generic.List <string>(new string[] { "rb", "rt", "rp" });
            judgeNest_denyTable.Add("rb", list);
            judgeNest_denyTable.Add("rt", list);
            judgeNest_denyTable.Add("rp", list);
        }
Exemple #26
0
  public static string ProcessSource(string input,Argument _args){
    string output=input;
    Argument args=_args;
    string dirname=System.IO.Path.GetDirectoryName(args.OutputFile);

    // directives の読み取り
    Gen::Dictionary<string,string> tokenmap=new Gen::Dictionary<string,string>();
    Gen::List<ReplaceData> replaces=new Gen::List<ReplaceData>();

    output=reg_gzjs_directive.Replace(output,delegate(Rgx::Match m){
      // 先頭以外に改行が入っている物は無効
      if(0<m.Value.IndexOfAny("\r\n".ToCharArray()))return m.Value;
      
      switch(m.Groups["dir"].Value){
      case "outfile":
        args.OutputFile=System.IO.Path.Combine(
          System.IO.Path.GetDirectoryName(args.OutputFile),
          ReadArg(m.Groups["arg1"])
        );
        if(args.Verbose)
          args.WriteLine("#> output-file was set to '"+args.OutputFile+"'");
        return "\n";
      case "tokenmap":{
        string before=ReadArg(m.Groups["arg1"]);
        string after=ReadArg(m.Groups["arg2"]);
        tokenmap[before]=after;
        if(args.Verbose)
          args.WriteLine("#> token-mapping registered: "+before+" -> "+after+"");
        return "\n";
      }
      case "replace":{
        string before=ReadArg(m.Groups["arg1"]);
        string after=ReadArg(m.Groups["arg2"]);
        replaces.Add(new ReplaceData(before,after));
        if(args.Verbose)
          args.WriteLine("#> replace registered: "+before+" -> "+after+"");
        return "\n";
      }
      case "include":{
        if(args.Verbose)
          args.WriteLine("#gzjs-include");
        return Program.Include(ReadArg(m.Groups["arg1"]),args)??m.Value;
      }
      case "option":{
        string op=ReadArg(m.Groups["arg1"]);
        if(!args.ReadOption(op)){
          args.WriteLine("#gzjs-option > '{0}' は認識できない option です",op);
          return m.Value;
        }
        return "\n";
      }
      default:
        return m.Value;
      }
    });

    // コメント空白類の削除
    if(args.CutComment)
      output=RegExp.CutComment(output);

    // token 置き換え
    if(tokenmap.Count>0){
      string rex=null;
      foreach(string token in tokenmap.Keys){
        if(rex==null)rex=token;else rex+="|"+token;
      }
      rex=@"\b(?:"+rex+@")\b";
      output=new Rgx::Regex(rex).Replace(output,delegate(Rgx::Match m){
        return tokenmap[m.Value];
      });
    }

    // #gzjs-replace 実行
    foreach(ReplaceData r in replaces)
      output=r.Replace(output);

    return output;
  }
Exemple #27
0
    byte[] ZipDeflate(byte[] str,int level)
    {
        int i,j;

        deflate_data=str;
        deflate_pos=0;
        deflate_start(level);

        byte[] buff=new byte[1024];
        Gen::List<byte> @out=new Gen::List<byte>();
        while((i=deflate_internal(buff,0,buff.Length))>0){
            for(j=0;j<i;j++)@out.Add(buff[j]);
        }
        deflate_data=null;// G.C.
        return @out.ToArray();
    }
Exemple #28
0
            /// <summary>
            /// 要素連続部分 ('|' '(' ')' などで区切られた部分) を読み取ります。
            /// </summary>
            /// <returns>読み取って出来たノードを返します。有効な正規表現指定が見つからなかった場合には null を返します。</returns>
            private INode ReadSequence()
            {
                Gen::List <INode> nodes = new Gen::List <INode>();

                while (true)
                {
                    switch (this.scanner.CurrentType.value)
                    {
                    case WordType.vInvalid:
                        goto ED_LOOP;

                    case WordType.vComment:                     // (?#)
                        this.scanner.ReadNext();
                        continue;

                    case RegexScannerA.WT_CHARCLASS:                     // [文字クラス]
                        nodes.Add(this.ProcessClass(this.scanner.CurrentWord));
                        this.scanner.ReadNext();
                        break;

                    case RegexScannerA.WT_COMMAND:                     // コマンド
                        parseCommand(ref nodes);
                        break;

                    case RegexScannerA.WT_COMMAND_C:                     // : コマンド
                        nodes.Add(this.ProcessCommandC(scanner.CurrentWord, scanner.Value));
                        this.scanner.ReadNext();
                        break;

                    case WordType.vSuffix:                     // ? + *
                        parseSuffix(ref nodes);
                        break;

                    case WordType.vOperator:                     // ( | )
                        if (scanner.CurrentWord == ")" || scanner.CurrentWord == "|")
                        {
                            goto ED_LOOP;
                        }
                        if (scanner.CurrentWord == "(?flags)")
                        {
                            // 括弧の始まる前に flags を覚えておく仕組み
                            __debug__.RegexParserToDo("未実装");
                        }
                        INode node = parseOperator();
                        if (node != null)
                        {
                            nodes.Add(node);
                        }
                        break;

                    case WordType.vText:                     // 通常の文字
                        switch (scanner.CurrentWord[0])
                        {
                        case '.': nodes.Add(AnyElemNode.Instance); break;

                        case '^': nodes.Add(StartOfStreamNode.instance); break;

                        case '$': nodes.Add(EndOfStreamNode.instance); break;

                        default:
                            nodes.Add(this.ProcessLetter(scanner.CurrentWord[0]));
                            break;
                        }
                        this.scanner.ReadNext();
                        break;
                    }
                }
ED_LOOP:
                if (nodes.Count == 0)
                {
                    return(null);
                }
                if (nodes.Count == 1)
                {
                    return(nodes[0]);
                }
                return(new SequenceNode(nodes.ToArray()));
            }
Exemple #29
0
        public override bool TryParse(Word w, Parser p)
        {
            Gen::List <Tree.IExpression> args_rev = new Gen::List <Tree.IExpression>();

            // 始まりの括弧が見つかる迄
            StartArgsMarker m = p.Stack.Peek() as StartArgsMarker;
            int             c = -1;

            if (m == null)
            {
                args_rev.Add(null);
                c++;
            }
            while (m == null && !p.Stack.IsEmpty)
            {
                if (p.Stack.IsTopExpression)
                {
                    args_rev[c] = p.Stack.PopOperand(-1, false).Expression;

                    // 区切り?
                    DelimArgsMarker d = p.Stack.Peek() as DelimArgsMarker;
                    if (d != null)
                    {
                        args_rev.Add(null); c++;
                        continue;
                    }

                    // 始まりの括弧?
                    m = p.Stack.Peek() as StartArgsMarker;
                    if (m != null)
                    {
                        continue;
                    }

                    p.ReportError(w, "引数と引数の間に区切りが入っていない可能性があります。");
                    continue;
                }

                if (p.Stack.IsTopPrefix)
                {
                    // Prefix の適用先が見つからない
                    return(false);
                }

                break;
            }

            if (m != null)
            {
                p.Stack.Pop();
                p.PopContext();

#if PAREN_MATCH
                if (m.StartParen != this.start_paren)
                {
                    // ※ 区間などの場合には始まりと終わりが食い違っても OK
                    p.ReportError(w, "始まりの括弧と終わりの括弧が一致しません。");
                    return(true);
                }
#endif

                p.Stack.Push(new ExpressionElement(
                                 new Tree.FunctionCallExpression(
                                     start_paren + w.word,
                                     m.FunctionExpression,
                                     GetArguments(args_rev)
                                     )
                                 ));
                return(true);
            }
            else
            {
                p.ReportError(w, "対応する始まりの括弧が存在しません。");
                return(true);
            }
        }
        //============================================================
        //	初期化
        //============================================================
        public AttributeCollection(LanguageWriter writer, ICustomAttributeProvider provider, IType type)
        {
            this.writer   = writer;
            this.provider = provider;
            this.type     = type;

            // 属性の対象
            if (provider is IAssembly)
            {
                attr_class    = "assembly";
                isAsmOrModule = true;
            }
            else if (provider is IModule)
            {
                attr_class    = "module";
                isAsmOrModule = true;
            }
            else if (provider is IMethodReturnType)
            {
                attr_class = "returnvalue";
            }

            // 個々の属性に対して走査
            foreach (ICustomAttribute attr in provider.Attributes)
            {
                if (attr == null)
                {
                    continue;
                }

                string attrname = GetCustomAttributeName(attr);
                switch (attrname)
                {
                case "ParamArray":
                case "System::ParamArray":
                    containsParams = true;
                    continue;

                case "MarshalAs":
                case "System::Runtime::InteropServices::MarshalAs":
                    IExpressionCollection arguments = attr.Arguments;
                    if (arguments == null)
                    {
                        break;
                    }
                    IFieldReferenceExpression exp_fld = arguments[0] as IFieldReferenceExpression;
                    if (exp_fld == null)
                    {
                        break;
                    }
                    ITypeReferenceExpression target = exp_fld.Target as ITypeReferenceExpression;
                    if (target == null || target.Type.Name != "UnmanagedType")
                    {
                        break;
                    }
                    IFieldReference field = exp_fld.Field;
                    if (field.Name == "U1")
                    {
                        if (LanguageWriter.Type(type, "System", "Boolean"))
                        {
                            continue;
                        }
                    }
                    else if (field.Name == "U2" && LanguageWriter.Type(type, "System", "Char"))
                    {
                        continue;
                    }
                    break;
                }

                attrs.Add(new AttrPair(attrname, attr));
            }

            // 名前空間順に並び替え
            attrs.Sort(delegate(AttrPair l, AttrPair r){
                string l_name = ((ITypeReference)l.Value.Constructor.DeclaringType).Namespace;
                string r_name = ((ITypeReference)r.Value.Constructor.DeclaringType).Namespace;
                return(l_name.CompareTo(r_name));
            });
        }
            //----------------------------------------------------------------------
            public void Balance()
            {
                if (this.level < 2)
                {
                    return;
                }
                // level==2
                //   □
                //   □    □  □
                //   1 5 3 2 4 5 2 4 ... 調整出来る。
                // level==1
                //   □
                //   5 4 8 ... LLIMIT/ULIMIT で制限されているので調整不要

//%%if IsEx==0 (
#if DEBUG
                Test.dbg_nbalance++;
#endif

//%%)
                // 必要性判定
                float min = float.MaxValue;
                float max = 0;
                for (int i = 0, iN = this.data.Count; i < iN; i++)
                {
                    int w = this.data[i].weight;
                    if (w < min)
                    {
                        min = w;
                    }
                    if (w > max)
                    {
                        max = w;
                    }
                }
                if (min * BALANCE > max)
                {
                    return;
                }

//%%if IsEx==0 (
#if DEBUG
                Test.dbg_nbalance++;
#endif

//%%)
                // 孫要素回収
                int ngrand = 0;
                for (int i = 0, iN = this.data.Count; i < iN; i++)
                {
                    ngrand += ((Node1)this.data[i]).data.Count;
                }
                Gen::List <Node> grands = new Gen::List <Node>(ngrand);
                {
                    for (int i = 0, iN = this.data.Count; i < iN; i++)
                    {
                        Node1 node = (Node1)this.data[i];
                        for (int j = 0, jN = node.data.Count; j < jN; j++)
                        {
                            grands.Add(node.data[j]);
                        }

                        node.data.Clear();
                        node.weight = 0;
                    }
                }

                // 再配置
                {
                    int    s = 0;
                    double n = (double)this.weight / this.data.Count;

                    int   i    = 0;
                    int   sN   = (int)n;
                    Node1 node = (Node1)this.data[0];
                    for (int index = 0; index < this.weight; index++)
                    {
                        if (s >= sN)
                        {
                            if (++i >= this.data.Count)
                            {
                                break;
                            }
                            node = (Node1)this.data[i];
                            sN   = (int)((i + 1) * n);
                        }

                        Node grand = grands[index];
                        grand.parent = node;
                        grand.index  = node.data.Count;
                        node.weight += grand.weight;
                        node.data.Add(grand);

                        s += grand.weight;
                    }
                }
            }
Exemple #32
0
 public void Add(System.IDisposable value)
 {
     lock (list) list.Add(value);
 }