コード例 #1
0
ファイル: Condition.cs プロジェクト: JE-00/j-esquerra
        /// <summary>
        /// Ensure that this condition didn't come from a non matching if/elif.
        /// </summary>
        /// <returns></returns>
        protected virtual bool DoesPassElifSanityCheck()
        {
            System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType();
            var         prevCmdIndent       = ParentBlock.GetPreviousActiveCommandIndent();
            var         prevCmd             = ParentBlock.GetPreviousActiveCommand();

            //handle our matching if or else if in the chain failing and moving to us,
            //  need to make sure it is the same indent level
            if (prevCmd == null ||
                prevCmdIndent != IndentLevel ||
                !previousCommandType.IsSubclassOf(typeof(Condition)) ||
                (prevCmd as Condition).IsLooping)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: Condition.cs プロジェクト: tomcat7607/fungus
        public override void OnEnter()
        {
            if (ParentBlock == null)
            {
                return;
            }

            if (!HasNeededProperties())
            {
                Continue();
                return;
            }

            if (!this.IsElseIf)
            {
                EvaluateAndContinue();
            }
            else
            {
                System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType();
                var         prevCmdIndent       = ParentBlock.GetPreviousActiveCommandIndent();

                //handle our matching if or else if in the chain failing and moving to us,
                //  need to make sure it is the same indent level
                if (prevCmdIndent == IndentLevel && previousCommandType.IsSubclassOf(typeof(Condition)))
                {
                    // Else If behaves the same as an If command
                    EvaluateAndContinue();
                }
                else
                {
                    // Else If behaves mostly like an Else command,
                    // but will also jump to a following Else command.

                    // Stop if this is the last command in the list
                    if (CommandIndex >= ParentBlock.CommandList.Count - 1)
                    {
                        StopParentBlock();
                        return;
                    }

                    // Find the next End command at the same indent level as this Else If command
                    int indent = indentLevel;
                    for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
                    {
                        var command = ParentBlock.CommandList[i];

                        if (command.IndentLevel == indent)
                        {
                            System.Type type = command.GetType();
                            if (type == typeof(End))
                            {
                                // Execute command immediately after the Else or End command
                                Continue(command.CommandIndex + 1);
                                return;
                            }
                        }
                    }

                    // No End command found
                    StopParentBlock();
                }
            }
        }