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 Node parseMixinBlock(){ Token tok = expect(MixinBlock.class); if(this.inMixin == 0){ throw new JadeParserException(filename, lexer.getLineno(), templateLoader, "Anonymous blocks are not allowed unless they are part of a mixin."); } return new MixinBlockNode(); }
private Node parseDoctype() { Token token = expect(Doctype.class); Doctype doctype = (Doctype) token; DoctypeNode doctypeNode = new DoctypeNode(); doctypeNode.setValue(doctype.getValue()); return doctypeNode; }
/** * default */ private Node parseDefault(){ expect(Default.class); Node when = new CaseNode.When(); when.setValue("default"); when.setBlock(this.parseBlockExpansion()); return when; }
private Node parseExtends() { Token token = expect(ExtendsToken.class); ExtendsToken extendsToken = (ExtendsToken) token; String templateName = extendsToken.getValue().trim(); Parser parser = createParser(templateName); parser.setBlocks(blocks); parser.setContexts(contexts); extending = parser; LiteralNode node = new LiteralNode(); node.setValue(""); return node; }
private Node blockExpansion() { if (peek() instanceof Colon) { Token token = expect(Colon.class); Colon colon = (Colon) token; BlockNode block = new BlockNode(); block.setLineNumber(colon.getLineNumber()); block.setFileName(filename); block.getNodes().add(parseExpr()); return block; } return block(); }
private CaseConditionNode parseCaseCondition() { CaseConditionNode node = new CaseConditionNode(); Token token = null; if (peek() instanceof When) { token = expect(When.class); } else { token = expect(Default.class); node.setDefault(true); } node.setLineNumber(token.getLineNumber()); node.setFileName(filename); node.setValue(token.getValue()); node.setBlock(blockExpansion()); return node; }
private Node parseASTFilter() { Token token = expect(Filter.class); Filter filterToken = (Filter) token; AttributeList attr = (AttributeList) accept(AttributeList.class); token = expect(Colon.class); FilterNode node = new FilterNode(); node.setValue(filterToken.getValue()); node.setBlock(block()); node.setLineNumber(line()); node.setFileName(filename); node.setAttributes(convertToNodeAttributes(attr)); return node; }
/** * when */ private Node parseWhen(){ String val = this.expect(When.class).getValue(); CaseNode.When when = new CaseNode.When(); when.setValue(val); if (!(this.peek() instanceof Newline)) { when.setBlock(this.parseBlockExpansion()); } return when; }
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; }
/** * 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 parseAssignment() { Token token = expect(Assignment.class); Token assignmentToken = (Assignment) token; Node node = new AssigmentNode(); node.setName(assignmentToken.getName()); node.setValue(assignmentToken.getValue()); node.setLineNumber(assignmentToken.getLineNumber()); node.setFileName(filename); return node; }
private Node parseText() { Token tok = expect(Text.class); Node[] tokens = this.parseInlineTagsInText(tok.getValue()); if (tokens.length == 1) return tokens[0]; BlockNode node = new BlockNode(); for (int i = 0; i < tokens.length; i++) { node.push(tokens[i]); } node.setValue(tok.getValue()); node.setLineNumber(tok.getLineNumber()); node.setFileName(filename); return node; }
private Node parseWhile() { Token token = expect(While.class); While whileToken = (While) token; WhileNode node = new WhileNode(); node.setValue(whileToken.getValue()); node.setLineNumber(whileToken.getLineNumber()); node.setFileName(filename); BlockNode block = block(); if(block!=null) node.setBlock(block); else node.setBlock(new BlockNode()); return node; }
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 parseCall() { Token token = expect(Call.class); Call callToken = (Call) token; MixinNode mixin = new MixinNode(); mixin.setBlock(new BlockNode()); mixin.setName(callToken.getValue()); mixin.setLineNumber(callToken.getLineNumber()); mixin.setFileName(filename); mixin.setCall(true); if (StringUtils.isNotBlank(callToken.getArguments())) { mixin.setArguments(callToken.getArguments()); } this.tag(mixin); if(mixin.hasCodeNode()) { mixin.getBlock().push(mixin.getCodeNode()); mixin.setCodeNode(null); } if(mixin.hasBlock() && mixin.getBlock().getNodes().isEmpty()) mixin.setBlock(null); return mixin; }
private Node parseCode() { Token token = expect(Expression.class); Expression expressionToken = (Expression) token; ExpressionNode codeNode = new ExpressionNode(); codeNode.setValue(expressionToken.getValue()); codeNode.setBuffer(expressionToken.isBuffer()); codeNode.setEscape(expressionToken.isEscape()); codeNode.setLineNumber(expressionToken.getLineNumber()); codeNode.setFileName(filename); boolean block = false; // int i = 1; // while (lookahead(i) != null && lookahead(i) instanceof Newline) // ++i; block = peek() instanceof Indent; if (block) { codeNode.setBlock((BlockNode) block()); } return codeNode; }
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; }
private Node parseFilter() { Token token = expect(Filter.class); Filter filterToken = (Filter) token; AttributeList attr = (AttributeList) accept(AttributeList.class); lexer.setPipeless(true); Node tNode = parseTextBlock(); lexer.setPipeless(false); FilterNode node = new FilterNode(); node.setValue(filterToken.getValue()); node.setLineNumber(line()); node.setFileName(filename); if(tNode!=null) node.setTextBlock(tNode); else{ node.setTextBlock(new BlockNode()); } if (attr != null) { node.setAttributes(convertToNodeAttributes(attr)); } return node; }
private Node parseComment() { Token token = expect(Comment.class); Node block = this.parseTextBlock(); if (block != null ) { BlockCommentNode node = new BlockCommentNode(); node.setBlock(block); node.setBuffered(token.isBuffer()); node.setLineNumber(token.getLineNumber()); node.setFileName(filename); node.setValue(token.getValue()); return node; } else { CommentNode node = new CommentNode(); node.setBuffered(token.isBuffer()); node.setLineNumber(token.getLineNumber()); node.setFileName(filename); node.setValue(token.getValue()); return node; } }