コード例 #1
0
ファイル: TemplateManager.cs プロジェクト: luozhiyong520/CMS
        protected void ProcessIf(TagIf tagIf)
        {
            bool condition = false;

            try
            {
                object value = EvalExpression(tagIf.Test);

                condition = Util.ToBool(value);
            }
            catch (Exception ex)
            {
                DisplayError("if条件错误: " + ex.Message,
                             tagIf.Line, tagIf.Col);
                return;
            }

            if (condition)
            {
                ProcessElements(tagIf.InnerElements);
            }
            else
            {
                ProcessElement(tagIf.FalseBranch);
            }
        }
コード例 #2
0
        protected void ProcessIf(TagIf tagIf)
        {
            object value = EvalExpression(tagIf.Test);

            if (Util.ToBool(value))
            {
                ProcessElements(tagIf.InnerElements);
            }
            else
            {
                ProcessElement(tagIf.FalseBranch);
            }
        }
コード例 #3
0
ファイル: TemplateManager.cs プロジェクト: WZDotCMS/WZDotCMS
        protected void ProcessIf(TagIf tagIf)
        {
            bool condition = false;

            try
            {
                object value = EvalExpression(tagIf.Test);

                condition = Util.ToBool(value);
            }
            catch (Exception ex)
            {
                DisplayError("Error evaluating condition for if statement: " + ex.Message,
                    tagIf.Line, tagIf.Col);
                return;
            }

            if (condition)
                ProcessElements(tagIf.InnerElements);
            else
                ProcessElement(tagIf.FalseBranch);
        }
コード例 #4
0
ファイル: TagParser.cs プロジェクト: luozhiyong520/CMS
        private Tag CollectForTag(Tag tag, ref int index)
        {
            if (tag.IsClosed) // if self-closing tag, do not collect inner elements
            {
                return(tag);
            }

            if (string.Compare(tag.Name, "if", true) == 0)
            {
                tag = new TagIf(tag.Line, tag.Col, tag.AttributeValue("test"));
            }

            Tag collectTag = tag;

            for (index++; index < elements.Count; index++)
            {
                Element elem = elements[index];

                if ((elem as Text) != null)
                {
                    collectTag.InnerElements.Add(elem);
                }
                else if ((elem as Expression) != null)
                {
                    collectTag.InnerElements.Add(elem);
                }
                else if ((elem as Tag) != null)
                {
                    Tag innerTag = (Tag)elem;
                    if (string.Compare(innerTag.Name, "else", true) == 0)
                    {
                        if ((collectTag as TagIf) != null)
                        {
                            ((TagIf)collectTag).FalseBranch = innerTag;
                            collectTag = innerTag;
                        }
                        else
                        {
                            throw new ParseException("else tag has to be positioned inside of if or elseif tag", innerTag.Line, innerTag.Col);
                        }
                    }
                    else if (string.Compare(innerTag.Name, "elseif", true) == 0)
                    {
                        if ((collectTag as TagIf) != null)
                        {
                            Tag newTag = new TagIf(innerTag.Line, innerTag.Col, innerTag.AttributeValue("test"));
                            ((TagIf)collectTag).FalseBranch = newTag;
                            collectTag = newTag;
                        }
                        else
                        {
                            throw new ParseException("elseif tag is not positioned properly", innerTag.Line, innerTag.Col);
                        }
                    }
                    else
                    {
                        collectTag.InnerElements.Add(CollectForTag(innerTag, ref index));
                    }
                }
                else if ((elem as TagClose) != null)
                {
                    TagClose tagClose = (TagClose)elem;
                    if (string.Compare(tag.Name, tagClose.Name, true) == 0)
                    {
                        return(tag);
                    }

                    throw new ParseException("Close tag for " + tagClose.Name + " doesn't have matching start tag.", elem.Line, elem.Col);
                }
                else
                {
                    throw new ParseException("Invalid element: " + elem.GetType().ToString(), elem.Line, elem.Col);
                }
            }

            throw new ParseException("Start tag: " + tag.Name + " does not have matching end tag.", tag.Line, tag.Col);
        }
コード例 #5
0
ファイル: TagParser.cs プロジェクト: nkaluva/helper
        /// <summary>
        /// 收集子标签。
        /// </summary>
        /// <param name="tag">指定一个标签实例。</param>
        /// <param name="index">指定标签索引。</param>
        /// <returns>Tag</returns>
        private Tag CollectForTag(Tag tag, ref int index)
        {
            if (tag.IsClosed)
            {
                return(tag);
            }
            if (string.Compare(tag.Name, "if", true) == 0)
            {
                tag = new TagIf(tag.Line, tag.Col, tag.AttributeValue("test"));
            }

            Tag collectTag = tag;

            for (index++; index < _Elements.Count; index++)
            {
                Element elem = _Elements[index];

                if (elem is Text)
                {
                    collectTag.InnerElements.Add(elem);
                }
                else if (elem is Expression)
                {
                    collectTag.InnerElements.Add(elem);
                }
                else if (elem is Tag)
                {
                    Tag innerTag = (Tag)elem;
                    if (string.Compare(innerTag.Name, "else", true) == 0)
                    {
                        if (collectTag is TagIf)
                        {
                            ((TagIf)collectTag).FalseBranch = innerTag;
                            collectTag = innerTag;
                        }
                        else
                        {
                            throw new ParseException("else 标签必须包含在 if 或 elseif 之内。", innerTag.Line, innerTag.Col);
                        }
                    }
                    else if (string.Compare(innerTag.Name, "elseif", true) == 0)
                    {
                        if (collectTag is TagIf)
                        {
                            Tag newTag = new TagIf(innerTag.Line, innerTag.Col, innerTag.AttributeValue("test"));
                            ((TagIf)collectTag).FalseBranch = newTag;
                            collectTag = newTag;
                        }
                        else
                        {
                            throw new ParseException("elseif 标签位置不正确。", innerTag.Line, innerTag.Col);
                        }
                    }
                    else
                    {
                        collectTag.InnerElements.Add(CollectForTag(innerTag, ref index));
                    }
                }
                else if (elem is TagClose)
                {
                    TagClose tagClose = (TagClose)elem;
                    if (string.Compare(tag.Name, tagClose.Name, true) == 0)
                    {
                        return(tag);
                    }

                    throw new ParseException("没有为闭合标签 " + tagClose.Name + " 找到合适的开始标签。", elem.Line, elem.Col);
                }
                else
                {
                    throw new ParseException("无效标签: " + elem.GetType().ToString(), elem.Line, elem.Col);
                }
            }

            throw new ParseException("没有为开始标签 " + tag.Name + " 找到合适的闭合标签。", tag.Line, tag.Col);
        }
コード例 #6
0
ファイル: TagParser.cs プロジェクト: WZDotCMS/WZDotCMS
        private Tag CollectForTag(Tag tag, ref int index)
        {
            if (tag.IsClosed) // if self-closing tag, do not collect inner elements
            {
                return tag;
            }

            if (string.Compare(tag.Name, "if", true) == 0)
            {
                tag = new TagIf(tag.Line, tag.Col, tag.AttributeValue("test"));
            }

            Tag collectTag = tag;

            for (index++; index < elements.Count; index++)
            {
                Element elem = elements[index];

                if (elem is Text)
                    collectTag.InnerElements.Add(elem);
                else if (elem is Expression)
                    collectTag.InnerElements.Add(elem);
                else if (elem is Tag)
                {
                    Tag innerTag = (Tag)elem;
                    if (string.Compare(innerTag.Name, "else", true) == 0)
                    {
                        if (collectTag is TagIf)
                        {
                            ((TagIf)collectTag).FalseBranch = innerTag;
                            collectTag = innerTag;
                        }
                        else
                            throw new ParseException("else tag has to be positioned inside of if or elseif tag", innerTag.Line, innerTag.Col);

                    }
                    else if (string.Compare(innerTag.Name, "elseif", true) == 0)
                    {
                        if (collectTag is TagIf)
                        {
                            Tag newTag = new TagIf(innerTag.Line, innerTag.Col, innerTag.AttributeValue("test"));
                            ((TagIf)collectTag).FalseBranch = newTag;
                            collectTag = newTag;
                        }
                        else
                            throw new ParseException("elseif tag is not positioned properly", innerTag.Line, innerTag.Col);
                    }
                    else
                        collectTag.InnerElements.Add(CollectForTag(innerTag, ref index));
                }
                else if (elem is TagClose)
                {
                    TagClose tagClose = (TagClose)elem;
                    if (string.Compare(tag.Name, tagClose.Name, true) == 0)
                        return tag;

                    throw new ParseException("Close tag for " + tagClose.Name + " doesn't have matching start tag.", elem.Line, elem.Col);
                }
                else
                    throw new ParseException("Invalid element: " + elem.GetType().ToString(), elem.Line, elem.Col);

            }

            throw new ParseException("Start tag: " + tag.Name + " does not have matching end tag.", tag.Line, tag.Col);
        }