Esempio n. 1
0
 /// <summary>
 /// context の分岐標を読み取ります。
 /// </summary>
 private void ReadContextConditions()
 {
     if ("is:}")
     {
         this.wtype = WordType.Operator;
         this.mode  = WordReaderMode.Plain;
         add; nexit;
     }
     else if ("is::")
     {
         this.wtype = WordType.Operator;
         this.mode  = WordReaderMode.ContextCommands;
         add; nexit;
     }
     else
     {
         do
         {
             if ("is:\\")
             {
                 next;
             }
             add; next;
             if ("is::" || "is:}" || type.IsInvalid || type.IsSpace || this.IsComment())
             {
                 return;
             }
         }while(true);
     }
 }
Esempio n. 2
0
 //=================================================
 //		read context
 //=================================================
 /// <summary>
 /// Context の宣言部を読み取ります。
 /// </summary>
 private void ReadContextDeclaration()
 {
     // context の内容の始まり
     if ("is:{")
     {
         this.wtype = WordType.Operator;
         this.mode  = WordReaderMode.ContextConditions;
         add; nexit;
     }
     // その他の場合
     do
     {
         add; next;
         if ("is:{" || type.IsInvalid || type.IsSpace || this.IsComment())
         {
             return;
         }
     }while(true);
 }
 //=================================================
 //		read context
 //=================================================
 /// <summary>
 /// Context の宣言部を読み取ります。
 /// </summary>
 private void ReadContextDeclaration()
 {
     // context の内容の始まり
     if ((this.lreader.CurrentLetter == '{'))
     {
         this.wtype  = WordType.Operator;
         this.mode   = WordReaderMode.ContextConditions;
         this.cword += this.lreader.CurrentLetter; { this.lreader.MoveNext(); return; }
     }
     // その他の場合
     do
     {
         this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
         {
             return;
         }
         if ((this.lreader.CurrentLetter == '{') || this.lreader.CurrentType.IsInvalid || this.lreader.CurrentType.IsSpace || this.IsComment())
         {
             return;
         }
     }while(true);
 }
 /// <summary>
 /// context の分岐標を読み取ります。
 /// </summary>
 private void ReadContextConditions()
 {
     if ((this.lreader.CurrentLetter == '}'))
     {
         this.wtype  = WordType.Operator;
         this.mode   = WordReaderMode.Plain;
         this.cword += this.lreader.CurrentLetter; { this.lreader.MoveNext(); return; }
     }
     else if ((this.lreader.CurrentLetter == ':'))
     {
         this.wtype  = WordType.Operator;
         this.mode   = WordReaderMode.ContextCommands;
         this.cword += this.lreader.CurrentLetter; { this.lreader.MoveNext(); return; }
     }
     else
     {
         do
         {
             if ((this.lreader.CurrentLetter == '\\'))
             {
                 if (!this.lreader.MoveNext())
                 {
                     return;
                 }
             }
             this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
             {
                 return;
             }
             if ((this.lreader.CurrentLetter == ':') || (this.lreader.CurrentLetter == '}') || this.lreader.CurrentType.IsInvalid || this.lreader.CurrentType.IsSpace || this.IsComment())
             {
                 return;
             }
         }while(true);
     }
 }
        /// <summary>
        /// <para>
        /// ( で始まる場合は引数の読み取りを行います。( ではじまり ) で終わる迄を読み取ります。括弧文字自体は含めません。
        /// </para>
        /// <para>; の場合には命令の読み取りモードを抜けて、命令分岐コード取得に移行します。</para>
        /// <para>} の場合には現在のコンテクスト定義を抜けます。</para>
        /// </summary>
        private void ReadContextCommands()
        {
            const string MISS_ENDQUOTE = "引用符 '\"' に終端 '\"' がありません。";
            const string MISS_ENDPAREN = "括弧 '(' に終端 ')' がありません。";

            switch (this.lreader.CurrentLetter)
            {
            case '(':
                this.wtype = WordType.Suffix;
                if (!this.lreader.MoveNext())
                {
                    this.lreader.SetError((MISS_ENDPAREN), 0, null); return;
                }
                while (true)
                {
                    if ((this.lreader.CurrentLetter == '\"'))
                    {
                        while (true)
                        {
                            this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                            {
                                this.lreader.SetError((MISS_ENDQUOTE), 0, null); return;
                            }
                            if ((this.lreader.CurrentLetter == '\\'))
                            {
                                if (!this.lreader.MoveNext())
                                {
                                    this.lreader.SetError((MISS_ENDQUOTE), 0, null); return;
                                }
                            }
                            else if ((this.lreader.CurrentLetter == '\"'))
                            {
                                break;
                            }
                            else if ((this.lreader.CurrentLetter == '\r') || (this.lreader.CurrentLetter == '\n'))
                            {
                                { this.lreader.SetError((MISS_ENDQUOTE), 0, null); return; }
                            }
                        }
                    }
                    else if ((this.lreader.CurrentLetter == ')'))
                    {
                        if (!this.lreader.MoveNext())
                        {
                            this.lreader.SetError((MISS_ENDPAREN), 0, null); return;
                        }
                        return;
                    }
                    this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                    {
                        this.lreader.SetError((MISS_ENDPAREN), 0, null); return;
                    }
                }

            case ';':
                this.wtype  = WordType.Operator;
                this.mode   = WordReaderMode.ContextConditions;
                this.cword += this.lreader.CurrentLetter; { this.lreader.MoveNext(); return; }

            case '}':
                this.wtype  = WordType.Operator;
                this.mode   = WordReaderMode.Plain;
                this.cword += this.lreader.CurrentLetter; { this.lreader.MoveNext(); return; }

            default:
                while (true)
                {
                    if ((this.lreader.CurrentLetter == '\\'))
                    {
                        if (!this.lreader.MoveNext())
                        {
                            return;
                        }
                    }
                    this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                    {
                        return;
                    }
                    if ((this.lreader.CurrentLetter == '(') || (this.lreader.CurrentLetter == ';') || (this.lreader.CurrentLetter == '}') || this.lreader.CurrentType.IsInvalid || this.lreader.CurrentType.IsSpace || this.IsComment())
                    {
                        return;
                    }
                }
            }
        }
        public override bool ReadNext()
        {
start:
            this.cword = "";
            while (this.lreader.CurrentType.IsInvalid || this.lreader.CurrentType.IsSpace)
            {
                if (!lreader.MoveNext())
                {
                    this.wtype = WordType.Invalid;
                    return(false);
                }
            }
            this.lreader.StoreCurrentPos(0);

            // コメントの始まりの場合
            if (this.IsComment())
            {
                if ((this.lreader.CurrentLetter == '/'))
                {
                    this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                    {
                        return(true);
                    }

                    this.wtype = WordType.Comment;
#if !REMOVE_COMMENT
                    if ((this.lreader.CurrentLetter == '*'))
                    {
                        this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                        {
                            this.lreader.SetError(("コメントに終端 */ がありません。"), 0, null);
                            return(true);
                        }
                        ReadMultiComment();
                        return(true);
                    }
                    else if ((this.lreader.CurrentLetter == '/'))
                    {
                        this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                        {
                            return(true);
                        }
                        ReadLineComment();
                        return(true);
                    }
#else
                    if ((this.lreader.CurrentLetter == '*'))
                    {
                        this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                        {
                            this.lreader.SetError(("コメントに終端 */ がありません。"), 0, null);
                            return(false);
                        }
                        ReadMultiComment();
                        goto start;
                    }
                    else if ((this.lreader.CurrentLetter == '/'))
                    {
                        this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                        {
                            return(false);
                        }
                        ReadLineComment();
                        goto start;
                    }
#endif
                }
                throw new System.ApplicationException("Fatal: ここに制御は来ない筈…IsComment 関数の内容に誤りがあるのかも");
            }

            // 通常の読み取り
            this.wtype = WordType.Identifier;
            switch (mode)
            {
            case WordReaderMode.Plain:
                this.ReadPlain();
                if (this.wtype == WordType.Identifier)
                {
                    if (this.cword == "context")
                    {
                        this.mode = WordReaderMode.ContextDeclaration;
                    }
                    else if (this.cword == "command")
                    {
                        this.mode = WordReaderMode.CommandDeclaration;
                    }
                    else if (this.cword == "condition")
                    {
                        this.mode = WordReaderMode.ConditionDeclaration;
                    }
                }
                break;

            case WordReaderMode.ContextDeclaration:
                this.ReadContextDeclaration();
                break;

            case WordReaderMode.ContextConditions:
                this.ReadContextConditions();
                break;

            case WordReaderMode.ContextCommands:
                this.ReadContextCommands();
                break;

            case WordReaderMode.CommandDeclaration:
            case WordReaderMode.ConditionDeclaration:
                this.ReadCommandDeclaration();
                break;
            }
            return(true);
        }
        private void ReadCommandDeclaration()
        {
            // 通常時
            if (!(this.lreader.CurrentLetter == '{'))
            {
                do
                {
                    this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                    {
                        return;
                    }
                    if ((this.lreader.CurrentLetter == '{') || this.lreader.CurrentType.IsInvalid || this.lreader.CurrentType.IsSpace || this.IsComment())
                    {
                        return;
                    }
                }while(true);
            }

            // '{' の時: 内容の読み取り
            if (!this.lreader.MoveNext())
            {
                goto err;
            }
            int nestlevel = 0;

            while (true)
            {
                switch (this.lreader.CurrentLetter)
                {
                case '"':
                    this.ReadStringDQ();
                    if (this.lreader.CurrentType.IsInvalid)
                    {
                        goto err;
                    }
                    break;

                case '\\':
                    if (!this.lreader.MoveNext())
                    {
                        goto err;
                    }
                    goto default;

                case '{':
                    nestlevel++;
                    goto default;

                case '}':
                    if (0 == nestlevel--)
                    {
                        if (!this.lreader.MoveNext())
                        {
                            return;
                        }
                        goto exit;
                    }
                    goto default;

                default:
                    this.cword += this.lreader.CurrentLetter; if (!this.lreader.MoveNext())
                    {
                        goto err;
                    }
                    break;
                }
            }
exit:
            this.wtype = WordType.Literal;
            this.mode  = WordReaderMode.Plain;
            return;

err:
            this.lreader.SetError(("'{' に対応する '}' がありません"), 0, null);
        }
Esempio n. 8
0
        /// <summary>
        /// <para>
        /// ( で始まる場合は引数の読み取りを行います。( ではじまり ) で終わる迄を読み取ります。括弧文字自体は含めません。
        /// </para>
        /// <para>; の場合には命令の読み取りモードを抜けて、命令分岐コード取得に移行します。</para>
        /// <para>} の場合には現在のコンテクスト定義を抜けます。</para>
        /// </summary>
        private void ReadContextCommands()
        {
            const string MISS_ENDQUOTE = "引用符 '\"' に終端 '\"' がありません。";
            const string MISS_ENDPAREN = "括弧 '(' に終端 ')' がありません。";

            switch (letter)
            {
            case '(':
                this.wtype = WordType.Suffix;
                if (!next)
                {
                    errorexit(MISS_ENDPAREN);
                }
                while (true)
                {
                    if ("is:\"")
                    {
                        while (true)
                        {
                            add; if (!next)
                            {
                                errorexit(MISS_ENDQUOTE);
                            }
                            if ("is:\\")
                            {
                                if (!next)
                                {
                                    errorexit(MISS_ENDQUOTE);
                                }
                            }
                            else if ("is:\"")
                            {
                                break;
                            }
                            else if ("is:\r" || "is:\n")
                            {
                                errorexit(MISS_ENDQUOTE);
                            }
                        }
                    }
                    else if ("is:)")
                    {
                        if (!next)
                        {
                            errorexit(MISS_ENDPAREN);
                        }
                        return;
                    }
                    add; if (!next)
                    {
                        errorexit(MISS_ENDPAREN);
                    }
                }

            case ';':
                this.wtype = WordType.Operator;
                this.mode  = WordReaderMode.ContextConditions;
                add; nexit;

            case '}':
                this.wtype = WordType.Operator;
                this.mode  = WordReaderMode.Plain;
                add; nexit;

            default:
                while (true)
                {
                    if ("is:\\")
                    {
                        next;
                    }
                    add; next;
                    if ("is:(" || "is:;" || "is:}" || type.IsInvalid || type.IsSpace || this.IsComment())
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 9
0
        private void ReadCommandDeclaration()
        {
            // 通常時
            if ("not:{")
            {
                do
                {
                    add; next;
                    if ("is:{" || type.IsInvalid || type.IsSpace || this.IsComment())
                    {
                        return;
                    }
                }while(true);
            }

            // '{' の時: 内容の読み取り
            if (!next)
            {
                goto err;
            }
            int nestlevel = 0;

            while (true)
            {
                switch (letter)
                {
                case '"':
                    this.ReadStringDQ();
                    if (type.IsInvalid)
                    {
                        goto err;
                    }
                    break;

                case '\\':
                    if (!next)
                    {
                        goto err;
                    }
                    goto default;

                case '{':
                    nestlevel++;
                    goto default;

                case '}':
                    if (0 == nestlevel--)
                    {
                        next; goto exit;
                    }
                    goto default;

                default:
                    add; if (!next)
                    {
                        goto err;
                    }
                    break;
                }
            }
exit:
            this.wtype = WordType.Literal;
            this.mode  = WordReaderMode.Plain;
            return;

err:
            error("'{' に対応する '}' がありません");
        }