Beispiel #1
0
        // var tok = this.expect('code')
        // , node = new nodes.Code(tok.val, tok.buffer, tok.escape)
        // , block
        // , i = 1;
        // node.line = this.line();
        // while (this.lookahead(i) && 'newline' == this.lookahead(i).type) ++i;
        // block = 'indent' == this.lookahead(i).type;
        // if (block) {
        // this.skip(i-1);
        // node.block = this.block();
        // }
        // return node;
        private Node parseFilter()
        {
            Token token = expect(GetType())
            ;
            Filter filterToken = (Filter) token;
            Attribute attr = (Attribute) accept(typeof (Attribute))
            ;
            _jadeLexer.setPipeless(true);
            Node tNode = parseTextBlock();
            _jadeLexer.setPipeless(false);

            FilterNode node = new FilterNode();
            node.setValue(filterToken.getValue());
            node.setLineNumber(line());
            node.setFileName(filename);
            node.setTextBlock(tNode);
            if (attr != null)
            {
                node.setAttributes(attr.getAttributes());
            }
            return node;
        }
Beispiel #2
0
        private Node parseInclude()
        {
            Token token = expect(typeof (Include));
            Include includeToken = (Include) token;
            String templateName = includeToken.getValue().Trim();

            String extension = Path.GetExtension(templateName);
            if (!"".Equals(extension) && !"jade".Equals(extension))
            {
                FilterNode node = new FilterNode();
                node.setLineNumber(_jadeLexer.getLineno());
                node.setFileName(filename);
                node.setValue(extension);
                try
                {
                    TextReader reader = templateLoader.getReader(resolvePath(templateName));
                    Node textNode = new TextNode();
                    textNode.setFileName(filename);
                    textNode.setLineNumber(_jadeLexer.getLineno());
                    textNode.setValue(reader.ReadToEnd());
                    node.setTextBlock(textNode);
                }
                catch (IOException e)
                {
                    throw new JadeParserException(filename, _jadeLexer.getLineno(), templateLoader,
                        "the included file [" + templateName + "] could not be opened\n" + e.Message);
                }
                return node;
            }

            JadeParser jadeParser = createParser(templateName);
            jadeParser.setBlocks(blocks);
            contexts.AddLast(jadeParser);
            Node ast = jadeParser.parse();
            contexts.RemoveLast();

            if (peek() is Indent && ast is BlockNode)
            {
                ((BlockNode) ast).getIncludeBlock().push(block());
            }

            return ast;
        }
Beispiel #3
0
        private Node parseASTFilter()
        {
            Token token = expect(GetType());
            Filter filterToken = (Filter) token;
            Attribute attr = (Attribute) accept(typeof (Attribute));

            token = expect(typeof (Colon));

            FilterNode node = new FilterNode();
            node.setValue(filterToken.getValue());
            node.setBlock(block());
            node.setLineNumber(line());
            node.setFileName(filename);
            node.setAttributes(attr.getAttributes());
            return node;
        }