| 1 22 23 package org.javacc.jjtree; 24 25 26 public class ASTBNFAction extends SimpleNode { 27 ASTBNFAction(int id) { 28 super(id); 29 } 30 31 private Node getScopingParent(NodeScope ns) 32 { 33 for (Node n = this.jjtGetParent(); n != null; n = n.jjtGetParent()) { 34 if (n instanceof ASTBNFNodeScope) { 35 if (((ASTBNFNodeScope)n).node_scope == ns) { 36 return n; 37 } 38 } else if (n instanceof ASTExpansionNodeScope) { 39 if (((ASTExpansionNodeScope)n).node_scope == ns) { 40 return n; 41 } 42 } 43 } 44 return null; 45 } 46 47 48 public void print(IO io) 49 { 50 56 57 NodeScope ns = NodeScope.getEnclosingNodeScope(this); 58 if (ns != null && !ns.isVoid()) { 59 boolean needClose = true; 60 Node sp = getScopingParent(ns); 61 62 SimpleNode n = this; 63 while (true) { 64 Node p = n.jjtGetParent(); 65 if (p instanceof ASTBNFSequence || p instanceof ASTBNFTryBlock) { 66 if (n.getOrdinal() != p.jjtGetNumChildren() - 1) { 67 68 needClose = false; 69 break; 70 } 71 } else if (p instanceof ASTBNFZeroOrOne || 72 p instanceof ASTBNFZeroOrMore || 73 p instanceof ASTBNFOneOrMore) { 74 needClose = false; 75 break; 76 } 77 if (p == sp) { 78 79 break; 80 } 81 n = (SimpleNode)p; 82 } 83 if (needClose) { 84 openJJTreeComment(io, null); 85 io.println(); 86 ns.insertCloseNodeAction(io, getIndentation(this)); 87 closeJJTreeComment(io); 88 } 89 } 90 super.print(io); 91 } 92 93 94 } 95 96 97 | Popular Tags |