Пример #1
0
  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;
  }
Пример #2
0
  private Node parseInclude() {
    Token token = expect(Include.class);
    Include includeToken = (Include) token;
    String templateName = includeToken.getValue().trim();

    Parser parser = createParser(templateName);
    parser.setBlocks(blocks);
    contexts.push(parser);
    Node ast = parser.parse();
    contexts.pop();

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

    return ast;
  }
Пример #3
0
  public Node parse() {
    BlockNode block = new BlockNode();
    block.setLineNumber(lexer.getLineno());
    block.setFileName(filename);
    while (!(peek() instanceof Eos)) {
      if (peek() instanceof Newline) {
        nextToken();
      } else {
        Node expr = parseExpr();
        if (expr != null) {
          block.push(expr);
        }
      }
    }
    if (extending != null) {
      getContexts().push(extending);
      Node rootNode = extending.parse();
      getContexts().pop();
      return rootNode;
    }

    return block;
  }