Ejemplo n.º 1
0
  private Node parseBlock() {
    Token token = expect(Block.class);
    Block block = (Block) token;
    String mode = block.getMode();
    String name = block.getValue().trim();

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

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

    if (blocks.containsKey(name)) {
      BlockNode prev = (BlockNode) blocks.get(name);
      if ("append".equals(prev.getMode())) {
        blockNode.getNodes().addAll(prev.getNodes());
      }
      if ("prepend".equals(prev.getMode())) {
        blockNode.getNodes().addAll(0, prev.getNodes());
      }
      if ("replace".equals(prev.getMode())) {
        blockNode = prev;
      }
    }

    blocks.put(name, blockNode);
    return blockNode;
  }
Ejemplo n.º 2
0
 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();
 }