コード例 #1
0
ファイル: Markdown.java プロジェクト: lukehutch/ceylon
  private static Document extractBetween(
      SectionsMarkdownVisitor v, Node parent, Header header1, Header header2) {
    /*Node parent1 = header1 != null ? header1.jjtGetParent() : null;
    Node parent2 = header2 != null ? header2.jjtGetParent() : null;
    /*if (parent1 != null
            && parent2 != null
            && parent1 != parent2) {
        throw new RuntimeException();
    }* /
    Node parent = parent1 != null ? parent1 : parent2;*/

    Document doc = new Document(Parser.JJTDOCUMENT);
    final int numChildren = parent.jjtGetNumChildren();
    final int start = header1 != null ? Markdown.getIndexInParent(header1) + 1 : 0;
    final int end = header2 != null ? Markdown.getIndexInParent(header2) - 1 : numChildren - 1;
    for (int nodeIndex = start; nodeIndex <= end; nodeIndex++) {
      Node child = parent.jjtGetChild(nodeIndex);
      child.jjtSetParent(doc);
      doc.jjtAddChild(child, nodeIndex - start);
    }
    // Add a copy of all the resource definitions
    // to each document
    for (ResourceDefinition rd : v.resourceDefinitions) {
      ResourceDefinition copy = copy(rd);
      copy.jjtSetParent(doc);
      doc.jjtAddChild(copy, doc.jjtGetNumChildren());
    }
    return doc;
  }