@SuppressWarnings("rawtypes") private Token expect(Class expectedTokenClass) { Token t = this.peek(); if (t.getClass().equals(expectedTokenClass)) { return advance(); } else { throw new JadeParserException(filename, lexer.getLineno(), templateLoader, expectedTokenClass, t.getClass()); } }
private Node parseTextBlock() { BlockNode blockNode = new BlockNode(); blockNode.setLineNumber(line()); blockNode.setFileName(filename); Token body = peek(); if(!(body instanceof PipelessText)){ return null; } this.advance(); ArrayList<String> values = body.getValues(); Node[] textNodes = {}; for (String value : values) { textNodes = ArrayUtils.addAll(textNodes,parseInlineTagsInText(value)); } blockNode.setNodes(new LinkedList<Node>(Arrays.asList(textNodes))); return blockNode; }
private List<CaseConditionNode> whenBlock() { expect(Indent.class); List<CaseConditionNode> caseConditionalNodes = new LinkedList<CaseConditionNode>(); while (!(peek() instanceof Outdent) && !(peek() instanceof Eos)) { if (peek() instanceof Newline) { advance(); } else { caseConditionalNodes.add(this.parseCaseCondition()); } } if (peek() instanceof Outdent) { expect(Outdent.class); } return caseConditionalNodes; }
private BlockNode parseYield() { advance(); BlockNode block = new BlockNode(); block.setLineNumber(lexer.getLineno()); block.setFileName(filename); block.setYield(true); return block; } private Node parseInterpolation() {
private Node parseBlockExpansion(){ if (this.peek() instanceof Colon) { this.advance(); BlockNode blockNode = new BlockNode(); blockNode.push(this.parseExpr()); return blockNode; } else { return this.block(); } }
private Node parseCssClassOrId() { Token tok = advance(); Tag div = new Tag("div", line()); lexer.defer(div); lexer.defer(tok); return parseExpr(); } private Node parseBlock() {
public Node parse() { BlockNode block = new BlockNode(); block.setLineNumber(lexer.getLineno()); block.setFileName(filename); while (!(peek() instanceof Eos)) { if (peek() instanceof Newline) { advance(); } else { Node expr = parseExpr(); if (expr != null) { block.push(expr); } } } if (extending != null) { getContexts().push(extending); Node rootNode = extending.parse(); getContexts().pop(); // hoist mixins Set<String> keySet = this.mixins.keySet(); for (String name : keySet) { rootNode.getNodes().push(this.mixins.get(name)); } return rootNode; } return block; }
/** * block code */ private Node parseBlockCode(){ Token tok = this.expect(BlockCode.class); ExpressionNode node; Token body = this.peek(); String text; if (body instanceof PipelessText) { this.advance(); text = StringUtils.join(body.getValues(),"\n"); } else { text = ""; } node = new ExpressionNode(); node.setValue(text); node.setLineNumber(tok.getLineNumber()); return node; }
private Node parseInterpolation() { Token token = advance(); String name = token.getValue(); TagNode tagNode = new TagNode(); tagNode.setLineNumber(lexer.getLineno()); tagNode.setFileName(filename); tagNode.setName(name); tagNode.setBuffer(true); return this.tag(tagNode); }
private Node parseTag() { Token token = advance(); String name = token.getValue(); TagNode tagNode = new TagNode(); tagNode.setLineNumber(lexer.getLineno()); tagNode.setFileName(filename); tagNode.setName(name); tagNode.setValue(name); tagNode.setSelfClosing(token.isSelfClosing()); return this.tag(tagNode); }
Token incomingToken = peek(); if (incomingToken instanceof CssId) { Token tok = advance(); tagNode.setAttribute("id", tok.getValue(),false); continue; } else if (incomingToken instanceof CssClass) { Token tok = advance(); tagNode.setAttribute("class", tok.getValue(),false); continue; AttributeList tok = (AttributeList) advance(); List<Attribute> attrs = tok.getAttributes(); tagNode.setSelfClosing(tok.isSelfClosing()); Token tok = this.advance(); tagNode.addAttributes(tok.getValue()); } else { dot = true; tagNode.setTextOnly(true); advance(); tagNode.setCodeNode(parseCode()); } else if (peek() instanceof Colon) { Token next = advance(); BlockNode block = new BlockNode(); block.setLineNumber(next.getLineNumber()); advance();
private BlockNode block() { BlockNode block = new BlockNode(); block.setLineNumber(lexer.getLineno()); block.setFileName(filename); expect(Indent.class); while (!(peek() instanceof Outdent)) { if (peek() instanceof Newline) { advance(); } else { Node parseExpr = this.parseExpr(); parseExpr.setFileName(filename); if (parseExpr != null) { block.push(parseExpr); } } } expect(Outdent.class); return block; }
private Node parseCase() { String val = expect(CaseToken.class).getValue(); Node node = new CaseNode(); node.setValue(val); node.setLineNumber(line()); Node block = new BlockNode(); block.setLineNumber(line()); block.setFileName(filename); expect(Indent.class); while (!(peek() instanceof Outdent)) { if (peek() instanceof Comment) { advance(); } else if (peek() instanceof Newline) { advance(); } else if (peek() instanceof When) { block.push(parseWhen()); } else if (peek() instanceof Default) { block.push(parseDefault()); } else { throw new JadeParserException(filename,lexer.getLineno(),templateLoader,"Unexpected token \"" + this.peek() + "\", expected \"when\", \"default\" or \"newline\""); } } expect(Outdent.class); node.setBlock(block); return node; } /**
private Node parseEach() { Token token = expect(Each.class); Each eachToken = (Each) token; EachNode node = new EachNode(); node.setValue(eachToken.getValue()); node.setKey(eachToken.getKey()); node.setCode(eachToken.getCode()); node.setLineNumber(eachToken.getLineNumber()); node.setFileName(filename); node.setBlock(block()); if (peek() instanceof Else) { advance(); node.setElseNode(block()); } return node; }
@SuppressWarnings("rawtypes") private Token expect(Class expectedTokenClass) { Token t = this.peek(); if (t.getClass().equals(expectedTokenClass)) { return advance(); } else { throw new JadeParserException(filename, lexer.getLineno(), templateLoader, expectedTokenClass, t.getClass()); } }
private Node parseBlockExpansion(){ if (this.peek() instanceof Colon) { this.advance(); BlockNode blockNode = new BlockNode(); blockNode.push(this.parseExpr()); return blockNode; } else { return this.block(); } }
private Node parseCssClassOrId() { Token tok = advance(); Tag div = new Tag("div", line()); lexer.defer(div); lexer.defer(tok); return parseExpr(); } private Node parseBlock() {
private BlockNode parseYield() { advance(); BlockNode block = new BlockNode(); block.setLineNumber(lexer.getLineno()); block.setFileName(filename); block.setYield(true); return block; } private Node parseInterpolation() {
private Node parseInterpolation() { Token token = advance(); String name = token.getValue(); TagNode tagNode = new TagNode(); tagNode.setLineNumber(lexer.getLineno()); tagNode.setFileName(filename); tagNode.setName(name); tagNode.setBuffer(true); return this.tag(tagNode); }
private Node parseTag() { Token token = advance(); String name = token.getValue(); TagNode tagNode = new TagNode(); tagNode.setLineNumber(lexer.getLineno()); tagNode.setFileName(filename); tagNode.setName(name); tagNode.setValue(name); tagNode.setSelfClosing(token.isSelfClosing()); return this.tag(tagNode); }