Esempio n. 1
0
        public Node parse()
        {
            BlockNode block = new BlockNode();
            block.setLineNumber(_jadeLexer.getLineno());
            block.setFileName(filename);
            while (!(peek() is Eos))
            {
                if (peek() is Newline)
                {
                    nextToken();
                }
                else
                {
                    Node expr = parseExpr();
                    if (expr != null)
                    {
                        block.push(expr);
                    }
                }
            }
            if (extending != null)
            {
                getContexts().AddLast(extending);
                Node rootNode = extending.parse();
                getContexts().RemoveLast();
                return rootNode;
            }

            return block;
        }
Esempio n. 2
0
        public void test()
        {
            loadInParser("include_1.jade");

            tagNode = (TagNode) root.pollNode();
            Assert.AreEqual(tagNode.getName(), ("p"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("Before Include"));

            includeNode = (BlockNode) root.pollNode();
            tagNode = (TagNode) includeNode.pollNode();
            Assert.AreEqual(tagNode.getName(), ("span"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("Hello Include"));

            yieldNode = (BlockNode) includeNode.pollNode();
            Assert.IsNotNull(yieldNode);

            /*var blockNode = (BlockNode) yieldNode.pollNode();
            tagNode = (TagNode)blockNode.pollNode();
            Assert.AreEqual(blockNode.getName(), ("p"));
            textNode = (TextNode) tagNode.getTextNode();
            Assert.AreEqual(textNode.getValue(), ("After Include"));

            Assert.AreEqual(yieldNode.hasNodes(), (false));
            Assert.AreEqual(includeNode.hasNodes(), (false));
            Assert.AreEqual(root.hasNodes(), (false));
            */
        }
Esempio n. 3
0
        public void shouldReturnTagsWithTexts()
        {
            loadInParser("assignment.jade");
            block = (BlockNode) root;
            LinkedList<Node> nodes = block.getNodes();
            Assert.AreEqual(2, nodes.Count);

            AssigmentNode assignment = (AssigmentNode)block.getNodes().ElementAt(0);
            Assert.AreEqual("hello", assignment.getName());
            Assert.AreEqual("\"world\"", assignment.getValue());

            TagNode tag = (TagNode) block.getNodes().ElementAt(1);
            Assert.IsNotNull(tag);
        }
Esempio n. 4
0
        private Node parseTag()
        {
            // ast-filter look-ahead
            int i = 2;
            if (lookahead(i) is Attribute)
            {
                i++;
            }
            if (lookahead(i) is Colon)
            {
                i++;
                if (lookahead(i) is Indent)
                {
                    return this.parseASTFilter();
                }
            }
            Token token = nextToken();
            String name = token.getValue();
            TagNode tagNode = new TagNode();
            tagNode.setLineNumber(_jadeLexer.getLineno());
            tagNode.setFileName(filename);
            tagNode.setName(name);
            tagNode.setValue(name);
            tagNode.setSelfClosing(token.isSelfClosing());

            while (true)
            {
                Token incomingToken = peek();
                if (incomingToken is CssId)
                {
                    Token tok = nextToken();
                    tagNode.addAttribute("id", tok.getValue());
                    continue;
                }
                else if (incomingToken is CssClass)
                {
                    Token tok = nextToken();
                    tagNode.addAttribute("class", tok.getValue());
                    continue;
                }
                else if (incomingToken is Attribute)
                {
                    Attribute tok = (Attribute) nextToken();
                    tagNode.addAttributes(tok.getAttributes());
                    tagNode.setSelfClosing(tok.isSelfClosing());
                    continue;
                }
                else
                {
                    break;
                }
            }

            // check immediate '.'
            bool dot = false;
            if (peek() is Dot)
            {
                dot = true;
                tagNode.setTextOnly(true);
                nextToken();
            }

            // (text | code | ':')?
            if (peek() is Text)
            {
                tagNode.setTextNode(parseText());
            }
            else if (peek() is Jade.Lexer.Tokens.Expression)
            {
                tagNode.setCodeNode(parseCode());
            }
            else if (peek() is Colon)
            {
                Token next = nextToken();
                BlockNode block = new BlockNode();
                block.setLineNumber(next.getLineNumber());
                block.setFileName(filename);
                tagNode.setBlock(block);
                block.push(parseExpr());
            }

            // newline*
            while (peek() is Newline)
            {
                nextToken();
            }

            if (!tagNode.isTextOnly())
            {
                if (Array.IndexOf(textOnlyTags, tagNode.getName()) >= 0)
                {
                    tagNode.setTextOnly(true);
                }
            }

            // script special-case
            if ("script".Equals(tagNode.getName()))
            {
                String type = tagNode.getAttribute("type");
                if (!dot && StringUtils.isNotBlank(type))
                {
                    String cleanType = type.replaceAll("^['\"]|['\"]$", "");
                    if (!"text/javascript".Equals(cleanType))
                    {
                        tagNode.setTextOnly(false);
                    }
                }
            }

            if (peek() is Indent)
            {
                if (tagNode.isTextOnly())
                {
                    _jadeLexer.setPipeless(true);
                    tagNode.setTextNode(parseTextBlock());
                    _jadeLexer.setPipeless(false);
                }
                else
                {
                    Node blockNode = block();
                    if (tagNode.hasBlock())
                    {
                        tagNode.getBlock().getNodes().AppendRange(blockNode.getNodes());
                    }
                    else
                    {
                        tagNode.setBlock(blockNode);
                    }
                }
            }

            return tagNode;
        }
Esempio n. 5
0
        private Node parseBlock()
        {
            Token token = expect(typeof (Block));
            Block blockToken = (Block) token;
            String mode = blockToken.getMode();
            String name = blockToken.getValue().Trim();

            Node blockNode;
            if (peek() is Indent)
            {
                blockNode = block();
            }
            else
            {
                blockNode = new BlockNode();
                blockNode.setLineNumber(blockToken.getLineNumber());
                blockNode.setFileName(filename);
            }

            ((BlockNode) blockNode).setMode(mode);

            if (blocks.ContainsKey(name))
            {
                BlockNode prev = (BlockNode) blocks[name];
                if ("append".Equals(prev.getMode()))
                {
                    blockNode.getNodes().AppendRange(prev.getNodes());
                }
                if ("prepend".Equals(prev.getMode()))
                {
                    blockNode.getNodes().PrependRange(prev.getNodes());
                }
                if ("replace".Equals(prev.getMode()))
                {
                    blockNode = prev;
                }
            }

            blocks.Add(name, blockNode);
            return blockNode;
        }
Esempio n. 6
0
 private Node blockExpansion()
 {
     if (peek() is Colon)
     {
         Token token = expect(typeof (Colon))
         ;
         Colon colon = (Colon) token;
         BlockNode blockNode = new BlockNode();
         blockNode.setLineNumber(colon.getLineNumber());
         blockNode.setFileName(filename);
         blockNode.getNodes().AddLast(parseExpr());
         return blockNode;
     }
     return block();
 }
Esempio n. 7
0
 private Node block()
 {
     BlockNode block = new BlockNode();
     block.setLineNumber(_jadeLexer.getLineno());
     block.setFileName(filename);
     expect(typeof (Indent))
     ;
     while (!(peek() is Outdent) && !(peek() is Eos))
     {
         if (peek() is Newline)
         {
             nextToken();
         }
         else
         {
             Node parseExpr = this.parseExpr();
             if (parseExpr != null)
             {
                 block.push(parseExpr);
             }
         }
     }
     if (peek() is Outdent)
     {
         expect(typeof (Outdent));
     }
     return block;
 }
Esempio n. 8
0
 public void setYieldBlock(BlockNode yieldBlock)
 {
     this.yieldBlock = yieldBlock;
 }
Esempio n. 9
0
 public void setYieldBlock(BlockNode yieldBlock)
 {
     this.yieldBlock = yieldBlock;
 }