Пример #1
0
 public ForNode(string variableName, Expression itemsExpr, TemplateBlock body, string joiner)
 {
     this.variableName = variableName;
     this.itemsExpr    = itemsExpr;
     this.body         = body;
     this.joiner       = joiner;
 }
Пример #2
0
        public TemplateBlock parseBlock(int indentLen = 0)
        {
            var block     = new TemplateBlock(new ITemplateNode[0]);
            var indentMan = new BlockIndentManager(block, indentLen);

            while (!this.reader.eof)
            {
                if (this.reader.peekExactly("{{/"))
                {
                    break;
                }
                if (this.reader.readExactly("${"))
                {
                    var expr = this.parser.parseExpression();
                    block.items.push(new ExpressionNode(expr));
                    this.reader.expectToken("}");
                }
                else if (this.reader.readExactly("$"))
                {
                    var id = this.reader.expectIdentifier();
                    block.items.push(new ExpressionNode(new Identifier(id)));
                }
                else if (this.reader.readExactly("{{"))
                {
                    var blockIndentLen = indentMan.removePrevIndent();

                    if (this.reader.readToken("for"))
                    {
                        var varName = this.reader.expectIdentifier();
                        this.reader.expectToken("of");
                        var itemsExpr = this.parser.parseExpression();
                        var attrs     = this.parseAttributes();
                        this.reader.expectToken("}}");
                        var body = this.parseBlock(blockIndentLen);
                        this.reader.expectToken("{{/for}}");
                        block.items.push(new ForNode(varName, itemsExpr, body, attrs.get("joiner")));
                    }
                    else
                    {
                        var expr = this.parser.parseExpression();
                        block.items.push(new ExpressionNode(expr));
                        this.reader.expectToken("}}");
                    }
                }
                else
                {
                    var literal = this.reader.readRegex("([^\\\\]\\\\(\\{\\{|\\$)|\r|\n|(?!\\{\\{|\\$\\{|\\$).)*").get(0);
                    if (literal == "")
                    {
                        throw new Error("This should not happen!");
                    }
                    block.items.push(indentMan.deindent(new LiteralNode(literal)));
                }
            }

            if (indentLen != 0)
            {
                indentMan.removePrevIndent();
            }

            return(block);
        }
Пример #3
0
 public BlockIndentManager(TemplateBlock block, int indentLen)
 {
     this.block       = block;
     this.indentLen   = indentLen;
     this.deindentLen = -1;
 }