当前位置: 首页>>代码示例>>C#>>正文


C# StringTemplate.AddChunk方法代码示例

本文整理汇总了C#中StringTemplate.AddChunk方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate.AddChunk方法的具体用法?C# StringTemplate.AddChunk怎么用?C# StringTemplate.AddChunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringTemplate的用法示例。


在下文中一共展示了StringTemplate.AddChunk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: template

        //throws RecognitionException, TokenStreamException
        public void template(
            StringTemplate self
            )
        {
            IToken  s = null;
            IToken  nl = null;

            this.self = self;

            try {      // for error handling
            {    // ( ... )*
                for (;;)
                {
                    switch ( LA(1) )
                    {
                    case LITERAL:
                    {
                        s = LT(1);
                        match(LITERAL);
                        self.AddChunk(new StringRef(self,s.getText()));
                        break;
                    }
                    case NEWLINE:
                    {
                        nl = LT(1);
                        match(NEWLINE);

                        if ( (LA(1) != ELSE) && (LA(1) != ENDIF) ) {
                            self.AddChunk(new NewlineRef(self,nl.getText()));
                        }

                        break;
                    }
                    case ACTION:
                    case IF:
                    case REGION_REF:
                    case REGION_DEF:
                    {
                        action(self);
                        break;
                    }
                    default:
                    {
                        goto _loop3_breakloop;
                    }
                     }
                }
            _loop3_breakloop:				;
            }    // ( ... )*
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_0_);
            }
        }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:57,代码来源:TemplateParser.cs

示例2: action

        //throws RecognitionException, TokenStreamException
        public void action(
            StringTemplate self
            )
        {
            IToken  a = null;
            IToken  i = null;
            IToken  rr = null;
            IToken  rd = null;

            try {      // for error handling
            switch ( LA(1) )
            {
            case ACTION:
            {
                a = LT(1);
                match(ACTION);

                string indent = ((ChunkToken)a).Indentation;
                ASTExpr c = self.ParseAction(a.getText());
                c.Indentation = indent;
                self.AddChunk(c);

                break;
            }
            case IF:
            {
                i = LT(1);
                match(IF);

                ConditionalExpr c = (ConditionalExpr)self.ParseAction(i.getText());
                // create and precompile the subtemplate
                StringTemplate subtemplate =
                    new StringTemplate(self.Group, null);
                subtemplate.EnclosingInstance = self;
                subtemplate.Name = i.getText() + "_subtemplate";
                self.AddChunk(c);

                template(subtemplate);
                if ( c!=null ) c.Subtemplate = subtemplate;
                {
                    switch ( LA(1) )
                    {
                    case ELSE:
                    {
                        match(ELSE);

                        // create and precompile the subtemplate
                        StringTemplate elseSubtemplate =
                                new StringTemplate(self.Group, null);
                        elseSubtemplate.EnclosingInstance = self;
                        elseSubtemplate.Name = "else_subtemplate";

                        template(elseSubtemplate);
                        if ( c!=null ) c.ElseSubtemplate = elseSubtemplate;
                        break;
                    }
                    case ENDIF:
                    {
                        break;
                    }
                    default:
                    {
                        throw new NoViableAltException(LT(1), getFilename());
                    }
                     }
                }
                match(ENDIF);
                break;
            }
            case REGION_REF:
            {
                rr = LT(1);
                match(REGION_REF);

                        // define implicit template and
                        // convert <@r()> to <region__enclosingTemplate__r()>
                            string regionName = rr.getText();
                            string mangledRef = null;
                            bool err = false;
                            // watch out for <@super.r()>; that does NOT def implicit region
                            // convert to <super.region__enclosingTemplate__r()>
                            if ( regionName.StartsWith("super.") ) {
                                //Console.Out.Writeline("super region ref "+regionName);
                                string regionRef =
                                    regionName.Substring("super.".Length,regionName.Length-"super.".Length);
                                string templateScope =
                                    self.Group.GetUnMangledTemplateName(self.Name);
                                StringTemplate scopeST = self.Group.LookupTemplate(templateScope);
                                if ( scopeST==null ) {
                                    self.Group.Error("reference to region within undefined template: "+
                                        templateScope);
                                    err=true;
                                }
                                if ( !scopeST.ContainsRegionName(regionRef) ) {
                                    self.Group.Error("template "+templateScope+" has no region called "+
                                        regionRef);
                                    err=true;
                                }
                                else {
//.........这里部分代码省略.........
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:101,代码来源:TemplateParser.cs


注:本文中的StringTemplate.AddChunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。